Welcome to fdisk (util-linux 2.37.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xd97cd23b.
Command (m for help): g Created a new GPT disklabel (GUID: CED3C27F-6F17-D940-A99F-191D881FCD91).
Command (m for help): n Partition number (1-128, default 1): First sector (2048-209715166, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715166, default 209715166):
Created a new partition 1 of type 'Linux filesystem' and of size 100 GiB.
Command (m for help): p Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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: CED3C27F-6F17-D940-A99F-191D881FCD91
Device Start End Sectors Size Type /dev/sdb1 2048 209715166 209713119 100G Linux filesystem
Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
# 创建PV并查看 root@hello:~# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name ubuntu-vg PV Size <99.00 GiB / not usable 0 Allocatable yes PE Size 4.00 MiB Total PE 25343 Free PE 127 Allocated PE 25216 PV UUID Dys0fV-H7vi-KfCz-5Flh-n724-mjP4-dtzzJ5 root@hello:~# root@hello:~# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. root@hello:~# root@hello:~# root@hello:~# pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name ubuntu-vg PV Size <99.00 GiB / not usable 0 Allocatable yes PE Size 4.00 MiB Total PE 25343 Free PE 127 Allocated PE 25216 PV UUID Dys0fV-H7vi-KfCz-5Flh-n724-mjP4-dtzzJ5 "/dev/sdb1" is a new physical volume of "<100.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size <100.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID iR6wd1-QDJc-oqm7-dxF5-JzvB-e2Ta-LSciIm root@hello:~#
# 扩展VG并查看 root@hello:~# vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 1 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 1 Act PV 1 VG Size <99.00 GiB PE Size 4.00 MiB Total PE 25343 Alloc PE / Size 25216 / 98.50 GiB Free PE / Size 127 / 508.00 MiB VG UUID MJt4Ho-TZ8N-vBhS-TMnK-nSPa-2orh-MbV9jr root@hello:~# root@hello:~# vgextend ubuntu-vg /dev/sdb1 Volume group "ubuntu-vg" successfully extended root@hello:~# 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 198.99 GiB PE Size 4.00 MiB Total PE 50942 Alloc PE / Size 25216 / 98.50 GiB Free PE / Size 25726 / 100.49 GiB VG UUID MJt4Ho-TZ8N-vBhS-TMnK-nSPa-2orh-MbV9jr root@hello:~#
# 扩展LV并查看 root@hello:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID 5DDQEu-kuMX-VU3G-Gck0-5Pjq-bMzO-cHnbIr LV Write Access read/write LV Creation host, time ubuntu-server, 2021-09-23 11:50:37 +0800 LV Status available # open 1 LV Size 98.50 GiB Current LE 25216 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 root@hello:~# root@hello:~# lvextend /dev/ubuntu-vg/ubuntu-lv /dev/sdb1 Size of logical volume ubuntu-vg/ubuntu-lv changed from 98.50 GiB (25216 extents) to <198.50 GiB (50815 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized. root@hello:~# root@hello:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID 5DDQEu-kuMX-VU3G-Gck0-5Pjq-bMzO-cHnbIr LV Write Access read/write LV Creation host, time ubuntu-server, 2021-09-23 11:50:37 +0800 LV Status available # open 1 LV Size <198.50 GiB Current LE 50815 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 root@hello:~#
扩展根目录
1 2 3 4 5 6
# 扩展根目录 root@hello:~# resize2fs /dev/ubuntu-vg/ubuntu-lv resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required old_desc_blocks = 13, new_desc_blocks = 25 The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 52034560 (4k) blocks long.