0

Does Linux Need to Be Defragged?

Posted by Arch on December 10, 2019
does linux need to be defragged

There appears to be a lot of confusion when it comes to defragmentation and Linux operating systems. Myths wrongly persist that Linux does not require defragmentation at all, but the truth is that the operating system does, in fact, need it.

In this article, we’ll try to clear your doubts about defragging a Linux system and show you the best way to go about doing it.

What Is Defragging?

When we save files onto a hard disk, there’s every chance that the bits of larger files will get saved across different sectors of the hard drive. This occurrence is called fragmentation, and it is especially common in FAT and FAT32 file systems.

Fragmentation can also happen when we update a particular file. Since updating a file usually means increasing its size, the system will try to store the new chunks of information next to the original file. But in case there’s no room next to where the file is saved, the new pieces of data will be saved somewhere else.

When we try to access these files, the system will have to move around different physical locations on the drive to collect all the bits to open the file in question. Naturally, this will slow things down. Therefore, we use defragmentation to prevent these delays. Defragmentation bundles the scattered pieces of data together to improve loading and opening times.

What About Linux?

There is no doubt that Windows users are much more accustomed to defragmentation than Linux users. That’s because of the success of the journalized file systems used by Linux, including EXT2, 3, and 4, BTRFS, among others. Unlike the FAT, FAT32, and NTFS systems, the Linux file systems allow the data to be stored across multiple locations on the disk.

The following image shows how the data is stored on the FAT and FAT32 systems.

linux defragged

Here is an example of how Linux file systems store data.

defragged

So, when you save files for the first time, Linux will make sure to leave substantial unwritten spaces between them. When you update the files later, these spaces will store the new bits of information. This process ensures that the files never get scattered across the disk.

Even in cases when the unwritten space on a hard drive is insufficient for an updated file, Linux file systems will try to completely re-write the file in another sector. Once again, this ensures that when you try to access these files, they aren’t fragmented.

No Worries About Fragmentation with Linux?

We didn’t say that. Although Linux file systems don’t need defragmentation as much or as often as their Windows counterparts, there’s still a possibility that fragmentation may occur. It could happen if the hard drive is too small for the file system to leave enough space between the files. Multiple read/write executions could also leave the operating system in need of optimization.

Even though you’ll have to do it rarely on your Linux computer, it is good to know how the defragmentation process works. Here are nuts and bolts of defragmentation on Linux.

How to Check If Your Linux System Needs Defragmentation?

To check if your Linux system needs to be defragged, you’ll need to install a defragment tool. There are quite a few tools available for Linux systems, but we recommend that you use “e4defrag” as it might already be installed on your system.

Open the terminal and type this: sudo e4defrag -c /location or /dev/device

You can scan a particular folder to find its fragmentation score. The rule of thumb is that if this process outputs a score larger than 30, it’d be a good idea for you to defrag your system.

The Simplest Way to Defrag Your Linux Hard Drive

The simplest and best way to defrag your Linux computer is to copy all your hard disk data to another hard drive. Once you’ve done that, delete the files on your original hard drive and format it. Now, when you copy the files back, Linux file systems will make sure to group the data intelligently.

Defragged and Ready to Go

To sum it up, Linux operating systems hardly ever need to be defragged because of their excellent journaling techniques. However, if you do feel the need to defrag your hard drive, follow the method mentioned above.

It’s important to note that only HDDs need defragging. Most people are using SSDs nowadays. In case you’re using the latter, you don’t have to worry about defragging at all. That’s because SSDs can access the data stored on them randomly, unlike HDDs, which can only access data sequentially.

If you decide to defrag your Linux hard drive, create a backup before formatting your disk. There are more technical methods available too, but we wouldn’t recommend them. They could damage your data if not done with precision.

If there’s any other trick you use to avoid fragmentation, whether or Linux or Windows systems, please let us know in the comments section below. We’d be more than happy to hear from our community!

Leave a Reply

Your email address will not be published. Required fields are marked *


Disclaimer: Some pages on this site may include an affiliate link. This does not effect our editorial in any way.