Extend Ubuntu LVM Partition using available free space

Run out of space in Ubuntu / ? Fix this easily by allocating remaining free space to it.

This is the easiest method to increase "disk space".

It is used when you have unallocated space on your disk or have increased the virtual disk size.

First, check the current disk situation:

df -h
sudo vgdisplay
sudo lvdisplay

It is advisable that you make a backup (or snapshot if you are using a virtual machine) of the filesystem before you attempt the following steps.

Then, extend the logical volume by using all remaining free space. The logical volume in the example below uses /dev/ubuntu-vg/ubuntu-lv.

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

If you want to use some of the remaining free space, say 50%, you can adjust accordingly. For example:

sudo lvextend -l +50%FREE /dev/ubuntu-vg/ubuntu-lv

Finally, update the file-system (use df to get the correct name) to recognise the "new space". The file-system in the example below uses /dev/mapper/ubuntu--vg-ubuntu--lv.

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