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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to shrink root filesystem on CentOS / RHEL 6

by admin

By default, when you install the CentOS/RHEL OS, it creates a default layout consisting of a /boot partition and swap logical volume and then allocates all remaining space to one logical volume to be used for the root file system. Placing all data and system files in one file system is not always the best approach for large or production systems.

It is possible to reduce the size of the root file system and the logical volume on which it resides allowing the space to be allocated to auxiliary volumes without reinstalling the system. We can reduce the root filesystem in the rescue mode. For the purpose of this example, we will take /dev/VolGroup00/LogVol00 as the root filesystem.

Note: Note that if the volume group and logical volume names differ from the default VolGroup00 and LogVol00 the appropriate names and paths should be substituted in the commands given in this article.

Reduce the size of root filesystem

1. First, boot the system into rescue mode.

2. Activate the logical volume to be reduced. In this example, /dev/VolGroup00/LogVol00 was made available with the following command:

# lvm lvchange -ay /dev/VolGroup00/LogVol00

3. Reduce the size of the file system and logical volume on /dev/VolGroup00/LogVol00. Ensure there is sufficient space left on the root file system and that the logical volume is large enough to contain all the data that was previously present. Attempts to reduce the size of a file system beyond its current utilization will fail with an error message indicating that there is insufficient space. Before resizing file system, run the e2fsck command to perform a file system check:

# e2fsck -f /dev/VolGroup00/LogVol00
# resize2fs /dev/VolGroup00/LogVol00 3000M

4. Finally reduce the size of the logical volume containing the root file system:

# lvm lvreduce -L 3000M /dev/VolGroup00/LogVol00

The commands used in these examples specify the final size of the file system rather than the amount of space by which it should be reduced.

Alternate command to lvreduce – lvresize

The LVM2 commands support the alternative lvresize command which accepts relative sizes should this be more convenient. For example:

# lvresize -L -2000G VolGroup00/LogVol00

5. Finally, verify the modification and reboot the system by exiting the rescue shell.

# lvm vgdisplay VolGroup00

To leave the rescue shell:

# exit
WARNING: Resizing a mounted or in-use logical volume may lead to severe data loss. Plan and act accordingly and always ensure that a recent verified backup is in place.

Note on XFS filesystem

CentOS/RHEL 7 has a default filesystem of XFS which cannot be reduced in size. If a custom setup was created during installation which utilized an EXT filesystem instead, the above steps should also apply.

Workaround

While the XFS file systems can be grown while mounted, their size cannot be reduced as the feature is deemed to be complex and risky, and limited critical use cases are believed to exist. In some cases, the following workarounds may be acceptable:

  • Use thin-provisioned LVM volumes below the XFS filesystem.
  • Use some backup/restore solution, such as xfsdump/xfsrestore. This may be useful especially if the filesystem is mostly empty.

Filed Under: CentOS/RHEL 6, Linux, OEL 6

Some more articles you might also be interested in …

  1. “comm” Command in Linux with Examples
  2. pacstall Command Examples
  3. How to add or delete a samba user under Linux
  4. Why Does a Lun World Wide ID Starts with the Number 3 in Linux dm-multipath
  5. How to block non-root user from creating crontab entry in Linux
  6. gedit: command not found
  7. CentOS / RHEL : How To Shrink LVM Root File System
  8. How to Install gnome-session-wayland software package in Ubuntu
  9. How to Use rpm2cpio Command in Linux
  10. How to enable/disable SELinux Modes in RHEL/CentOS

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright