PDA

View Full Version : Defrag for linux?? Oh Yeah!



Seyyapc
05-18-2006, 08:05 AM
Like some nights when I can read info I stuck on these info on another linux-forum :oops: . Comparing the Linux Fragmentation Vs Windows fragmentation you'll note that it's almost nothing 8) but the fragmentation exists, lower but is there!

This perl script will show you the fragmentation in the directory you choose (you must use the script as root)

#!/usr/bin/perl -w

#this script search for frag on a fs
use strict;

#number of files
my $files = 0;
#number of fragment
my $fragments = 0;
#number of fragmented files
my $fragfiles = 0;

#search fs for all file
open (FILES, "find " . $ARGV[0] . " -xdev -type f -print0 |");

$/ = "\0";

while (defined (my $file = <FILES>)) {
open (FRAG, "-|", "filefrag", $file);
my $res = <FRAG>;
if ($res =~ m/.*:\s+(\d+) extents? found/) {
my $fragment = $1;
$fragments += $fragment;
if ($fragment > 1) {
$fragfiles++;
}
$files++;
} else {
print ("$res : not understand for $file.\n");
}
close (FRAG);
}
close (FILES);

print ( $fragfiles / $files * 100 . "% non contiguous files, " . $fragments / $files . " average fragments.\n");
For testing I used it on my home dir
root@rommiebox:~# ./fragm.pl /home/seyya
12.2209165687427% non contiguous files, 27.9980415197806 average fragments.
So imagine my surprise :shock: and WTF!! :evil: is happening here!! when I see the results. OK I didn't precisely take big care of my file system (reseirfs default) with bittorrents files, managing different images from posters desing to make-ups on photos with my digital camera, huge mp3 collection and fan of radios streammers...then what can i do to defrag my home dir?

Kolivas make a defrag script (http://ck.kolivas.org/apps/defrag/) that is the anwer :lol:

Before defrag script: 12.2209165687427% non contiguous files, 27.9980415197806 average fragments
After defrag script: 2.31055414137458% non contiguous files, 1.18778147640493 average fragmentsPlease read the README carefully. Note if you use lilo as your loader and you defrag the partition containing your kernel you will need to rerun lilo before rebooting!

Honestly I don't notice any difference and if not for the script I wouldn't have know my fragment situation, I take this tip like 'It changes nothing except you know that theorically it works better now"

More information HERE (http://forums.gentoo.org/viewtopic-t-429915-highlight-fragmentation+reiserfs.html)
The script it's not mine, I put the information here for knoppix user who has a hd-install