Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Howto: Defrag your HDD

Share your HowTo, Documentation, Tips and Tricks. Not for support questions!.
Post Reply
Message
Author
User avatar
Hallvor
Global Moderator
Global Moderator
Posts: 2029
Joined: 2009-04-16 18:35
Location: Kristiansand, Norway
Has thanked: 139 times
Been thanked: 206 times

Howto: Defrag your HDD

#1 Post by Hallvor »

What is defragmentation?
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 /
I have already done a defrag, and obviously I don't have to do it again:

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:~$ 
As you can see, the program will advise you to do a defrag once the fragmentation level gets too high.

If you want to defrag your HDD, just run the following command (as root), or choose a different location:

Code: Select all

# e4defrag /
Sources:
https://www.howtogeek.com/115229/htg-ex ... agmenting/
https://en.wikipedia.org/wiki/Defragmentation
[HowTo] Install and configure Debian bookworm
Debian 12 | KDE Plasma | ThinkPad T440s | 4 × Intel® Core™ i7-4600U CPU @ 2.10GHz | 12 GiB RAM | Mesa Intel® HD Graphics 4400 | 1 TB SSD

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

Re: Howto: Defrag your HDD

#2 Post by debiman »

thanks!

http://hultbergs.org/defrag/
(couldn't resist)
(javascript required)

User avatar
stevepusser
Posts: 12930
Joined: 2009-10-06 05:53
Has thanked: 41 times
Been thanked: 71 times

Re: Howto: Defrag your HDD

#3 Post by stevepusser »

It could be worth noting that defragging a solid state drive serves no real purpose.
MX Linux packager and developer

Post Reply