Command (m for help): p Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors Disk model: Virtual disk 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: 0x07ea7416
Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1050623 1048576 512M b W95 FAT32 /dev/sda2 1052670 188741631 187688962 89.5G 5 Extended /dev/sda5 1052672 188741631 187688960 89.5G 83 Linux // 需要扩充的分区,注意记录一下Start sector的值
Command (m for help): d // 删除2号分区 Partition number (1,2,5, default 5): 2
Partition 2 has been deleted.
Command (m for help): p Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors Disk model: Virtual disk 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: 0x07ea7416
Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1050623 1048576 512M b W95 FAT32
Command (m for help): n //创建新的extend分区 Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): e Partition number (2-4, default 2): First sector (1050624-209715199, default 1050624): // 默认即可,没必要和之前一样 Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-209715199, default 209715199):
Created a new partition 2 of type 'Extended' and of size 99.5 GiB. Partition #2 contains a vfat signature.
Do you want to remove the signature? [Y]es/[N]o: Y // 不确定是否必须移除
The signature will be removed by a write command.
Command (m for help): p Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors Disk model: Virtual disk 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: 0x07ea7416
Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1050623 1048576 512M b W95 FAT32 /dev/sda2 1050624 209715199 208664576 99.5G 5 Extended
Filesystem/RAID signature on partition 2 will be wiped.
Command (m for help): n // 新建逻辑分区 All space for primary partitions is in use. Adding logical partition 5 First sector (1052672-209715199, default 1052672): // 起始sector,一定要和之前一样 Last sector, +/-sectors or +/-size{K,M,G,T,P} (1052672-209715199, default 209715199):
Created a new partition 5 of type 'Linux' and of size 99.5 GiB. Partition #5 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: Y // 不确定是否必须移除
The signature will be removed by a write command.
Command (m for help): w // 写回磁盘 The partition table has been altered. Failed to add partition 2 to system: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot. Syncing disks.
ihopenot@ihopenot-virtual-machine:~$ sudo resize2fs /dev/sda5 resize2fs 1.45.5 (07-Jan-2020) Filesystem at /dev/sda5 is mounted on /; on-line resizing required old_desc_blocks = 12, new_desc_blocks = 13 The filesystem on /dev/sda5 is now 26082816 (4k) blocks long.
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: gpt Disk identifier: 538FA7A9-20C7-4F29-B05C-881BC791F1DF
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 3719167 3715072 1.8G Linux filesystem /dev/sda3 3719168 41940991 38221824 18.2G Linux filesystem
Command (m for help): n // 新建一个分区,使用所有剩余空间 Partition number (4-128, default 4): First sector (41940992-62914526, default 41940992): Last sector, +/-sectors or +/-size{K,M,G,T,P} (41940992-62914526, default 62914526):
Created a new partition 4 of type 'Linux filesystem' and of size 10 GiB.
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: gpt Disk identifier: 538FA7A9-20C7-4F29-B05C-881BC791F1DF
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 3719167 3715072 1.8G Linux filesystem /dev/sda3 3719168 41940991 38221824 18.2G Linux filesystem /dev/sda4 41940992 62914526 20973535 10G Linux filesystem
Command (m for help): w The partition table has been altered. Syncing disks.
ihopenot@ubuntu:~$ sudo vgextend ubuntu-vg /dev/sda4 Physical volume "/dev/sda4" successfully created. Volume group "ubuntu-vg" successfully extended ihopenot@ubuntu:~$ sudo vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size <28.22 GiB PE Size 4.00 MiB Total PE 7224 Alloc PE / Size 2560 / 10.00 GiB Free PE / Size 4664 / <18.22 GiB VG UUID p1xePf-Ye3h-wFoq-sFBX-kRi6-I3qI-wI0SYj
使用vgextend ubuntu-vg /dev/sda4将在新分区上创建PV并加入ubuntu-vg,可以看到ubuntu-vg中Free PE / Size已经扩充10个G了。