Extending space on linux LVM when using a virtualized server

For reference in the future when I want to again extend my LVM and not go through 2+ hours of searching the web.

I am running a Ubuntu server inside of a VMWare ESXI host. Occasionally I may re-arrange things on my server or decide to give a server a bit more space. Increasing the file size from VMWare is pretty easy. Stop the server, edit the VM, then change hard drive space appropriately. Restart the server, and the space is now available…technically.

In order to add to the partition I use the following:
sudo growpart /dev/sda 3

This does indeed grow the partition size...and that is about it. Using PVS / LVS / VGS all show that the size has not been increased at all, even though the partition size has changed.

Next you will need to extend the physical volume

sudo pvresize /dev/sda3

Now we are making some progress, the physical volume now looks to have grown, so now our extra space is beginning to materialize. Next we need to correctly increase the space on our LVM. For this we are going to do a few things, run a test, if it succeeds, continue and resize the volume with ALL increased space.

sudo lvresize -r -t -v -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

You should see a lot of messaging about whether this should succeed or fail. You will also see the beginning and ending size. Now to do it for real.

sudo lvresize -r -v -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

By removing the -t flag we now are no longer testing and instead finishing the actual increase in disk space. This should help to solve some of the challenged that "adding more space" from a virtual environment can have where you suddenly get extra space but making it usable inside of your LVM can be very frustrating to try and figure out.

December 13, 2021