Shrinking an XFS partition?

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:

  1. Boot the system into the single user mode — not necessary if you are the only one to work on it.
  2. Copy the contents out from the partition to be shrinked.
  3. Umount the partition.
  4. Delete partition completely. If it’s a logical volume, delete the LV.
  5. Recreate partitions (LVs) with the size desired.
  6. Create XFS filesystem on them.
  7. Mount them to the proper mount points.
  8. Copy contents back to the original mount point.

References:

  1. Supported and Recommended File Systems on Linux (Doc ID 236826.1)
  2. Certification Information for Oracle Database on Linux x86-64 (Doc ID 1304727.2)
  3. How To Reduce Or Shrink an XFS Partition (Doc ID 2583343.1)
  4. Frequently Asked Questions Oracle Linux
  5. XFS Filesystem on Oracle Linux (Doc ID 1632127.1)
  6. https://www.oracle.com/linux/technologies/xfs-overview.html
  7. http://xfs.org/index.php/XFS_FAQ

Leave a comment