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.
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.