Skip to content

Instantly share code, notes, and snippets.

@rmi1974
Last active July 6, 2024 03:18
Show Gist options
  • Save rmi1974/108c58cdeaa4c1f8b29a2af68f6ca698 to your computer and use it in GitHub Desktop.
Save rmi1974/108c58cdeaa4c1f8b29a2af68f6ca698 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