In the maintenance of file systems, defragmentation is a process that reduces the amount of fragmentation. It does this by physically organizing the contents of the mass storage device used to store files into the smallest number of contiguous regions (fragments).
Does GNU/Linux need defragmentation?
Linux’s ext2, ext3, and ext4 file systems – ext4 being the file system used by Debian and most other current Linux distributions – allocates files in a more intelligent way than NTFS on Windows. Instead of placing multiple files near each other on the hard disk, Linux file systems scatter different files all over the disk, leaving a large amount of free space between them. When a file is edited and needs to grow, there’s usually plenty of free space for the file to grow into. If fragmentation does occur, the file system will attempt to move the files around to reduce fragmentation in normal use, without the need for a defragmentation utility.
Because of the way this approach works, you will start to see fragmentation if your file system fills up. If it’s 95% (or even 80%) full, you’ll start to see some fragmentation. However, the file system is designed to avoid fragmentation in normal use.
How can I see if my file system is fragmented?
As root, run the following command to check the root partition:
Code: Select all
# e4defrag -c /
Code: Select all
hallvor@debian-hp:~$ su
Passord:
root@debian-hp:/home/hallvor# e4defrag -c /
<Fragmented files> now/best size/ext
1. /home/hallvor/.cache/chromium/Default/Cache/1513aefa62ebb471_0
2/1 4 KB
2. /home/hallvor/.cache/chromium/Default/Cache/7c4455bf7efed853_0
2/1 4 KB
3. /home/hallvor/.cache/chromium/Default/Cache/f7d205a293a15136_0
2/1 4 KB
4. /home/hallvor/.cache/chromium/Default/Cache/b6a709b230c92d44_0
2/1 4 KB
5. /home/hallvor/.cache/chromium/Default/Cache/3f0dbf6972000ce1_0
2/1 4 KB
Total/best extents 147279/145521
Average size per extent 1476 KB
Fragmentation score 0
[0-30 no problem: 31-55 a little bit fragmented: 56- needs defrag]
This directory (/) does not need defragmentation.
Done.
root@debian-hp:/home/hallvor# exit
exit
hallvor@debian-hp:~$
If you want to defrag your HDD, just run the following command (as root), or choose a different location:
Code: Select all
# e4defrag /
https://www.howtogeek.com/115229/htg-ex ... agmenting/
https://en.wikipedia.org/wiki/Defragmentation