Date: Tue, 07 Jan 2003 11:49:21 -0800
From: Rick Moen (rick@linuxmafia.com)
Subject: Re: Defragging
To: luv@luv.asn.au

Quoting john (voltan@bigpond.com):

> 1. Do I need to defrag the Fat32 drive? If so, how do I do this from
> Linux?

I don't know of any FAT32 defragmenters that run under Linux, but perhaps someone will suggest one. (If so, you'll probably want to run it from single-user mode, to protect filesystem integrity.) There's none, for example, in the most-recent release of the dosfstools for Linux.

> 2. Why don't I need to defrag Linux? (General knowledge question.)

Most filesystem types of the last quarter-century have a designed-in tendency to resist fragmentation, provided that they're not too close to 100% full. The only exceptions I know of — filesystem types that lack this feature — are FAT, NTFS, and VMS's partitions. (Note that the VMS design team were hired by Microsoft Corporation to write MS-Windows NT.)

The matter isn't very well documented, that I've seen. Here's one fellow who discusses it: https://listman.redhat.com/archives/seawolf-list/2002-February/msg00124.html

Also this one: https://listman.redhat.com/archives/ext3-users/2002-February/msg00072.html
Quoting:

"Utilities exist for such a purpose (look on http://freshmeat.net), but little purpose exists for them. Unix filesystems by their very nature resist fragmentation very strongly. It is not uncommon for even a very full, very heavily used filesystem to keep its fragmentation under 15%. Also, because of advanced read-ahead, disk buffers, and file caches, Unix also tends to be much less affected by fragmentation than, say, MS Windows of any variety."

If you ever wish to manually defragment an ext2 partition anyway, there's Stephen Tweedie "defrag" aka e2defrag tool, which you can get here: http://www.ibiblio.org/pub/Linux/system/filesystems/ See the Linux System Administrator's Guide, http://tldp.org/LDP/sag/html/x1319.html .

However, defrag is old (last updated August 1997!), is unmaintained, was always experimental, and is very likely dangerous to your data. (If you do use it, it's vital that you allow it to complete, or you will almost certainly lose data.)

Personally, I would much, much rather back up the filesystem (using a file-by-file tool such as tar), confirm the integrity/completeness of my backup, blow the original filesystem away, mkfs it again, and then put the data back. If fragmentation were a problem — which it is not.

In other words, the only defragmenter I can properly recommend, if you insist you need one, is mkfs (i.e., backup, destructive reconstruction of the partition, and a restore operation).

-- 
Cheers,               I have /usr/sbin/coffee mounted from /dev/mug right now, 
Rick Moen             and you can't have it.  Oh no, I just tried to seek past 
rick@linuxmafia.com   end-of-beverage. *sigh*  -- Graham Reed, in the Monastery




Date: Sat, 09 Jun 2007 17:17:58 +0100
From: Jeroen Massar, jeroen@unfix.org
Organization: Unfix
To: Lisa Muir, 34.24.34@gmail.com
Cc: ilug@linux.ie
Subject: Re: [ILUG] Defragmenting

Jeroen Massar wrote:
> Lisa Muir wrote:
> Just done a quick Google to see if I can find a tool for
> defragmenting a disk under Linux, but all hits quickly refer to Windows.
>
> > Can anyone recommend such a tool?
>
> Recommend no as Ext2/3 _should_ automatically defrag itself, so I
> actually never bothered doing one :)

Replying to self :) [Who invented Google, lets shoot them!]

I found:
http://www2.lut.fi/~ilonen/ext3_fragmentation.html
and:
http://www.informatik.uni-frankfurt.de/~loizides/reiserfs/fibmap.html

These tools can tell you how much fragmentation is happening on your disk.

Short test:
... see below ...

Non-contiguous:
  Files 63 (34631.0MB, avg. 562891.60kB per file), blocks 171345,
average block 206.96kB
Contiguous:
  Files 12 (0.1MB, avg. 8.73kB per file)

So that kind of empirically proves that ext3 *DOES* fragment.

# apt-get install defrag

defrag here I come, unfortunately it means you have to turn the disk offline... (umounted)

Greets,
Jeroen

 64826 3832.6MB    60.54kB a
 34137 2766.2MB    82.98kB b
 17071  831.3MB    49.86kB c
 12442  686.5MB    56.50kB d
  8706  779.3MB    91.66kB e
  7299 4280.4MB   600.51kB f
  5238  699.5MB   136.74kB g
  3247 4480.8MB  1413.09kB h
  3110 4403.9MB  1450.03kB i
  2071  490.4MB   242.47kB j
  1691  626.5MB   379.40kB k
  1533  736.1MB   491.70kB l
  1396  616.3MB   452.05kB m
  1395  698.7MB   512.85kB o

eek 60k pieces... not good!





RM comments: First cited hyperlink is to a page by a user of the "fibmap" fragmentation-measuring utility. As evidence of my point that fragmentation on Linux-native filesystems "have a designed-in tendency to resist fragmentation, provided that they're not too close to 100% full", the author admits, in the one case where he found significant fragmentation:

So in this case the partition was heavily fragmented, but that is not very surprising because the partition is a bit too small and has therefore been always nearly full.




Date: Sat, 09 Jun 2007 16:11:05 +0100
From: Robert Sweetnam, linux@sweetnam.eu
To: Lisa Muir, 34.24.34@gmail.com
Cc: ILUG list, ilug@linux.ie
Subject: Re: [ILUG] Defragmenting

Lisa Muir wrote:
> Just done a quick Google to see if I can find a tool for defragmenting
> a disk under Linux, but all hits quickly refer to Windows.
>
> Can anyone recommend such a tool?

Are you trying to defrag a FAT(32) disk under Windows? If the partition is a Linux partition, EXT2 or 3 or ReiserFS, then you should not need to defrag it, as the filesystems prevent fragmentation occurring in the first place.

"http://www.novell.com/coolsolutions/qna/15032.html
http://geekblog.oneandoneis2.org/index.php/2006/08/17/why_doesn_t_linux_need_defragmenting

Regards,
Robert





RM comments: Christopher Browne has a good general summary of the situation, here: http://cbbrowne.com/info/defrag.html