Novell Home

How do I defragment my hard drive in Linux?

Novell Cool Solutions: Question & Answer

Rate This Page

Reader Rating  stars  from 28 ratings

Posted: 25 May 2005

Q:
When I was using Windows, I had to run a defragmentation program quite often to speed up my computer. Where do I do this in Linux?

A:
Unlike Windows' filesystems, most filesystems that run on Linux have no need of being defragemented because they prevent fragments from occurring in the first place.

If you use the default filesystem (ReiserFS), you'll never have to defragment your hard drive as long as you use it.

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

Reader Comments

  • All file systems can become fragmented since file sizes can grow and thus require the file to be moved if it doesn't fit in the adjacent space, which may place the file in a less convenient place on the drive (i.e. not near other commonly used files). Unless reiser has some way of rearranging a bunch of files on the fly, it cannot possibly do as good of a job as a full defrag/optimization. Will someone please code such a thing for reiser or ext3?
  • I am greatly relieved to hear these words. Thanks so much, Novell! You're brilliant! --Dylan, United States of America
  • Anyone who ignores defragment/otimization of their hard drive(s) is forcing a disaster. For those who can, copy the partition to another drive, reformat and copy back. IF IT WAS A BOOT PARTITION - rerun LILO. A Bootable CD-ROM is quite usefull for this purpose. One bootablefull system partition and one bootable miminal partition works well also. Use one to clean the other.
  • All filesystems are subject to fragmentation. And since disk drives are not Random Access Memory, this has an impact on performances. However, the fragmentation itself can be limited by the filesystem, at file creation (by trying to guess the file size and find optimal place), of by explicit or implicit (on the fly) defragmentation. And the fragmentation impact on performance can be reduced by use of cache and of better reading algorithms (read sequentially). The fact is that Linux filesystems tend to fragment less due to their on disk structure and allocation algorithms, and Linux itself does a good job to increase performance (intensive use of cache, read ahead feature, elevator algorithm for disk access). So does the Linux filesystem fragment? Yes, but not as much as the awfull (but simple and ubiquitous) FAT. Do you need to defrag? No. You will waste your time to get micro performance boosts after. So, practically, defragmentation is generally useless under Linux, except if you have uncommon usage on nearly full devices. And does exist a defrag utility for FAT32 under Linux: I don't think so, you'll have to boot Windows/DOS for that. Btw, defragmentation problem is specific to the kind of storage use: if the storage is random access (such as a memory card, flash or USB key), fragmentation is not a problem (and even, dispatching written block on the whole device is good for its lifetime). It's also dependant on the cache present. For instance, fragmentation of RAM is normally not a problem... because it is a RAM, but it can cause cache miss in the upper level (for instance processor) and decrease performance. But for good systems, all this is generally and practically not significant.
  • Reader comments are excellent is anyone going to respond to them? I have a external hard drive that I created using linux and I noticed it was running VERY poorly (FAT 32) and I had to hook it up to my windows system to defragment it as Windows defragmentor showed a great deal of fragmented files. I also noticed I needed to use HDcleaner on my external under Windows because I can't maintain and keep it cleaned up in linux.
  • the details, why reiserfs can't fragement (maybe a link to "how reiserfs works for non-programmers"), would help make the answer even better... (and btw: please use at least 10 px fontsize fot this field. this 4x or what is a catastroph. oh. and try to look if it's still ok when you reite more and the textarea's scrollbars appear [in firefox for ex.])
  • Generally speaking, this is true, although it is true that Fragmentation is inevitable for most filesystems (e.g. the one in Windows). A brief overview of Reiserfs can be found at http://en.wikipedia.org/wiki/ReiserFS. Also, the next generation of ReisferFS (Reiser4) will be designed to have a built in defragmenter, although I don't know when or if Novell will use this filesystem.
  • This question and answer is phrased in such a way that it overlooks the fact that someone might want to defragment a fat partition while using Linux.
  • While it is great that this almighty FS called ReiserFS never needs defraging (which I don't fully believe as files become larger and smaller all the time requireing them to be moved to a larger or smaller spod on the drive, what about ext3, 2 and all the other linux fs types out there.
  • I got a good knowledge on defragment
  • The subject has still not been addressed specifically, and the comments show conflicting feedback. One comment states ReiserFS never needs to be defragmented while other comments states ALL file systems become fragmented as files are added/removed/enlarged/reduced. We need a straight answer. Ext2, Ext3, and ReiserFS are not so new, someone must be in the know and able to give a definitive answer.
  • pretty much all current filesystems are prone to fragmentation, some just are less prone. A link to as to why fs xy is NOT affected by this would be good. thanks.

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.