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:
  1. First edit the settings for the VM in vSphere client, selecting the harddisk and increasing its size by the amount you want to add
  2. Then login to that VM and use 'df' to see what is mounted.
  3. 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)
  4. 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'
  5. 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
  6. Create a new pvdisk: 'pvcreate /dev/sda3'
  7. Find the volume group via 'vgdisplay'
  8. Extend the volume group via 'vgextend vg0 /dev/sda3'
  9. 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'
  10. Now extend the filesystem: 'resize2fs /dev/vg0/lv_root'
That's it. New space should now be in place.

-- Main.ShawnMcKee - 28 Feb 2017

This topic: AGLT2 > WebHome > ExtendLVMVsphereDisk
Topic revision: 28 Feb 2017, ShawnMcKee
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback