Extending LVM Disks on VMware VMs
We sometimes have partitions fill during operations and when those partitions are on VMs and using LVM we can easily extend them without rebooting. Here are the steps:
- First edit the settings for the VM in vSphere client, selecting the harddisk and increasing its size by the amount you want to add
- Then login to that VM and use 'df' to see what is mounted.
- Find the device(s) underlying LVM by using 'pvdisplay' and looking for the "PV Name". On um-omd-wn I see "/dev/sda2". So we want to tell the OS to find changes to /dev/sda
- Check disk currently: fdisk -l /dev/sda
- echo 1 > /sys/block/sda/device/rescan
- Check now: fdisk -l /dev/sda (Should show new space)
- Now we can create a new partition of type LVM via:
- fdisk /dev/sda
- Type 'n' for new partition, select 'p' for primary, pick the next available number, e.g. "3", hit enter twice
- Set partition type via entering 't', pick partition (3) and use Hex code 8e
- Write the results out via entering 'w'
- Now we have to do a trick to get the new partition to appear. Use 'partx' like this 'partx -a /dev/sda'. It will give you "Device or resource busy" but now /dev/sda3 (or your partition number) will appear
- Create a new pvdisk: 'pvcreate /dev/sda3'
- Find the volume group via 'vgdisplay'
- Extend the volume group via 'vgextend vg0 /dev/sda3'
- Extend the logical volume you want. In my case the "root" '/' area named 'lv_root' (do 'ls /dev/vg0/' to see options)
- Determine how much is available to add via 'vgdisplay'. Get the number from "Free PE / Size" row. Grab the extents number; mine was 5199
- Extend the logical volume: 'lvextend -l+5199 /dev/vg0/lv_root'
- Now extend the filesystem: 'resize2fs /dev/vg0/lv_root'
That's it. New space should now be in place.
-- Main.ShawnMcKee - 28 Feb 2017