-   Linux - Server (
-   -   What's the best way to defrag ext3? (

niri 11-29-2012 12:58 AM

What's the best way to defrag ext3?

I have a web server with centos 5.8.

There are many fragmented files, for example:

# filefrag /home3/files/ZSPNIMTLS2EVSX14ZU2RJYPEX0HU42JGCOJU.avi
/home3/files/ZSPNIMTLS2EVSX14ZU2RJYPEX0HU42JGCOJU.avi: 226 extents found, perfection would be 6 extents

# filefrag /home3/files/YEUBCBYNY02E4VT2ODWUCTAJAY5WVSSGXEEK.avi
/home3/files/YEUBCBYNY02E4VT2ODWUCTAJAY5WVSSGXEEK.avi: 222 extents found, perfection would be 6 extents

# filefrag /home3/files/VMV2SOC3OP0DAVUG1DTIFPX5VHQSPPED4331.avi
/home3/files/VMV2SOC3OP0DAVUG1DTIFPX5VHQSPPED4331.avi: 224 extents found, perfection would be 6 extents

How to reach perfection state?
Currently I get very poor HDD throughput.


pan64 11-29-2012 06:35 AM

see here:

markush 11-29-2012 09:05 AM

Hello niri, welcome to LQ,

if you want to defrag a filesystem, you should use Windows.


wpeckham 11-29-2012 03:21 PM

EXT filesystems (and most Linux file systems in general) defragment themselves over time. That said, if you use the storage in such a way as to promote fragmentation, moving to EXT4 with delayed allocation seems to help a LOT. On a busy system it reduces fragmentation during new file creation dramaticly, and fragmentation has less impact on performance than it does with EXT3.

There are newer file systems that should have even better properties, but they do not seem quite ready. Yet.

I suspect that your storage performance issues may not be due to fragmentation, but it would take a significant effort to test enough to be sure.

k3lt01 11-29-2012 05:45 PM

The easiest way I know of defragmenting ext3, not that it needs it anyway, is to copy the entire system to another drive and then copy it back. The writing process automatically puts the file fragments in their corerct position. I have a system running Debian Sid here and its fragment status is 0.2% I wouldn't think that is an issue.

PTrenholme 11-29-2012 06:41 PM

Your best solution, in my opinion, would be to combine the suggestions in the two prior posts (#4 and #5), by copying the ext3 file system into an ext4 one, and using the new ext4 one to replace the old one. Note, however, that you cannot copy system files (/dev, /proc, etc.) and expect things to keep working. (rsync can be used for system files. In fact, consider changing your file system to ext4 and then just restoring the files from your back-ups.) IIRC, you can convert an ext3 file system to an ext4 on "on the fly," but - if I were to attempt that - I'd make sure that I had at least two working back-ups. . .

jefro 11-29-2012 07:49 PM

The old way was to back up to tape as in tar and replace the data. Still works.

All times are GMT -5. The time now is 10:52 AM.