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.
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.
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