How to extend the size of a Logical Volume?

In this article, we cover how to extend the size of a Logical Volume. Recently, we increased the size of our Virtual Machine’s Disk in VirtualBox. Our disk configuration had LVM (Logical Volume Management) architecture, so we thought of writing a separate article.

A brief about LVM architecture. Multiple physical volumes can be combined into a single-volume group. The size of the volume group is equal to the size of such physical volumes’ storage capacity. And, the volume group can further be divided into logical volumes (or, partitions).

Note: Following operations require Administrative Rights. If you don’t have the necessary rights then contact your System Administrator for assistance.

Word of Caution: Before you move ahead, we strongly advise you to take a backup of your data. We modify the partition size here. And, it can lead to loss of data if things don’t go as planned.

We cover two scenarios here.

How to extend the size of a Logical Volume?

Case I: We assume that the volume group is already present and we have increased the space through GParted. But, it is available as an Unused space. Now, what we do here is extend the logical volume so that it starts using the unused space as well. Look at Free PE / Size component.

Run the following command to get the above data:

sudo vgdisplay

To get information about the Logical volume we wish to extend:

sudo lvdisplay

Clearly, we had nearly 13 GiB of space available. But, could only utilize 10 GiB. Now, to extend the size of the logical volume.

sudo lvextend -l +830 /dev/ubuntu-vg/ubuntu-lv

We have used the -l option to extend the remaining Free PE (Physical Extents), which in this case was 831. So, we used 830.

Lastly, don’t forget to do:

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

Case II: Let’s say we created a new partition /dev/sda4 instead of resizing the existing partition through GParted. So, we have to first create a Physical Volume for the existing partition.

sudo pvcreate /dev/sda4

We can verify the above through:

sudo pvdisplay

Now, we need to extend our volume group, which in our case was ubuntu-vg.

sudo vgextend ubuntu-vg /dev/sda4

Once we have extended the volume group, it gets easier to extend the logical volume. Just like we did in Case I.

sudo lvextend -l +830 /dev/ubuntu-vg/ubuntu-lv

Lastly, don’t forget to do:

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

In conclusion, we have covered here how to extend the size of a Logical volume in Linux.

Similar Posts