$ pvdisplay --- Physical volume --- PV Name /dev/sda3 VG Name ubuntu-vg PV Size <63.00 GiB / not usable 0 Allocatable yes PE Size 4.00 MiB Total PE 16127 Free PE 3327 Allocated PE 12800 PV UUID cs39RZ-Dfac-qED7-KHNz-Liht-QMtu-FvhS04
$ vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 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 <63.00 GiB PE Size 4.00 MiB Total PE 16127 Alloc PE / Size 12800 / 50.00 GiB Free PE / Size 3327 / <13.00 GiB VG UUID LRE3Y3-QvmP-mCI0-D0PT-Hk9w-3tqb-129LhN
LV 當初只有分配了 50 GB 空間
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID xWDQsf-VimA-iX00-Kx6G-NzmJ-yaol-XVZr3L LV Write Access read/write LV Creation host, time ubuntu-server, 2019-08-05 10:16:13 +0800 LV Status available # open 1 LV Size 50.00 GiB Current LE 12800 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
# 使用 parted 工具進行擴充 $ parted GNU Parted 3.2 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print Model: VMware Virtual disk (scsi) Disk /dev/sda: 215GB #硬碟容量一共有 215GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: # 其中 number 3 只使用了 67.6GB Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 1076MB 1074MB ext4 3 1076MB 68.7GB 67.6GB
# 執行 partition resize 操作 (parted) resizepart Partition number? 3 End? [68.7GB]? 215GB #使用所有空間 (parted) print Model: VMware Virtual disk (scsi) Disk /dev/sda: 215GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: # 此時 number 3 partition 已經使用了所有空間 Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 1076MB 1074MB ext4 3 1076MB 215GB 214GB
# 離開 parted (parted) quit Information: You may need to update /etc/fstab.
擴充 PV 空間
原本上面的 number 3 partition 已經是現存的 PV,既然 partition 已經變大,接著就可以直接進行 resize 的操作:
$ 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 <199.00 GiB # 變成 199GB 了 PE Size 4.00 MiB Total PE 50943 Alloc PE / Size 12800 / 50.00 GiB Free PE / Size 38143 / <149.00 GiB VG UUID LRE3Y3-QvmP-mCI0-D0PT-Hk9w-3tqb-129LhN