磁盘分区格式化,挂载,交换分区的挂载

硬盘分区并挂载


环境:虚拟机,centos6.5


1.添加一块硬盘20G


2.查看fdisk -l分区情况,是一块完整的盘

# fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


3.对磁盘进行分区

# fdisk /dev/sdb

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.


查看内核是否真正的读取分区表

# cat /proc/partitions 
major minor  #blocks  name
   8        0   20971520 sda
   8        1     409600 sda1
   8        2   20560896 sda2
   8       16   20971520 sdb
   8       17    5253223 sdb1

4.格式化分区   

# mkfs.ext4 /dev/sdb1


5.设定卷标

# e2label /dev/sdb1 myfirst


6.编辑/etc/fstab文件,添加如下内容

# vim /etc/fstab
LABEL=myfirst           /mnt/firstsdb           ext4    defaults        0 0


7.新建一个挂载点

# mkdir /mnt/firstsdb


8.挂载文件系统

# mount /dev/sdb1 /mnt/firstsdb/


查看是否挂载成功

# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mnt/firstsdb type ext4 (rw)



在挂载目录下,会生成一个lost+found目录

# cd /mnt/firstsdb/
# ls
lost+found



按前面的步骤又新建一个磁盘

# fdisk -cu /dev/sdb
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63    10506509     5253223+  83  Linux
/dev/sdb2        10506510    14700813     2097152   83  Linux


查看时,没有识别sdb2分区

# cat /proc/partitions 
major minor  #blocks  name
   8        0   20971520 sda
   8        1     409600 sda1
   8        2   20560896 sda2
   8       16   20971520 sdb
   8       17    5253223 sdb1

此时可以使用partx识别

# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition 1
# cat /proc/partitions 
major minor  #blocks  name
   8        0   20971520 sda
   8        1     409600 sda1
   8        2   20560896 sda2
   8       16   20971520 sdb
   8       17    5253223 sdb1
   8       18    2097152 sdb2

   

之后再进行相应的挂载工作


查看卷标,用e2label 磁盘名

# e2label /dev/sdb1
myfirst



创建一个1G的交换分区

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 82
/dev/sdb3             916        1046     1048576   82  Linux swap / Solaris


挂载前查看交换分区多大

# free -m
             total       used       free     shared    buffers     cached
Mem:          1006        161        844          0         20         69
-/+ buffers/cache:         72        934
Swap:          399          0        399


格式化交换分区

# mkswap /dev/sdb3
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=71372e47-1252-4303-9fa2-6a1545820716
# vim /etc/fstab 
/dev/sdb3    swap    swap    defaults    0 0

激活swap分区

# swapon /dev/sdb3


激活交换分区后,查看交换分区的大小

# free -m
             total       used       free     shared    buffers     cached
Mem:          1006        162        844          0         20         69
-/+ buffers/cache:         72        933
Swap:         1423          0       1423







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章