Welcome to fdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
GPT PMBR size mismatch (209715199 != 629145599) will be corrected by write. The backup GPT table is not on the end of the device. This problem will be corrected by write.
Command (m for help): n Partition number (4-128, default 4): First sector (209713152-629145566, default 209713152): Last sector, +/-sectors or +/-size{K,M,G,T,P} (209713152-629145566, default 629145566):
Created a new partition 4 of type 'Linux filesystem' and of size 200 GiB.
Command (m for help): p Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors Disk model: QEMU HARDDISK 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: 9FD87B41-A400-4DD9-AE87-C852ACB2854D
Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 2101247 2097152 1G Linux filesystem /dev/sda3 2101248 209713151 207611904 99G Linux filesystem /dev/sda4 209713152 629145566 419432415 200G Linux filesystem
Command (m for help): w The partition table has been altered. Syncing disks.
root@hello:~# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name ubuntu-vg PV Size <99.00 GiB / not usable 0 Allocatable yes (but full) PE Size 4.00 MiB Total PE 25343 Free PE 0 Allocated PE 25343 PV UUID DfUNvp-F4D5-J6Rj-sMcS-PqE1-bKf6-2XLfb2
--- Physical volume --- PV Name /dev/sda4 VG Name ubuntu-vg PV Size 200.00 GiB / not usable 4.98 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 51199 Free PE 0 Allocated PE 51199 PV UUID yeXSs6-mUWY-Q31q-oD0J-yWHA-zPfp-92AKrO
root@hello:~# vgextend ubuntu-vg /dev/sda4 Volume group "ubuntu-vg" successfully extended
root@hello:~# vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 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 298.99 GiB PE Size 4.00 MiB Total PE 76542 Alloc PE / Size 76542 / 298.99 GiB Free PE / Size 0 / 0 VG UUID QpG0NU-5tPY-q5Bw-mLIu-Axl6-mdtP-19WWq6
root@hello:~# lvextend /dev/ubuntu-vg/ubuntu-lv /dev/sda4 Size of logical volume ubuntu-vg/ubuntu-lv changed from <99.00 GiB (25343 extents) to 298.99 GiB (76542 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@hello:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID ODU5p6-8E8i-30tn-3hzs-AifF-iF4Z-HzMuFL LV Write Access read/write LV Creation host, time ubuntu-server, 2022-03-29 09:07:30 +0000 LV Status available # open 1 LV Size 298.99 GiB Current LE 76542 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
扩展根文件系统
1 2 3 4 5
root@hello:~# resize2fs /dev/ubuntu-vg/ubuntu-lv resize2fs 1.45.5 (07-Jan-2020) Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required old_desc_blocks = 13, new_desc_blocks = 38 The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 78379008 (4k) blocks long.