硬盤分區並掛載
環境:虛擬機,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