How to Extend Logical Volume in Redhat Linux using command line

One benefit of logical volumes is the ability to increase their size without experiencing downtime. Free physical extents in a volume group can be added to a logical volume to extend its capacity, which can be used to extend the file system it contains.

Extending logical volume

There are three steps needed to extend logical volume

  1. Verify the volume group has space available.

vgdisplay is used to verify that there are sufficient physical extents available for use.

Check the free PE/Size in the output. It should report a value equal to or more than the additional space required. If there is insufficient space available then extend the volume group by at least the required space.

vgdisplay command
  1. Extend the logical volume.

lvextend extends the logical volume to a new size. Add the LV device name as the last argument to the command.

      lvextend -L +300 /dev/vg/cycle

This will increase the size of logical volume cycle by 300 MiB. Remember that  the “+” in front of the size, which means add this value to the existing size; otherwise, the value defines the final, exact size of the LV.

Like lvcreate, there are multiple ways to specify the size. -l generally expects physical extent values, while -L expects size in bytes or larger named values, such as mebibytes and gigabytes.

Some examples:

  • lvextend -l 150: Resize the logical volume to exactly 150 extents in size.
  • lvextend -l +150: Add 150 extents to the current size of the logical volume.
  • lvextend -l 150M: Resize the logical volume to exactly 150 MiB.
  • lvextend -l +150: Add 150MiB to the current size of the logical volume.
  • lvextend -l +50%FREE: Add 50 percent of the current free space in the VG to the LV.
  1. Extend the filesystem

xfs_ growfs /mountpoint expands the file system to occupy the extended till LV. xfs_ growfs Requires the file system be  mounted while it is being Run; it can continue to be used during the reset operation.

Important Note:

How to Create Logical Volume Manager in Linux

A common mistake is to run every lvextend, but forgot to run xfs_growfs. An alternative to running the two steps consecutively is to include -r as an option with the lvextend command. This resize the file system after LV is extended.

You can verify the new size of the mounted file system.

df -h /mountpoint