CentOS / RHEL : How To Shrink LVM Root File System

During system installation, one may allocate an over-generous amount of disk space to the root partition and may later wish to reclaim any unused space. The post describes how to reduce the space allocated to an root file system on a Linux Volume Manager (LVM) logical volume.

Note : this procedure applies only if the root file system (which holds the / directory) is provisioned as an EXT2/3/4 file system on an LVM device. It is possible to reduce the allocation of other non-EXT2/3/4 file systems, but each file system type requires its own process and is not described here.

Steps

1. Back up all data on the file system whose size is to be changed.

2. Boot the system into rescue mode, using an installation media copy.

3. Do not allow the rescue mode to detect and mount your root file system; the file system cannot be resized if mounted. Should your root file system be mounted, you must unmount it before proceeding:

# umount /mnt/sysimage

4. Detect and activate the LVM volumes like this:

# vgchange -ay

5. Make sure the file system is clean before attempting any changes:

# e2fsck -f /dev/[volumegou]/[logicalvolume]

6. Rerun the e2fsck application as needed until the file system is clean and no more errors are reported.

7. Before reducing the size of the now-clean file system, calculate the desired size of the changed file system and add a 10% margin for O/S overhead. For example, if you want the finished file system to have 100GB usable space, then the resize should allocate 110GB to allow for this overhead to avoid corrupting the finished file system.

8. You may now alter the size of the logical volume. Using the size from our previous example:

# resize2fs -p /dev/[volumegroup]/[logicalvolume] [size]

For example :

# resize2fs -p /dev/vg_geeklab/lv_root 110GB

9. The file system layout has been reduced and thus there is now spare space available in the logical volume. Adjust the size of the logical volume:

# lvreduce -L [newlvsize] /dev/[volumegroup]/[logicalvolume]

Note that when resizing the logical volume, use the exact size (for our example, 110GB).
For Example :

# lvreduce -L 110GB /dev/vg_geeklab/lv_root

10. Because of various physical alignment issues, there may well be slack space at the end of the new logical volume. Just grow the file system to fix the available space:

# resize2fs -f /dev/[volumegroup]/[logicalvolume]

By default, the resize occupies all available space.

11. Reboot the system out of rescue mode and observe the new disk allocation.

Related Post