How to Resize an LVM Logical Volume to Use Maximum Free Space

In Linux, Logical Volume Management (LVM) allows you to dynamically resize logical volumes to efficiently manage your storage. If you have free space available in your Volume Group and want to expand a logical volume to use this space, follow these steps:

Checking Disk Space

Before resizing the logical volume, it’s essential to check the available free space and the current usage using the df -h command:

1
df -h

This command will display information about your filesystems, including their sizes, used space, and available space.

Extending the Logical Volume

Assuming you have identified the logical volume you want to resize, you can extend it to use all available free space. Replace /dev/mapper/ubuntu--vg-ubuntu--lv with the path to your logical volume in the following command:

1
lvextend -l+100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  • lvextend is the command used to extend logical volumes.
  • -l+100%FREE specifies that you want to use 100% of the available free space.
  • /dev/mapper/ubuntu--vg-ubuntu--lv should be replaced with the path to your logical volume.

Resizing the Filesystem

After extending the logical volume, you need to resize the filesystem to make use of the additional space. Use the resize2fs command for this purpose:

1
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
  • resize2fs is the command to resize the ext2, ext3, or ext4 filesystem.
  • /dev/mapper/ubuntu--vg-ubuntu--lv should be replaced with the path to your logical volume.

Verifying the Changes

To ensure that the resizing was successful and that the filesystem now uses the maximum available space, you can once again use the df -h command:

1
df -h

This will display the updated information about your filesystems, including the increased size and available space.

By following these steps, you can easily resize an LVM logical volume to make use of the maximum free space available in your Volume Group. Remember to replace /dev/mapper/ubuntu--vg-ubuntu--lv with the appropriate path to your logical volume.

0%