Tag Archives: defrag

PyFrag, Simple yet powerful Linux Defrag tool.

The last few weeks I’ve noticed lower performance in my media server than I should be getting out of my 6tb RAID5. At first I thought it was probably my ram, nope 3gb free. Then I checked the network, nope healthy ping and the internet performance and file transfers to other computers are fine. Cpu usage? Next to none. Then it occurred to me, maybe my files are fragmented. This is a big RAID and it’s usually 80-90% full. Research on the net of course came up with “lol linux doesn’t need defragmentation! Windows n00b!”. However the more I started to research the more I found more users with simular issues, looking for a defrag tool.

There is e2defrag, but I’m using ext4, e4defrag is designed specifically for this purpose as demand for a defrag tool slowly rises, but there isn’t a stable release yet and it doesn’t look like there’s going to be one any time soon. The common advise is to backup to new drives and format and restore all your data. If this was just an OS partition I would be ok with this, but this is a 6tb RAID drive with over 5tb of files on it! To back that up would take weeks at it’s current speed, WEEKS! I needed a defrag tool.

Hidden in the depths of the Ubuntu fourms I came across a python script called pyfragtools. Originally written in may 2006 by jdong It uses rsync, filefrag and a few other tools to automatically defrag a specified partition file by file. A simple technique but an effective one, not as powerful as a full partition aware format tool but useful nonetheless. However over the years this script became less and less useful as the original Author gave up on the project. Thankfully webbertiger has continued the work on the project and there is a well working version residing on the last few pages on the fourm post. After running this tool my RAID5 is back to normal performance. The main thing I like about this script is that it’s fairly safe to use and it supports virtually any filesystem Linux supports!

I must warn you though that this tool is not designed to be run while the drive is being written to, so make sure it’s not being used while you defrag. That in mind, with pyfragtools you eat your py and defrag it too!

pyfragtools