# vgdisplay -v
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <19.00 GiB ### VG 容量只有 19GB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0
VG UUID edb3Hx-xxxx-xxxx-xxxx-xxxx-xxxx-iiOyAf
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID ocf2IU-xxxx-xxxx-xxxx-xxxx-xxxx-BoYp70
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 5mZgRT-xxxx-xxxx-xxxx-xxxx-xxxx-0KHlI7
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 1
LV Size <17.00 GiB ### LV 容量只有 17GB,前面有 2GB 是 Swap
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID 86HkpN-xxxx-xxxx-xxxx-xxxx-xxxx-Z6DNv4
PV Status allocatable
Total PE / Free PE 4863 / 0
# vgdisplay -v
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <19.00 GiB ### VG 容量還是沒變,只有 19GB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0
VG UUID edb3Hx-xxxx-xxxx-xxxx-xxxx-xxxx-iiOyAf
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID ocf2IU-xxxx-xxxx-xxxx-xxxx-xxxx-BoYp70
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 5mZgRT-xxxx-xxxx-xxxx-xxxx-xxxx-0KHlI7
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 1
LV Size <17.00 GiB ### LV 容量也沒變,只有 17GB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID 86HkpN-xxxx-xxxx-xxxx-xxxx-xxxx-Z6DNv4
PV Status allocatable
Total PE / Free PE 4863 / 0
# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)
你可以在 parted 裡面輸入需要的指令,打 quit 離開互動式介面
先打 print 印出磁區列表,
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 64.4GB ### 可以看到硬碟大小變成 64.4GB 了
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 21.5GB 20.4GB primary lvm ### 但 LVM 磁區只有 20.4GB
使用 resizepart 指令調整分割區大小
(parted) resizepart 2 100%
記得這個 2 要換成對應的數字
再印一次看看
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 64.4GB 63.3GB primary lvm ### LVM 磁區擴增變成新的大小 63.3GB
打 quit 離開互動式介面
(parted) quit
Information: You may need to update /etc/fstab.
LVM 資訊看一下
# vgdisplay -v
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <19.00 GiB ### VG 容量還是沒變,只有 19GB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0
VG UUID edb3Hx-xxxx-xxxx-xxxx-xxxx-xxxx-iiOyAf
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID ocf2IU-xxxx-xxxx-xxxx-xxxx-xxxx-BoYp70
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 5mZgRT-xxxx-xxxx-xxxx-xxxx-xxxx-0KHlI7
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 1
LV Size <17.00 GiB ### LV 容量也沒變,只有 17GB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID 86HkpN-xxxx-xxxx-xxxx-xxxx-xxxx-Z6DNv4
PV Status allocatable
Total PE / Free PE 4863 / 0
Step4. 擴增 PV
我們用 pvresize 調整 PV 的大小
# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
再次印一次 LVM 資訊看看
# vgdisplay -v
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <59.00 GiB ### VG 容量變大了 59GB
PE Size 4.00 MiB
Total PE 15103
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 10240 / 40.00 GiB ### 跑出了一些 PE 大小
VG UUID edb3Hx-xxxx-xxxx-xxxx-xxxx-xxxx-iiOyAf
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID ocf2IU-xxxx-xxxx-xxxx-xxxx-xxxx-BoYp70
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 5mZgRT-xxxx-xxxx-xxxx-xxxx-xxxx-0KHlI7
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 1
LV Size <17.00 GiB ### LV 容量沒變,還是 17GB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID 86HkpN-xxxx-xxxx-xxxx-xxxx-xxxx-Z6DNv4
PV Status allocatable
Total PE / Free PE 15103 / 10240 ### 跑出了一些 Free PE 出來(因為我們還沒調整)
Step5. 擴增 LV
我們使用 lvextend 擴大 LV 大小
# lvextend -l +100%FREE /dev/rhel/root
Size of logical volume rhel/root changed from <17.00 GiB (4351 extents) to <57.00 GiB (14591 extents).
Logical volume rhel/root successfully resized.
再次印一次 LVM 資訊看看
# vgdisplay -v
--- Volume group ---
VG Name rhel
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <59.00 GiB ### VG 容量沒問題 59GB
PE Size 4.00 MiB
Total PE 15103
Alloc PE / Size 15103 / <59.00 GiB
Free PE / Size 0 / 0
VG UUID edb3Hx-xxxx-xxxx-xxxx-xxxx-xxxx-iiOyAf
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID ocf2IU-xxxx-xxxx-xxxx-xxxx-xxxx-BoYp70
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 5mZgRT-xxxx-xxxx-xxxx-xxxx-xxxx-0KHlI7
LV Write Access read/write
LV Creation host, time uatgit, 2023-08-21 18:06:42 +0800
LV Status available
# open 1
LV Size <57.00 GiB ### LV 容量變大了 57GB
Current LE 14591
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID 86HkpN-xxxx-xxxx-xxxx-xxxx-xxxx-Z6DNv4
PV Status allocatable
Total PE / Free PE 15103 / 0 ### 沒有 Free PE 了