Defragment ext4

diskDoes the ext4 filesystem need defragmentation? The answer, in short, is yes. The ext4 filesystem is robust and gets fragmented in a few scenarios (like pidgin chat logs or browser cache) or on prolonged usage (but much less than FAT or NTFS). ext4 comes with its own defrag tool – e4defrag which is present in some distros including Ubuntu.

  • To check for fragmentation:
    sudo e4defrag -c /
  • To defragment:
    sudo e4defrag /

Tune ext4 performance

ext4

Power tips to get the best performance on ext4 volumes.

Some of the options available for tuning the ext4 filesystem are very powerful and can even corrupt your filesystem if used incorrectly. Handle with care!!! For example, do not use data=writeback for root partitions with ext4. My system didn’t boot on Ubuntu 12.04. Keep a USB installed distro like SliTaz handy for these kind of issues.

To turn off journaling completely:

$ sudo tune2fs -O ^has_journal /dev/sdXn

To enable faster large directories:

$ sudo tune2fs -O dir_index /dev/sdXn

To reduce percentage of reserved blocks:

$ sudo tune2fs -m .1 /dev/sdXn //to reserve .1% blocks

For the record, my fstab entry for the NTFS partition I have is:

UUID=658822A60A30C96C /mnt/NTFS ntfs noauto,noatime,
nodiratime,noacl,noinherit,uid=1000,nouser_xattr 0 2

References: