ITlover00 2020-03-27
# fdisk -l
系统显示如下类似信息:
Disk /dev/vda: 500 GiB, 536870912000 bytes, 1048576000 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 Disklabel type: dos Disk identifier: 0x00027c9e Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 2105343 2103296 1G 83 Linux /dev/vda2 2105344 18876415 16771072 8G 8e Linux LVM /dev/vda3 18876416 62914559 44038144 21G 8e Linux LVM Disk /dev/mapper/root-root: 21 GiB, 22540189696 bytes, 44023808 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 /dev/mapper/swap-swap: 8 GiB, 8581545984 bytes, 16760832 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
上述示例,系统有一个空间500G的磁盘,盘符为/dev/vda,该磁盘已存在三个分区/dev/vda1(空间为1G)、/dev/vda2(空间为8G)、/dev/vda3(空间为21G)。则需将剩余的470G空间划分为两个分区。
# fdisk /dev/vda
系统显示如下类似信息:
Welcome to fdisk (util-linux 2.28). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n
Partition type p primary (3 primary, 0 extended, 1 free) e extended (container for logical partitions) Select (default e): e
操作系统默认划分4个primary分区,本示例只剩一个primary分区free。此时需先新建一个extend分区/dev/vda4,然后将该extend分区划分为两个logical分区/dev/vda5和/dev/vda6。
如果磁盘小于等于两个primary分区,则可直接在此基础上再划分2个primary分区,即此处可选p。
Selected partition 4 First sector (62914560-1048575999, default 62914560): Last sector, +sectors or +size{K,M,G,T,P} (62914560-1048575999, default 1048575999):
Created a new partition 4 of type ‘Extended‘ and of size 470 GiB Command (m for help): n
在第二行后执行回车,表示选择分区5的起始位置接着上一分区的末尾;在第三行后输入+200G,表示选择分区5的终止位置由起始位置开始偏移200G。
All primary partitions are in use. Adding logical partition 5 First sector (62916608-1048575999, default 62916608): Last sector, +sectors or +size{K,M,G,T,P} (62916608-1048575999, default 1048575999): +200G
Created a new partition 5 of type ‘Linux‘ and of size 200 GiB. Command (m for help): n
在第二行后执行回车,表示选择分区6的起始位置接着上一分区的末尾;在第三行后执行回车,表示选择分区6的终止位置为/dev/vda磁盘的末尾。
All primary partitions are in use. Adding logical partition 6 First sector (482349056-1048575999, default 482349056): Last sector, +sectors or +size{K,M,G,T,P} (482349056-1048575999, default 1048575999):
Created a new partition 5 of type ‘Linux‘ and of size 200 GiB. Command (m for help): p
Disk /dev/vda: 500 GiB, 536870912000 bytes, 1048576000 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 Disklabel type: dos Disk identifier: 0x00027c9e Device Boot Start End Sectors Size Id Type /dev/vda1 * 2048 2105343 2103296 1G 83 Linux /dev/vda2 2105344 18876415 16771072 8G 8e Linux LVM /dev/vda3 18876416 62914559 44038144 21G 8e Linux LVM /dev/vda4 62914560 1048575999 985661440 470G 5 Extended /dev/vda5 62916608 482347007 419430400 200G 83 Linux /dev/vda6 482349056 1048575999 566226944 270G 83 Linux Command (m for help): w
The partition table has been altered. Calling ioctl() to re-read partition table. Re-reading the partition table failed.: Device or resource busy The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8)
# partprobe
/dev/vda5: block special (253/5)
/dev/vda5: block special (253/5)
如果信息显示异常,步骤2.通知系统分区表的变化。可尝试使用reboot命令替换。
# mkfs.ext4 /dev/vda5
# mkfs.ext4 /dev/vda6
# mkdir /data01
# mkdir /data02
# mount /dev/vda5 /data01
# mount /dev/vda6 /data02
# vi /etc/fstab
增加如下类似配置后按:wq!保存退出。
/dev/vda5 /data01 ext4 defaults 0 0 /dev/vda6 /data02 ext4 defaults 0 0
#df -hT
Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 16G 8.0K 16G 1% /dev tmpfs tmpfs 16G 80K 16G 1% /dev/shm tmpfs tmpfs 16G 18M 16G 1% /run tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/mapper/root-root xfs 21G 3.1G 18G 15% / /dev/vda1 ext4 979M 57M 855M 7% /boot tmpfs tmpfs 3.2G 16K 3.2G 1% /run/user/483 tmpfs tmpfs 3.2G 0 3.2G 0% /run/user/0 /dev/vda5 ext4 500G 60M 499G 1% /data01 /dev/vda6 ext4 500G 60M 499G 1% /data02