在VMware虚拟机配置中增加磁盘后,启动Linux,使用root登录。
首先查看未分区的磁盘,使用下面命令:
## 查看未使用的磁盘 fdisk -l
磁盘/dev/sdb后面没有任何分区,是新挂载的磁盘
输入下面命令来开始对磁盘/dev/sdb进行分区
## 开始格式化磁盘 ## fdisk /dev/sdb
有如下提示:
[root@localhost dev]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. 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 g create a new empty GPT partition table G create an IRIX (SGI) partition table 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)
首选使用n来创建一个扩展分区,输入选项n:
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p):
选择创建扩展分区,输入选项e,然后选择扩展分区编号、起始位置和大小,我们选择整个磁盘只创建一个扩展分区:
Select (default p): e Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Partition 1 of type Extended and of size 20 GiB is set
扩展分区创建好后,可以在此基础上进行创建逻辑分区,我们创建2个逻辑分区并分别设置为10G:
Command (m for help): n Partition type: p primary (0 primary, 1 extended, 3 free) l logical (numbered from 5) Select (default p): l Adding logical partition 5 First sector (4096-41943039, default 4096): Using default value 4096 Last sector, +sectors or +size{K,M,G} (4096-41943039, default 41943039): +10G Partition 5 of type Linux and of size 10 GiB is set Command (m for help): n Partition type: p primary (0 primary, 1 extended, 3 free) l logical (numbered from 5) Select (default p): l Adding logical partition 6 First sector (20977664-41943039, default 20977664): Using default value 20977664 Last sector, +sectors or +size{K,M,G} (20977664-41943039, default 41943039): Using default value 41943039 Partition 6 of type Linux and of size 10 GiB is set
最后使用选项p来查看分好的分区:
Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x40e44e64 Device Boot Start End Blocks Id System /dev/sdb1 2048 41943039 20970496 5 Extended /dev/sdb5 4096 20975615 10485760 83 Linux /dev/sdb6 20977664 41943039 10482688 83 Linux
为磁盘分配好分区后,需要使用选项w来进行保存:
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
在执行partprobe命令来重新读取分区信息,如果有警告可以忽略。
## 重新读取分区信息 ## partprobe
然后需要对磁盘进行格式化,使用mkfs将磁盘格式化为ext4格式(注意扩展分区不能进行格式化)