Resizing a LVM Logical Volume
Problem
The following describes the process of resizing a logical volume using an installation of RHEL/CentOS.
Notable
- If the XFS file system is used, a volume can be increased, but not decreased, in size.
- Decreasing an Ext4 file system can be done offline only, which means that you need to unmount it before you can resize it.
- When resizing a LV with the file system it contains, nothing will happen to the file system, and its data will remain intact.
- Most file system resizing operations can be done online, without any need to unmount the file system.
Solution
Layer 1: Physical Volume (PV)
- Create a MBR or GPT partition.
-
Assign partition to PV.
pvcreate /dev/${DEVICE}
-
Verify the PV.
# Listing pvs # Summary pvdisplay # Hierarchical lsblk
Layer 2: Volume Group (VG)
-
Change the size of the VG.
# Increase vgextend ${VG_NAME} /dev/${DEVICE} # Reduce vgreduce ${VG_NAME} /dev/${DEVICE}
-
Verify the VG.
# Listing vgs # Summary vgdisplay
Layer 3: Logical Volume (LV)
-
Change the size of the LV.
# Increase relative size lvextend -r -l +50%FREE /dev/${VG_NAME}/${LV_NAME} # Decrease absolute size lvreduce -r -L -150M /dev/${VG_NAME}/${LV_NAME}
-
Verify the LV.
# Listing lvs # Summary lvdisplay # Filesystem df -h
-
Create a file system on top of the LV.
mkfs.xfs /dev/${VG_NAME}/${LV_NAME}
Summary
The main part of LVM flexibility resides in how easy it is to resize a VG and LV backed by a PV.