Occasionally there might be a need to shrink a disk filesystem. For example when customizing a pre-built OS with filesystems from a template to meet the storage available specific to your envrionment.
It’s possible to use resize2fs to shrink an ext2/3/4 filesystem. But when talking about XFS, the thing is quite different — XFS cannot be shrinked!
XFS is a high-performance 64-bit journaling file system created in 1993 and it’s been introduced in Linux world for more than 20 years. Starting with Red Hat Enterprise Linux 7, XFS is the default file system, which is the same for Oracle Linux 7 & 8.
- XFS supports metadata journaling, which facilitates quicker crash recovery.
- The XFS file system can be defragmented and enlarged while mounted and active.
As Red Hat has stated: “While XFS file systems can be grown while mounted, their size cannot be reduced at all.“
So if you are lucky as I was, to shrink a non /boot or / partition, here are steps you can take:
- Boot the system into the single user mode — not necessary if you are the only one to work on it.
- Copy the contents out from the partition to be shrinked.
- Umount the partition.
- Delete partition completely. If it’s a logical volume, delete the LV.
- Recreate partitions (LVs) with the size desired.
- Create XFS filesystem on them.
- Mount them to the proper mount points.
- Copy contents back to the original mount point.
- Supported and Recommended File Systems on Linux (Doc ID 236826.1)
- Certification Information for Oracle Database on Linux x86-64 (Doc ID 1304727.2)
- How To Reduce Or Shrink an XFS Partition (Doc ID 2583343.1)
- Frequently Asked Questions Oracle Linux
- XFS Filesystem on Oracle Linux (Doc ID 1632127.1)