25

I know Windows file systems are very sensitive to fragmentation and Unix such as UFS, ZFS, ext3, or ext4 are not as sensitive.

But, is there any reason to defragment these filesystems at all?

If so, what tools are available for that ?

Good Person
  • 359
  • 6
  • 18
paulgreg
  • 4,094
  • 6
  • 31
  • 32
  • Most mornern file systems in general do not need to be manually defragmented. This includes ext3, NTFS, UFS and others. – Chris S Feb 22 '10 at 21:23
  • 3
    Chris, I can't comment on others but NTFS most certainly does benefit from defrag. It greatly reduces the head thrashing caused by fragmentation and improves response times as a result. – John Gardeniers Feb 22 '10 at 22:41
  • @JohnGardeniers Every FS that support fragmentation will benefit from being defragmented. But, it's not necessary and the performance degradation due to fragmentation is limited compared to older file systems. – Chris S Nov 13 '11 at 19:37

7 Answers7

15

Quoting Wikipedia's page about the Ext3 Filesystem

Modern Linux filesystem(s) keep fragmentation at a minimum by keeping all blocks in a file close together, even if they can't be stored in consecutive sectors. Some filesystems, like ext3, effectively allocate the free block that is nearest to other blocks in a file. Therefore it is not necessary to worry about fragmentation in a Linux system

Alnitak
  • 20,901
  • 3
  • 48
  • 81
10

Actually, NTFS is not that sensitive to fragmentation. NTFS is significantly better than FAT32 -- in every way -- and is a fully modern filesystem.

I've been running Linux at home since 1996 and have never defragmented any filesystem. I have never had the need. The most I have done in this direction was pay attention to the kind of files I will be putting on a filesystem and using appropriate options when I mkfs. For example, if a filesystem will primarily contain large files, I'll use a larger block size. If I am making a huge file system but I know it will never have more than 1,000,000 files, then I'll use the -N 1000000 option to limit the number of inodes. In general, I'll tune the filesystem at creation to its task if a particular kind of file will inhabit it.

Eddie
  • 11,332
  • 8
  • 36
  • 48
7

You don't need to defrag no. But if you still want to do it, you can always use shake.

Gert M
  • 1,471
  • 1
  • 15
  • 14
4

While ext2 and ext3 do not provide for it (and generally need it less as they keep files relatively together in the first place) ext4 does provide for defrag. This article talks about the e4defrag program. But ext4 is a new filesystem.

However, compared to windows linux file systems are much better at not fragmenting, so I wouldn't worry about it.

Hamish Downer
  • 9,142
  • 6
  • 36
  • 49
  • 1
    ext2 and ext3 *can* be defragmented. They just don't need it in normal circumstances. – Eddie Apr 30 '09 at 15:35
  • bear in mind Windows FS never needed to be defragged either - NT3.51 used to allocate space either side of blocks just like ext3 does, but then MS scrapped that in NT4 for some reason. – gbjbaanb Aug 04 '09 at 15:24
2

You can defrag XFS file system (using xfs_fsr [dev|file]) and btrfs (using btrfs filesystem defragment [file]

As for all others, just make sure you have at least 80% free or few dozen gigabytes (whichever is smaller) and you shouldn't worry about defragmentation.

Hubert Kario
  • 6,351
  • 6
  • 33
  • 65
2

http://en.wikipedia.org/wiki/Ext3#Defragmentation, but I wouldn't bother

Dave Cheney
  • 18,307
  • 7
  • 48
  • 56
1

The only good reason for defragging linux filesystem is to shrink virtual hard disks that have bloated.

Zero fill unused space, defrag and then compact the virtual disk from the VM manager.

Fiasco Labs
  • 563
  • 4
  • 10