Disk Resizing and LVMs

Really handy if you have done a proof of concept box and a colleague decides to push the VM into production.  Assuming you have already resized the disk in the hypervisor lets start -

Get the OS to detect the new disk size (substitute 'sda' for whatever disk you are resizing)

echo 1>/sys/class/block/sda/device/rescan

Then I like to take a look at the disks using

cfdisk

Select (most likely) /dev/sda3 partition from the list and then select “Resize” from the bottom menu. Hit ENTER and it will prompt you to confirm the new size. Hit ENTER again and you will now see the /dev/sda3 partition with a new larger size.

Select “Write” from the bottom menu, type YES to confirm, and hit ENTER. Then use "Quit" to exit the program.

Now that /dev/sda3 has been extended we now need to extend the PV itself. Run

pvresize /dev/sda3

and check with

pvdisplay 

We can check the overall volume group size and space using

vgdisplay

Mind how I told you it was a POC box? Well using the default Ubuntu names we now need to extend the Logical Volume (LV) using

lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Change the names as needed for your Volume Group/Logical Volume and check with

lvdisplay

So thats all good and well, but wait, theres more! The logical volume has been extended but we need the file system that resides on it to be extented.

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Final check with

df -h

Should show all that lovely new free disk space.