How to resize an LVM

Sometimes we have faced that when provisioning a virtual machine in proxmox, using LVM, the disk space provisioned in the OS is the half of the one provisioned in proxmox. For example, we have provisioned an Ubuntu 22.04 VM with a HDD of 100GB and when we check with the command du -h we find that we have only 50GB available. Then, what can we do to fully use the provisioned size when using LVM? Just resize the LVM.

We can resize the LVM using the GUI (Gparted) or the Terminal. We are going to show how to use the later. First we need to check if we have free disk space. Remember to execute these commands with sudo privileges.

fdisk -l

This command will show the sectors, size and type of each device

In this example our disk is 30 GB in size but right now the LVM is using only the half (15 GB). We can check this executing the command

lvdisplay

No we need to extend the physical drive partition of this we will execute the following commands

growpart /dev/sda 3 (extend the physical drive)
pvdisplay (check the physical drive)
pvresize /dev/sda3 (Instruct the LVM that the disk has changed)

Now that we have extended the physical drive partition we are going to extend the logical volume. Let’s execute the commands:

lvdisplay (Check the current LVM)
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv (Instruct to resize the LVM)
lvdisplay (Check the new LVM)

The command lvdisplay will show the location of the current LVM in the /dev/ folder. You might use the one in the LV Path variable. Finally we can resize the filesystem

resize2fs /dev/ubuntu-vg/ubuntu-lv
fdisk -l (Check the results)

I hope this procedure is useful as it has helped us when storage is very low. Specially in proxmox we have encountered this situation in which we have configured the VM to use some disk space and this disk space is cut to half when using LVM on our Ubuntu machines. This situation is very common but also should be used with caution as it can cause a system to crash eventually.

Scroll to Top