Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Defrag in linux?

4 views
Skip to first unread message

tuximus

unread,
Mar 25, 2001, 11:42:51 AM3/25/01
to

How do you defragment a linux filesystem?

Thanks
Tuximus

A V Flinsch

unread,
Mar 25, 2001, 11:57:00 AM3/25/01
to
In article <fepv6.130115$p66.36...@news3.rdc1.on.home.com>, "tuximus"
<tux...@my-deja.com> wrote:


> How do you defragment a linux filesystem? Thanks

Depends on what type of filesystem you are using, but in general you
don't need to do it.

Most linux systems use ext2, which is fairly immune to fragmentation.
When it does get fragmented, the best way to fix it is to back
everything up, do a mkfs on the filesystem and restore the backup.

Peter T. Breuer

unread,
Mar 25, 2001, 12:57:35 PM3/25/01
to
tuximus <tux...@my-deja.com> wrote:

> How do you defragment a linux filesystem?

Short answer: you don't.

This is a FAQ, so look for a longer answer in the linux FAQ. It should
be on your disk (I'm not going to do the lookup for you, but believe
me, the answers to such things are there or thereabouts). Basically,
most filesystems don't fragment, and if they do it's a good thing.
It's only the ancient msdos FS that has this problem.

Peter

Texstar

unread,
Mar 25, 2001, 2:35:01 PM3/25/01
to
tuximus wrote:

It is not required. Remember this is Linux not Windows.


Dan Sarginson

unread,
Mar 25, 2001, 5:57:15 PM3/25/01
to
On Sun, 25 Mar 2001 16:42:51 GMT, tuximus <tux...@my-deja.com> wrote:

>
>How do you defragment a linux filesystem?
>

You don't... the ext2 filesystem is rather clever, and *generally*
doesn't require you to defragment the hard drive. I believe there are
utilities out there that do a similar thing, but none spring to mind.
If you're really getting into problems, you may want to try on of
those...

Dan Sarginson
[Quite new to 'ux by the way]


Jan Eric Andersson

unread,
Mar 25, 2001, 8:44:33 PM3/25/01
to
tuximus wrote:

> How do you defragment a linux filesystem?

Why would you want to?

Jan Eric


[Steve]

unread,
Mar 25, 2001, 11:42:40 PM3/25/01
to
> > How do you defragment a linux filesystem?
>
> Short answer: you don't.
>
...

> It's only the ancient msdos FS that has this problem.
>

NTFS has major problems with defragmentation too.


s

unread,
Mar 26, 2001, 5:20:50 AM3/26/01
to
Dude,
Where is/are your site(s)? Lost in the cyber abyss? I was looking for
one/some of your tutorials a few days back and my bookmarks didn't work.
Got page can't be found errors.
-s

Texstar wrote:
>
> It is not required. Remember this is Linux not Windows.
>
>
>

--
linux inside

Roy Oestensen

unread,
Mar 26, 2001, 7:55:41 AM3/26/01
to
"Jan Eric Andersson" <haes...@piasanet.com> skrev i melding
news:Aaxv6.3885$551.5...@news-west.usenetserver.com...

Because anyone used to Windows would be concerned about fragmentation, even
if using Windows NT or 2000.

Roy


Lew Pitcher

unread,
Mar 26, 2001, 8:41:45 AM3/26/01
to
On Sun, 25 Mar 2001 16:42:51 GMT, tuximus <tux...@my-deja.com> wrote:

Let's explain this again..... <g>


In general, fragmentation is a concern when one (and only one) process
access data from one (and only one) file. When more than one file is
involved, the disk addresses being requested are 'fragmented' wrt the
sequence that the driver has to service them, and thus it doesn't
matter to the device driver whether or not a file was fragmented.

To illustrate:

I have two programs executing simultaneously, each reading two
different files. Assume that the file system contains four files (file
1, file 2, file 3, and file 4) allocated in ascending contigious
blocks. The filesystem would be in an 'unfragmented' state, and would
look like

|-File 1-|-File 2-|-File 3-|--File 4---|
|b1,b2,b3|b1,b2,b3|b1,b2,b3|b1,b2,b3,b4|
+--------+--------+--------+-----------+

The programs access files in the following manner:

Program 1 reads file 1, block 1
file 1, block 2
file 2, block 1
file 2, block 2
file 2, block 3
file 1, block 3

Program 2 reads file 3, block 1
file 4, block 1
file 3, block 2
file 4, block 2
file 3, block 3
file 4, block 4

The OS scheduler causes the programs to be scheduled and executed such
that the device driver receives requests
file 3, block 1
file 1, block 1
file 4, block 1
file 1, block 2
file 3, block 2
file 2, block 1
file 4, block 2
file 2, block 2
file 3, block 3
file 2, block 3
file 4, block 4
file 1, block 3

As you can see, the accesses are already 'fragmented' and we haven't
even reached the disk yet. I have to stress this, the above situation
is _no different_ from an MSDOS single file access against a
fragmented file.

So, how do we minimize the effect seen above? If you are MSDOS, you
reorder the blocks on disk to match the (presumed) order in which they
will be requested. OTOH, if you are Linux, you reorder the _requests_
into a regular sequence that minimizes disk access. You also buffer
most of the data in memory, and you only write dirty blocks. In other
words, you minimize the effect of 'disk file fragmentation' as part of
the other optimizations you perform on the _access requests_ before
you execute them.

Now, this is not to say that 'disk file fragmentation' is a good
thing. It's just that 'disk file fragmentation' doesn't have the
*impact* here that it would have in MSDOS-based systems. The
performance difference between a 'disk file fragmented' Linux file
system and a 'disk file unfragmented' Linux file system is minimal to
none, where the same performance difference under MSDOS would be huge.
Under the right circumstances, fragmentation is a neutral thing,
neither bad nor good.

As to defraging a Linux filesystem (ext2fs), there are tools
available, but (because of the design of the system) these tools are
rarely (if ever) needed or used. That's the impact of designing up
front the multi-processing/multi-tasking multi-user capacity of the OS
into it's facilities, rather than tacking
multi-processing/multi-tasking multi-user support on to an inherently
single-processing/single-tasking single-user system.

Lew Pitcher
Information Technology Consultant
Toronto Dominion Bank Financial Group

(Lew.P...@td.com)


(Opinions expressed are my own, not my employer's.)

Darb

unread,
Mar 26, 2001, 11:57:22 AM3/26/01
to
There is an ext2 defragger... I haven't used it in a long time, so check its
documentation to make sure it is up to date with current versions of ext2.

You can get it from sunsite @:
ftp://sunsite.unc.edu/pub/Linux/system/filesystems/defrag-0.70.tar.gz

If you are defragging a runtime necessary file system, put this utility on
your emergency recovery media. Boot from the recovery media and then do
the defrag on the filesystem(s) you wish. Never, I repeat, NEVER do this
to a mounted filesystem. I don't know about now, but it used to let you.
(Yes, *evil*.)

*TheDarb

tuximus <tux...@my-deja.com> wrote:

> Thanks
> Tuximus

--

Jan Eric Andersson

unread,
Mar 26, 2001, 12:21:45 PM3/26/01
to
[Steve] wrote:

Only Mickeysoft doesn't supply a defragger with NT :^)

Jan Eric


Jan Eric Andersson

unread,
Mar 26, 2001, 1:29:30 PM3/26/01
to
Roy Oestensen wrote:

Yeah, but Linux ain't windoze :^)

Jan Eric


Jan Eric Andersson

unread,
Mar 26, 2001, 1:43:39 PM3/26/01
to
Lew Pitcher wrote:

> Let's explain this again..... <g>

Thanks for a very clear explanation, Lew, much better than I could have
explained it myself :^)

I hope you don't mind if I save it and use it next time someone asks me
about this issue?

Jan Eric


Lew Pitcher

unread,
Mar 26, 2001, 2:48:39 PM3/26/01
to

Not at all; that's what I did <g>.

I originally wrote that response to another "where's the Linux defrag"
question, and the response was encouraging enough that I kept it
around.

Jan Eric Andersson

unread,
Mar 26, 2001, 4:39:44 PM3/26/01
to
Lew Pitcher wrote:

> Not at all; that's what I did <g>.

Good, good, quite in the spirit of open source :^)

> I originally wrote that response to another "where's the Linux defrag"
> question, and the response was encouraging enough that I kept it
> around.

I do know about this, and I explained it[1] to my wife when she asked me
about it[2] after I weaned her from the dark side :^)

I'm considering making a new section of my website[3] to deal with these
common kinds of questions that I see here all the time[4], I'll put it
there as well, along with any other answers and fixes I think will be
useful.

Jan Eric

[1] Not as clearly, I fear, but she got the point

[2] She was accustomed to defragging at least weekly

[3] When I get it up and running again[5]

[4] Like that "I have no sound as a user" thing and "how do I upgrade to
KDE 2.1" and so on

[5] I've changed both countries and ISP's since it last was up, and I
haven't gotten around to it[6] yet.

[6] Anyone got a round tuit they could spare? I always seem to be running
out of them :^)


Mike Fell

unread,
Mar 28, 2001, 12:34:38 PM3/28/01
to

On 26-03-01, 3:41:45 PM, pit...@tdbank.ca (Lew Pitcher) wrote regarding
Re: Defrag in linux?:

> On Sun, 25 Mar 2001 16:42:51 GMT, tuximus <tux...@my-deja.com> wrote:

> >
> >How do you defragment a linux filesystem?
> >
> >Thanks
> >Tuximus

> Let's explain this again..... <g>

[big snip]

Hi Lew

that was very nice. Thanks for taking the trouble :-)

Regards
Hannibal

Jan Eric Andersson

unread,
Mar 28, 2001, 9:00:06 PM3/28/01
to
Preamp wrote:

>>> NTFS has major problems with defragmentation too.
>>
>>Only Mickeysoft doesn't supply a defragger with NT :^)
>
>

> But they do in Win2k (which is really NT5) :-)

Still not enough to induce me to use win2k, though :^)

Jan Eric


0 new messages