VMware ESX: enlarging a Linux guest partition with LVM
Initial state: CentOS 4.8, 10 GB HDD (vmdk). Goal: expand /dev/sda2 to 30 GB.
0. Shut down the guest machine.
1. Increase the disk size to 30 GB in its settings.
2. Boot from GParted and expand /dev/sda2 to 30 GB.
3. Boot the OS and verify:
# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
ext3 8192440 1863040 5913248 24% /
/dev/sda1 ext3 101086 13365 82502 14% /boot
none tmpfs 517268 0 517268 0% /dev/shm
# pvdisplay -m
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 29.90 GB / not usable 25.84 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 956
Free PE 640
Allocated PE 316
PV UUID 0xMSrd-rM2u-WcfA-rwGb-Ysmm-ykls-FZBteb
--- Physical Segments ---
Physical extent 0 to 253:
Logical volume /dev/VolGroup00/LogVol00
Logical extents 0 to 253
Physical extent 254 to 315:
Logical volume /dev/VolGroup00/LogVol01
Logical extents 0 to 61
Physical extent 316 to 955:
FREE
3. Expand the LV to all available space. (This may have been possible from GParted.)
# lvextend -l +100%FREE /dev/mapper/VolGroup00-LogVol00
Extending logical volume LogVol00 to 27.94 GB
Logical volume LogVol00 successfully resized
4. The system will not run resize2fs on the active root filesystem. Boot GParted and open a terminal.
sudo lvm vgchange -ay
sudo e2fsck /dev/mapper/VolGroup00-LogVol00
sudo resize2fs /dev/mapper/VolGroup00-LogVol00
5. Reboot into the OS and verify: