Skip to content

Instantly share code, notes, and snippets.

@524c
Forked from rmi1974/defrag_ext4_filesystem.md
Created February 4, 2022 03:03
Show Gist options
  • Save 524c/bfb3af757ace207c7ced9dd91775f8ac to your computer and use it in GitHub Desktop.
Save 524c/bfb3af757ace207c7ced9dd91775f8ac to your computer and use it in GitHub Desktop.
How to optimize / defrag ext4 filesystem #ext4 #commandlinefu

How to optimize / defrag ext4 filesystem

Make sure the target filesystem is sane

Open up the terminal and run:

sudo fsck.ext4 -y -f -v /dev/<disk/partition>

Optimize the directories

sudo fsck.ext4 -y -f -v -D /dev/<disk/partition>

Done. Note : Pass 3A: Optimizing directories.

It also (almost always) reports :

****** FILE SYSTEM WAS MODIFIED *****

Don't panic, as long the previous 'fsck' went off without a hitch, all should be golden. Run the 'fsck' (Without '-D' option) once more sometimes just to see how much it optimized.

Optimize files

Mount your filesystem now.

(Right-click on your disk on the desktop or wherever and 'mount')

After mounting:

sudo e4defrag -v /dev/<disk/partition>

Now, unmount again with :

sudo umount /dev/<disk/partition> && cd /

Finally to check fragmentation stats:

sudo fsck.ext4 -y -f -v /dev/<disk/partition>

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment