Page 1 of 1

To defragment mechanical hard disk

Posted: Fri Oct 18, 2024 5:37 am
by Domenico
Good morning,
on my PC with MX Linux I have a mechanical hard disk. What should I do to defragment it?
Thanks.

Re: To defragment mechanical hard disk

Posted: Fri Oct 18, 2024 5:54 am
by Eadwine Rose
Nothing. It is not windows, defragmenting is not needed.

"File systems used by Linux don't generally need defragging because they're better designed than NTFS. They don't 'defrag in the background', they just do a better job of allocating files into available space.

You can defrag ext4 with the e4defrag command. Use -c to check for fragmentation. You'll generally be wasting your time." (found on Reddit)

Re: To defragment mechanical hard disk

Posted: Fri Oct 18, 2024 6:15 am
by chrispop99
Just to add to the advice from @Eadwine Rose, Windows doesn't need manual defragmentation these days; it does it automatically.

Chris

Re: To defragment mechanical hard disk

Posted: Fri Oct 18, 2024 7:09 am
by Stuart_M
FAT and FAT32 write files right next to each other so there is no room left for file growth. NTFS leaves a little more room between files and that allows room for growth so, because space is limited, fragmentation will occur over time.

Defragmentation in Linux should not be a problem under normal conditions. Problems can occur when the disk/partition is almost full and there will be a contiguous area large enough to allocate a file. Linux journaling filesystems place each file scattered all over the disk leaving a generous amount of space between files. This leaves enough room for file updates which is why fragmentation rarely occurs with ext4. If fragmentation does happen, most Linux filesystems will attempt to shuffle files and chunks around to make them contiguous again.

To see if fragmentation is a problem in Linux using ext4, run the command in the below code window. Ensure "sudo" is used to see the "score" information. If the score is 0-30 then you do not need to defrag. 31-55 means that it is a bit fragmented, and if >=56 then you should defragment the location. See the man page for e4defrag for more information.

Remove the -c option if you want to defragment the location, which is given as root (/) in the below command:

Code: Select all

sudo e4defrag -c /

Re: To defragment mechanical hard disk

Posted: Fri Oct 18, 2024 8:31 am
by Domenico
Thank you all

Re: To defragment mechanical hard disk

Posted: Fri Oct 18, 2024 8:36 am
by Kermit the Frog
One more thing: If it's ntfs you can even use an ext4 partition to defrag it, rather than any software in Windows etc. Just copy or move data to ext4, then copy or move back to ntfs :)