At boot, fsck sometimes reports the frgmentation for a disk: "5.3% non-contiguous".
How can I get this information myself? Is there a specific fsck invocation?
Yes, there is a specific
Replace X and Y with the correct parameters for your case (e.g.
DO NOT RUN THIS ON A MOUNTED PARTITION! It can seriously damage your filesystem.
For some more information on Linux and defragmenting, see my answer here.
If you do not need to specifically run fsck, but just want to check your drive's fragmentation, the following script (taken from here) should do the trick:
You can then run it on the directory (or mount point) in question:
You can use a tool like e2defrag to get this information.
Do mind that because of the nature of Linux file systems, defragging is normally unnecessary.
|show 3 more comments|
The modern ext family of filesystems take balancing and contiguity into consideration when allocating files. In ext3 and ext4 balancing is generally taken care of by applying journal entries in order, and in ext4 specifically, by pre-allocating file-system extents to increase contiguous blocks. Chasing fragmentation levels lower than 20% might not be worth your time, especially if your system is accessing a few files repeatedly. I suggest pursuing these tactics for increasing read speed for a single disk system:
If you have multiple disks and are using raid striping and/or LVM, you other factors to consider, such as stripe size.