Home » OS » Linux » Defragmenting XFS file systems on Ubuntu 13.04

Defragmenting XFS file systems on Ubuntu 13.04

After using the XFS file system for a while, you might see it slow down a bit.  If so, you may need to defragment the file system.  Doing so is very easy but does require root access and the xfsdump package:

sudo aptitude install xfsdump

Now that we have the xfsdump package, we can use the xfs_db utility to determine the current fragmentation percentage:

sudo xfs_db -r /dev/sda6
xfs_db> frag
actual 95343, ideal 85809, fragmentation factor 10.00%
xfs_db> quit

As you can see, the estimated fragmentation percentage is 10%. Not bad but let’s get that down:

 sudo xfs_fsr -v /dev/sda6
/home start inode=0
ino=138
extents before:2 after:1 DONE ino=138
ino=100725
extents before:19 after:1 DONE ino=100725
ino=103896
extents before:17 after:1 DONE ino=103896
ino=474184
extents before:3 after:1 DONE ino=474184
ino=474183
extents before:2 after:1 DONE ino=474183
ino=474185
....

We can have XFS defrag all the mounted file systems automatically by creating a crontab job in /etc/cron.daily/xfs-defrag.sh:

#!/usr/bin/env bash
/bin/date >> /var/log/xfs.log
/usr/sbin/xfs_fsr -v 2>&1 >> /var/log/xfs.log
/bin/date >> /var/log/xfs.log
Share Button

Comments

  1. No, you don’t need to unmount the file system! 🙂

  2. Ubuntu feature request 307625 is a proposal to run the xfs defrag every day for 10 minutes by default.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*

Facebook login by WP-FB-AutoConnect