Defrag

Question: In all my user manuals & help files, I can't find any reference in how to run defrag in Linux. Is this because Linux files don't get fragmented like Windows files - or what? Sorry if this is a dumb question.

Everything Linux 1798 This topic was started by ,


data/avatar/default/avatar14.webp

25 Posts
Location -
Joined 2005-03-03
Question: In all my user manuals & help files, I can't find any reference in how to run defrag in Linux. Is this because Linux files don't get fragmented like Windows files - or what? Sorry if this is a dumb question.

Participate on our website and join the conversation

You have already an account on our website? Use the link below to login.
Login
Create a new user account. Registration is free and takes only a few seconds.
Register
This topic is archived. New comments cannot be posted and votes cannot be cast.

Responses to this topic


data/avatar/default/avatar05.webp

500 Posts
Location -
Joined 2004-04-06
From NewsForge:
 
QUOTE
Defragmenting a disk
 
Microsoft filesystems, such as the File Allocation Table (FAT) filesystem and the New Technology File System (NTFS), suffer greatly from disk fragmentation -- the tendency of files to be broken up into many noncontiguous segments. Disk fragmentation degrades performance because the OS may need to move the disk head more frequently and over greater distances to read a fragmented file than to read a nonfragmented file.
 
Fortunately, Linux's native filesystems are all far more resistant to fragmentation than are Windows filesystems. Therefore, most Linux users don't bother defragmenting their disks. In fact, defragmentation tools for Linux are hard to come by. One that does exist is called defrag, but this package doesn't ship with most distributions. Because it is an older tool, it won't work with most modern ext2fs partitions, much less any of the journaling filesystems.
 
If you think your system may be suffering from fragmentation problems, you can at least discover how fragmented your ext2 or ext3 filesystems are by performing an fsck on them. You may need to force a check by using the -f parameter. This action will produce, among other things, a report on the fragmentation on the disk:
 
/dev/hda5: 45/8032 files (2.2% non-contiguous), 4170/32098 blocks
 
This report indicates that 2.2 percent of the files are noncontiguous (that is, fragmented). Such a small amount of fragmentation isn't a problem. Unfortunately, the fsck tools for other journaling filesystems don't return this information, so you have no indicator of fragmentation on these filesystems. If you truly believe that fragmentation has become a problem, you may be able to improve matters by backing up the partition, creating a fresh filesystem, and then restoring the files. This procedure is likely to take far longer than the time saved in disk accesses over the next several months or years, though, so I only recommend doing it if you want to change filesystem types or have some other reason (such as replacing a hard disk) to engage in this activity.
 
As a general rule, fragmentation becomes a problem only if your disk is almost full. On a nearly full disk, Linux may have trouble locating a large enough block of free space to fit a file without fragmenting it. If you almost fill a disk and then delete files, the remaining files may or may not be fragmented, depending on which ones you deleted. For this reason, keeping your partitions from filling up is best. As a general rule, anything less than 80 to 90 percent full is fine from a fragmentation perspective.
 
 
Since Linux treats everything like a file, the fragmentation that does take place is within that file, not all over the hard drive.

data/avatar/default/avatar14.webp

25 Posts
Location -
Joined 2005-03-03
OP
Thanks for that clarification. I have no reason to think my Linux partition is fragmented, just that I like preventive maintenance. One more reason to jump out of the Windows into Linux.

data/avatar/default/avatar05.webp

500 Posts
Location -
Joined 2004-04-06
All partitions will become fragmented after a certain period of usage. Windows ones much faster. I have never heard of anyone who has had to defrag his/her GNU/Linux partitions.