How to reduce XFS filesystem on Redhat Enterprise Linux or CentOS ?
XFS filesystem is the default filesystem that comes with RHEL 7, and is considered as highly scalable and high performance filesystem.
Ideally XFS filesystem can only be increased in size and can’t be reduced on Redhat Linux system.
Today we will see the trick how to reduce XFS filesystem on RHEL or CentOS.
The logic to achieve this is to take backup of XFS filesystem using xfsdump and then create new LV of reduced size, format it with XFS and then restore the contents using xfsrestore utility.
Lets see how to achieve this task step by step.
1. Install XFS backup tool
# yum -y install xfsdump
2. Take backup of the sample filesystem
# xfsdump -l 0 -f /home.image /dev/xfs_fs/home -l options speicifies the dump level, "0" specifies to perform full backup, -f specifies the target backup image path
2. Destroy Old partition: Umount and remove LV.
# umount /dev/xfs_fs/home # lvremove /dev/xfs_fs/home
3. Create new reduced size XFS partition.
a. Create LV # lvcreate -L 10G -n home xfs_fs b. Format it # mkfs.xfs /dev/xfs_fs/home c. Mount # mount /dev/xfs_fs/home /home
4. Restore data back.
# xfsrestore -f /home.image /home
Hence after restoring the data, we have complete disk data on our new partition with reduced size.