• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

HowTos | Basics | Concepts

  • Solaris
    • Solaris 11
    • SVM
    • ZFS
    • Zones
    • LDOMs
    • Hardware
  • Linux
    • CentOS/RHEL 7
    • RHCSA notes
    • SuSE Linux Enterprise
    • Linux Services
  • VCS
    • VxVM
  • Interview Questions
  • oracle
    • ASM
    • mysql
    • RAC
    • oracle 12c
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Hadoop
    • Hortonworks HDP
      • HDPCA
    • Cloudera
      • CCA 131

CentOS / RHEL : How To Shrink LVM Root File System

By admin

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.

RHEL / CentOS : How to shrink LVM volume

Filed Under: Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to remove a mirror with mdadm
  2. CentOS / RHEL : How to find free space in a Volume Group in LVM
  3. How to configure IPtables to open Ports in CentOS / RHEL
  4. How to schedule Jobs with Cron in Linux
  5. How to Verify a Lun is in Active/Optimized Mode when ALUA Is Configured on Storage
  6. Linux Interview Questions : Open Files / Open File Descriptors
  7. RHEL 7 – RHCSA Notes – System documentation including man, info, and files in /usr/share/doc
  8. How to create LXC container using lxcbr0 and virbr0 in CentOS/RHEL
  9. CentOS / RHEL 4 : How to install and configure FTP server (vsftpd)
  10. Manual Changes Made To /etc/hosts Or /etc/sysconfig/network-scripts/ifcfg-* Are Lost

You May Also Like

Primary Sidebar

Recent Posts

  • Understanding “docker stats” Command Output
  • ‘docker images’ command error – “Permission Denied”
  • Docker Basics – Expose ports, port binding and docker link
  • How to split BCV and open oracle ASM database
  • How to change the interface name in CentOS/RHEL 8 using prefixdevname
  • Archives
  • Contact Us
  • Copyright

© 2019 · The Geek Diary