Extending LVM Partitions in Linux

In Linux, Logical Volume Manager (LVM) is a technology that provides logical volume management for the Linux kernel. You can use LVM in most Linux distributions to resize file system by increasing it or descreasing it as per your needs.

The concept is pretty simple. You have multiple physical volumes (physical disk attached to the system) forming a volume group and in a volume group you can create logical volumes. You then have the flexibility to add/remove the physical volumes to increase the volume group capacity, and as such, being able to add new logical volumes or extending the size of the existing ones as needed.

In this short tutorial we will discuss the steps to extend a file system that is running out of space. For this, let’s suppose we have a LVM partition (/dev/mapper/centos-root) mounted on / that is almost out of space and we want to increase the space available on the disk.

Listing the file system along with the available and free space

Above command shows /dev/mapper/centos-root has only 1.7G available.

Checking the existing Physical Volumes and Volume Groups

From below command, we can see that there is one physical volume (/dev/sda2) into one volume group called centos.

Checking the existing Logical Volumes

We have two logical volumes named root and swap inside the centos Volume Group.

Checking the disks attached on the system

We have a raw disk (sdb) attached to our system with a size of 4GB that can be used to extend the centos Volume Group, then assign all available free space to the Logical Volume root.

Turning the attached disk to a Physical Volume

Before being able to add sdb to the centos Volume Group, we need to mark it as a Physical Volume.

Adding the /dev/sdb to the centos Volume Group

Volume Group centos has two disks now, /dev/sda2 and /dev/sdb.

Extending the Logical Volume

The last step would be to assign the available free (4GB) to the root Logical Volume. The -r here is used to resize the file system on the fly along with the logical volume. This will avoid you to run resize2fs afterwards.

Checking the updated file system free space

The file system size has been increased after adding 4GB and the free space available now is 5.7GB.


Find this post interesting. Share it!

Leave a Comment

Your email address will not be published. Required fields are marked *