Defragging?

Soldato
Joined
1 Jul 2007
Posts
21,898
Location
Various
Do you need to defragment when using Linux, or are files stored in a way that renders it unnecessary?

If you do need to, can somebody recommend me a program to do it with? Is there a terminal command that can do it? I'm running Linux Mint 5 (basically Ubuntu 8.04).
 
You don't need to defrag under Linux. Welcome to the advantages of an actually modern file system :)
 
All read/write filesystems get fragmented, even Linux ones, although usually far less than NTFS. XFS is the only filesystem for Linux which has an online defrag utility - xfs_fsr
 
All read/write filesystems get fragmented, even Linux ones, although usually far less than NTFS. XFS is the only filesystem for Linux which has an online defrag utility - xfs_fsr

Ext2/Ext3 works in a rather different fashion to NTFS and FAT which tend to shove bits anywhere that is free on the hard disk. Ext3 always puts the file's bits as close together on a hard disk as possible, resulting in such dramatically lower fragmentation as to be negligible except on a system with an extremely high amount of file creation and deletion, e.g. an enterprise level or above mail server. Even then the impact on performance is minor at best, unless you're operating with only a small amount of disk space free; unlike, say, NTFS where even a monthly defrag will see huge benefits. Off the top of my head there is an ext2 defragger, but it's not been updated to work with ext3, or if it has no one has found significant enough advantage in it to bother releasing it. With the way Linux development takes place if there was any benefit at all of defragging it there would be a mainstream open source utility for it. There is one on its way for ext4, but performance advantages from it are shown to be so minor it's almost not worth wasting time with.

File systems like ReiserFS4 automatically defragment as you go along, ResierFS doesn't and isn't quite so good about fragmentation, but hey that wife murderer's file system isn't so mainstream these days as to be a problem ;)

XFS uses something called lazy evaluation for allocating files. Instead of being writted straight to disk a file is written to the buffer cache and instead of allocating specific sectors for the data, XFS reserves the appropriate amount of space for the data held in the buffer cache. Specific block allocation only happens when XFS comes to finally write the data to the actual hard disk. This pretty much dramatically reduces the chances of files ending up fragmented on a hard disk, along with associated performance advantages. When I've been administrating mail servers for ISP/Enterprise level, XFS has been my preferred file system for the heavy accessed mount point, primarily because the large number of reads and writes are transitory.

If you're really really bored, utterly convinced your filesystem is fragmented, and have good backups you might try this script, but no promises:
http://ck.kolivas.org/apps/defrag/

A tool for finding how fragmented your ext3 filesystem is: http://sourceforge.net/project/showfiles.php?group_id=132340
 
"e2fsck -vn $device" is a quick way to show fragmentation on ext{2,3}.
I used to use XFS as my preferred Linux FS, but the benefits of the agressive write buffering/allocation ordering was outweighed by the risk of corruption with flaky power supplies for my particular scenarios :)
 
Why doesn't MS update NTFS to where it doesn't need defraging? :confused:

Microsoft don't like to break eggs. There are scores of people using all sorts of weird hardware components and peripherals with their PCs and MS tend to play it as safe as possible to avoid losing those customers. That's admirable to a fair extent, but there does come a point when you need to throw the whole thing out the window and start again; which is essentially what Apple did with OSX.
 
Microsoft don't like to break eggs. There are scores of people using all sorts of weird hardware components and peripherals with their PCs and MS tend to play it as safe as possible to avoid losing those customers. That's admirable to a fair extent, but there does come a point when you need to throw the whole thing out the window and start again; which is essentially what Apple did with OSX.

That's easy to do when you have the amount of customers Apple had at the time though. Hardly a wise thing to do with the amount of customers Microsoft have.
 
Back
Top Bottom