Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Command (m for help): m
Help:
DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag
Generic d delete a partition F list free unpartitioned space l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition
Misc m print this menu u change display/entry units x extra functionality (experts only)
Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file
Save & Exit w write table to disk and exit q quit without saving changes
Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table
Command (m for help):
可以先打印分区表看看基本信息
1 2 3 4 5 6 7 8 9 10 11 12 13
Command (m for help): p Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors Disk model: VMware Virtual S 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: 0xa4334a8d
Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 41940991 41938944 20G 83 Linux
Command (m for help):
如果有交换分区(Linux swap),比如/dev/sdan,则需要关闭。
1
sudo swapoff /dev/sdan
然后删除分区
1 2 3 4 5
Command (m for help): d Selected partition 1 Partition 1 has been deleted.
Command (m for help):
新建分区
1 2 3 4 5 6 7 8 9 10 11 12 13
Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-62914559, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62914559, default 62914559):
Created a new partition 1 of type 'Linux' and of size 30 GiB. Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
打印看一下
1 2 3 4 5 6 7 8 9 10 11
Command (m for help): p Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors Disk model: VMware Virtual S 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: 0xa4334a8d
Device Boot Start End Sectors Size Id Type /dev/sda1 2048 62914559 62912512 30G 83 Linux
确认无误
1 2 3
Command (m for help): a Selected partition 1 The bootable flag on partition 1 is enabled now.
写入
1 2 3
Command (m for help): w The partition table has been altered. Syncing disks.
重启虚拟机
1
sudo reboot
不要着急,这个时候查看磁盘,还是会显示20G的。
执行扩容操作
1 2 3 4 5 6
sudo resize2fs /dev/sda1 [sudo] password for simon: resize2fs 1.44.6 (5-Mar-2019) Filesystem at /dev/sda1 is mounted on /; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 4 The filesystem on /dev/sda1 is now 7864064 (4k) blocks long.