Skip to content

Instantly share code, notes, and snippets.

@rmi1974
Last active March 29, 2020 16:19
Show Gist options
  • Save rmi1974/36792e049e5a32ea9841d38b5bffd885 to your computer and use it in GitHub Desktop.
Save rmi1974/36792e049e5a32ea9841d38b5bffd885 to your computer and use it in GitHub Desktop.
How to optimize / defrag EXT4 filesystems #ext4 #performance #commandlinefu

How to optimize / defrag EXT4 filesystems

Courtesy of How to optimize / defrag EXT4 filesystems.

Open up the terminal and run:

sudo fsck.ext4 -y -f -v /dev/sd**

(Where ** put your drive location here and elsewhere, mine is sdb3).

To see that all is well with my system before I attempt any kind of defragmentation.

Optimize the directories

sudo fsck.ext4 -y -f -v -D /dev/sd**

Done. Note : Pass 3A: Optimizing directories.

It also (almost always) reports :

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

So don't panic, as long your previous 'fsck' went off without a hitch, you should be golden. I run the 'fsck' ( Without -D option) once more sometimes just to see how much it optimized.

Optimize files

MOUNT YOUR FILE SYSTEM NOW.

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

After mounting:

sudo e4defrag -v /dev/sd**

Now, unmount again with :

sudo umount /dev/sd** && cd /

Finally to check fragmentation stats:

sudo fsck.ext4 -y -f -v /dev/sd**

Links

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