How to Reduce an LVM volume on Ubuntu

Question: How can I shrink an existing LVM volume to free up some space on my Ubuntu Machine?

Backup existing data

Before modifying any system, it is always recommended to create a backup first as there is an elevated risk of data corruption with reducing an LVM size. In most cases, the lvreduce command warns about possible data loss and asks for a confirmation. However, you should not rely on these confirmation prompts to prevent data loss because in some cases you will not see these prompts, such as when the logical volume is inactive or the –resizefs option is not used. Note that using the –test option of thelvreduce command does not indicate where the operation is safe, as this option does not check the file system or test the file system resize.

Find the name of the logical volume that you would like to shrink (This example uses logical volume /dev/vg0/lv_data):

# lvs

For this example here is the current and expected volume size.

Current Volume Size: 100GB
Expected Volume size: 80GB

Run FS check

To perform a lvreduce, the disk must be unmounted, so this must be done when there is no need for activity on the disk. Then run a filesystem check to verify data integrity:

# umount /dev/vg0/lv_data
# e2fsck -f /dev/vg0/lv_data

Reduce the Volume

Resize the logical volume using the lvreduce command. This command can shrink the file system along with the logical volume.

# lvreduce -r -L 80G /dev/vg0/lv_data

Notice the -r flag here. As per man page of lvreduce:

-r|--resizefs
       Resize underlying filesystem together with the LV using fsadm.

Mount the Volume

You can mount the logical volume again:

# mount /dev/vg0/lv_data

Now the volume group has 20G of free space. You can then use lvcreate to create your new logical volume using the 20G free space.

Conclusion

In older Linux systems, lvreduce was missing “-r” option, which takes care of resizing underlying filesystem, hence, resize2fs is mandatory before shrinking logical volume. But this is not required any more.

Related Post