Problem. Need to resize a LVM partition inside a Linux RHEL5 VM ware image.
Constraints. A environment where lvresize does not support online resizing. No access to a rescue disk.
First. Add the disk image to another VM image in VM player. Now startup. We can see both volumes.
vgscan Reading all physical volumes. This may take a while... Found volume group "VolGroup00" using metadata type lvm2 Found volume group "VolGroup00" using metadata type lvm2
Problem. We cannot address the volumes separately because they have the same name…
# Fix naming conflict, find UUIDs with vgdisplay vgdisplay # rename non-mounted one vgrename abcdef-abcd-abcd-abcd-abcd-abcd-abcdef VolGroupXX # check vgscan Reading all physical volumes. This may take a while... Found volume group "VolGroupXX" using metadata type lvm2 Found volume group "VolGroup00" using metadata type lvm2 # activate vgchange -a y 2 logical volume(s) in volume group "VolGroupXX" now active 2 logical volume(s) in volume group "VolGroup00" now active
Now we can resize the “guest” disk.
# resize, check first
e2fsck -f /dev/mapper/VolGroupXX-LogVol00
# resize
resize2fs /dev/mapper/VolGroupXX-LogVol00 20G
# check
mkdir m
mount /dev/mapper/VolGroupXX-LogVol00 m
df -h m
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroupXX-LogVol00
20G 14G 4.8G 75% /root/m
# deactivate
umount m
vgchange -a n
Now it gets interesting… We cannot boot the VM image, this is because the boot disk has references to VolGroup00 and we renamed it to VolGroupXX. Unfortunately vgrename prevents renaming to conflicting names.
A solution: Mount the /boot partition. Extract the root disk image, edit, and repack.
sudo su # access guest boot mkdir boot mount /dev/sdb1 boot # extract mkdir tmp cd tmp gzip -dc ../boot/initrd-2.6.18-53.el5.img | cpio -id # edit - with your favourite UNIX text editor, replace VolGroup00 with VolGroupXX emacs -nw init # repack and replace find ./ | cpio -H newc -o > ../boot/initrd-2.6.18-53.el5.img.cpio gzip -c ../boot/initrd-2.6.18-53.el5.img.cpio > ../boot/initrd-2.6.18-53.el5.img # unmount umount ../boot

