Resizing a Logical Volume in an LVM Filesystem





Last Updated on 04/19/2017 by dboth

The need to resize a filesystem has been around since the beginning of the first versions of Unix and has not gone away with Linux. It has gotten easier, however, with Logical Volume Management.

This article covers resizing an existing Logical Volume in an LVM environment using the Command Line Interface (CLI). It adds about 50GB of space to the /Stuff filesystem. This procedure can be used on a mounted, live filesystem only with the 2.6 Kernel (and higher) and Ext3 and EXT4 filesystems. I do not recommend that you do so on any critical system, but it can be done and I have done so many times; even on the root (/) filesystem. Use your judgment.

WARNING: Not all filesystem types can be resized. The EXT3, EXT4, BTRFS and XFS filesystems can be resized on the fly on a running, mounted filesystem. Other filesystems may not be able to be resized. Be sure to check the documentation for the filesystem you want to resize to ensure that it can be.

Install hard drive

If there is not enough space on the existing hard drive(s) in the system to add the desired amount of space it may be necessary to add a new hard drive and create the space to add to the Logical Volume.

First install the hard drive and then perform the following steps.

Create Physical Volume from hard drive

It is first necessary to create a new Physical Volume (PV). Use the command below, which assumes that the new hard drive is assigned as /dev/sdc.

pvcreate /dev/sdc

It is not necessary to create a partition of any kind on the new hard drive. This creation of the Physical Volume which will be recognized by the Logical Volume Manager can be performed on a newly installed raw disk or on a Linux partition of type 83. If you are going to use the entire hard drive, creating a partition first does not offer any particular advantages and uses disk space for metadata that could otherwise be used as part of the PV.

Add PV to existing Volume Group

After the Physical Volume has been created, extend the existing Volume Group (VG) to include the space on the new PV. In this example the existing Volume Group is named MyVG01.

vgextend /dev/MyVG01 /dev/sdc

Expand the Logical Volume

The rest of these steps are performed whether a new hard drive was installed or not. Note that the rest of these steps can be performed while the system is up and running and the filesystem being expanded can be mounted and active during the expansion.

First expand the Logical Volume (LV) from existing free space within the Volume Group. The command below expands the LV by 50GB. The Volume Group name is MyVG01 and the Logical Volume Name is Stuff.

lvextend -L +50G /dev/MyVG01/Stuff

Expand the filesystem

Expanding the Logical Volume does not expand the filesystem. That task must be performed separately. The command below resizes the filesystem to fit the newly resized Logical Volume.

resize2fs /dev/MyVG01/Stuff

 





Leave a Reply