This title has far too many acronyms so I will start by clarifying the problem that this post aims to solve. I have a Ubuntu 18.04 server running LVM (Logical Volume Manager). My primary LV (Logical Volume) was ‘full’ but was only using 4GB of a 29GB PV (Physical Volume). So if you are suffering the same issue, here are the commands you need to fix this problem.
df -h output:
This is fictitious data, but this is reflective of the fact that the root filesystem is full. This caused me a LOT of headaches and I needed to free up some free space on that partition before I could run any of the upcoming commands to expand the LV. Ways to free up space include:
sudo apt clean sudo apt autoremove -y
I was running snap and use the following command to remove older versions of a snap application:
snap remove "$snapname" --revision="$revision"
Finding the available PV space
Now that we have a tiny bit of space on ‘/’ we cab start to work on expanding the available space in the LV. First, we need to find out the available space in the PV which is where the LV ‘lives’.
the value we are looking for specifically is:
Free PE / Size 2319 / 9.06 GiB
As per the example above, we have just over 2GB available. I want to go head and give all of that space to my one and only LV.
Extending LV with lvextend
so finally, the command you were looking for:
sudo lvextend -l +2319 /dev/i-hate-lvm
Adjust the ‘2319’ value and the ‘/dev/’ path to suit your required level of expansion and the LVM volume.
Extending an LV filesystem with resize2fs
Finally, now that the LV is larger, we need to expand the filesystem on the volume to make the newly acquired space available for use. Fortunately this another really simple command:
Pay attention to the fact that I am running this command against ‘/dev/mapper/<volume-name>‘.
Run the ‘df -h’ command and again and you should now have ALL OF THE FREE SPACE!
This was a massive PITA for me, an inexperienced LVM user. Consider giving this post a bookmark or a share to help out a fellow LVM sufferer in a moment of need.
More useful Ubuntu rangling posts:
- How to upgrade Ubuntu from 18.04 to 20.04 – https://exitcode0.net/how-to-upgrade-ubuntu-from-18-04-to-20-04/
- Setup the Nextcloud Snap Package with HTTPS and a separate data path – https://exitcode0.net/setup-the-nextcloud-snap-package-with-https-and-a-separate-data-path/