Defragment MythTV server runing XFS

I had been brought up with the impression, that you do not need to defragment a linux file system. In most cases this is true, but just by chance I read this article and have since changed my mind. I use XFS for both my hard drives that host MythTV recordings. I assume, that XFS can not guess the size of a recording and thus can not reserve that space on the hard drive in advance. This thus leads to higher fragmentation compared to just copying files from another source. My system had recordings that where cut into more than 5.000 chunks. By typing

xfs_bmap -v /var/lib/mythtv/recordings/*

you get a pretty good overview of how fragmented your MythTV recordings are. As a rule of thumb, the longer the list after the filename, the higher is your fragmentation. All you need to do to defragment your file system is type:


as root and wait two hours (default length). It will automatically defragment all your XFS file systems, no need to tell it what devices. To get six hours of defragmentation run:

xfs_fsr -t 21600

You should notice some improvements, especially when copying your files. If you want to know how fragmented your drive is just type:

xfs_db -r /dev/sdc1 -c frag

actual 94088, ideal 2790, fragmentation factor 97.03%

You see, my drive was 97% fragmented!

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.