Linux Commands

LVM: How to Resize Volumes After They are Created

A filesystem on a logical volume can be extended using the LVM tool whenever the logical volume shorts for space. The extended logical volume has more space and capacity than the previous logical volume. In this tutorial, we will discuss how the LVM command-line interface and the graphical user interface can be used to extend the logical volume.

Pre-requisites

In order to go along with this article, you must have

  • A physical volume from your storage drive
  • A physical volume under volume group
  • Logical volume over volume group
  • Filesystem on logical volume

Use the lsblk command to check physical volumes.

ubuntu@ubuntu:~$ sudo lsblk

Notice the three available physical volumes /dev/sda, /dev/sdb and /dev/sdc in the above screenshots. Now, list all the volume groups on the system using any of these vgdisplay, vgscan and vgs commands.

ubuntu@ubuntu:~$ sudo vgs

OR

ubuntu@ubuntu:~$ sudo vgdisplay

OR

ubuntu@ubuntu:~$ sudo vgscan

There is only one volume group vg01 created from only one physical volume. Now, list all the available logical volumes on the volume group vg01 using lvs, lvscan or lvdisplay command.

ubuntu@ubuntu:~$ sudo lvs /dev/vg01

OR

ubuntu@ubuntu:~$ sudo lvdisplay /dev/vg01

OR

ubuntu@ubuntu:~$ sudo lvscan

The output above displays two logical volumes lv01 and lv02 on the volume group vg01. If you donā€™t have any of the above prerequisites, check the previous articles on LVM.

Extend Logical Volume

Before logical volume extension, make sure there is enough space in the volume group containing the logical volume. Use the vgs, vgdisplay or vgscan command to verify the available space in the volume groups.

ubuntu@ubuntu:~$ sudo vgs

OR

ubuntu@ubuntu:~$ sudo vgdisplay

The current size of the volume group vg01 is about 30 GB and there is a free space of 15 GB available in the volume group. If there is not enough space available in the volume group, then the volume group will be expanded first to create free space. Alternatively, if there are more logical volumes in the volume group, shrink these volume groups to create free space.

After checking the volume group for free space, now check the current size of the logical volume and estimate its extended size. The lvdisplay command can be used to get the information of the existing logical volume.

ubuntu@ubuntu:~$ sudo lvdisplay

So, there are two logical volumes lv01 and lv02 with the size of 10 GB and 5 GB respectively. For this demo, let us increase the size of the logical volume lv01 from 10 GB to 15 GB. In order to increase the logical volume size, the lvextend command will be used along with the -L flag.

ubuntu@ubuntu:~$ sudo lvextend -L+5G /dev/vg01/lv01

The lvextend command has increased the size of volume group lv01 from 10 GB to 15 GB. In order to confirm the size of the logical volume using the command line interface, use any one of the lvdisplay, lvscan and lvs commands.

ubuntu@ubuntu:~$ sudo lvs

OR

ubuntu@ubuntu:~$ sudo lvdisplay

OR

ubuntu@ubuntu:~$ sudo lvscan

Use the vgs or vgdisplay commands to display the occupied and free space of the volume group vg01.

ubuntu@ubuntu:~$ sudo vgs

OR

ubuntu@ubuntu:~$ sudo vgdisplay

As shown above, the volume group vg01 has a free space size of 15GB and now there is only 10 GB of free space which depicts successful logical volume extension.

After extending the size of the logical volume, mount the logical volume on the system to verify file system extension.

ubuntu@ubuntu:~$ sudo mount /dev/vg01/lv01 /media/ubuntu/lv01

After mounting the logical volume, list all the mounted filesystems on the system.

ubuntu@ubuntu:~$ sudo df -Th /dev/vg01/lv01

The filesystem is still 10 GB in size and it also needs to be extended separately. The resize2fs command can be used to extend an ext4 filesystem.

Now, use the df command to check the filesystem mounted on the system again to verify extension.

The filesystem mounted on the system is 15 GB in size and has been extended successfully.

Extend Logical Volume via GUI Tool

An easier way to extend logical volume size is using a graphical user interface tool that is kvpm. You can find instructions about installing the tool in the previous articles. Open the kvpm by running the kvpm command in the terminal.

ubuntu@ubuntu:~$ sudo kvpm

It will open a window containing information about all the block devices connected to the system. For this section, we will extend the logical volume lv02 from 5 GB to 10 GB.

In order to extend the logical volume size, go to the Group:vg01 tab and select the logical volume lv02. Then extend the list of the options by clicking on the arrow sign and click on the Extend option.

For the new size of the logical volume select the General tab, enter the new size of the logical volume and click on the OK button to increase the size.

It increases the logical volume size that can be observed from the kvpm tool.

In order to extend the filesystem, select the Group: vg01 tab, select the logical volume lv02 and click on the Extend fs button.

A window prompts for confirmation before extending the filesystem.

Alternatively, the logical volume size and filesystem can also be confirmed using the command line interface. The lvdisplay and df commands can be used to display all the details of the logical volumes.

ubuntu@ubuntu:~$ sudo lvdisplay /dev/vg01/lv02

Mount the logical volume on the system and check the filesystem size.

ubuntu@ubuntu:~$ sudo mount /dev/vg01/lv02 /media/ubuntu/lv02

ubuntu@ubuntu:~$ sudo df -Th /dev/vg01/lv02

Conclusion

Extending the logical volume size for a server is a crucial task as a file system mounted on the server may run out of space. LVM provides facility to extend the logical volume size without facing any downtime. This blog explains all the steps to extend an existing logical volume and the filesystem using the command line interface and graphical user interface tool.

About the author

Usama Azad

A security enthusiast who loves Terminal and Open Source. My area of expertise is Python, Linux (Debian), Bash, Penetration testing, and Firewalls. Iā€™m born and raised in Wazirabad, Pakistan and currently doing Undergraduation from National University of Science and Technology (NUST). On Twitter i go by @UsamaAzad14