In this article we will discuss about how to Defrag Linux System. People have a lot of wrong ideas about how file systems and operating systems work. Most people think that only Windows hard drives that use the NTFS file system can get fragmented.
This is not true. Microsoft’s idea of “fragmentation” isn’t a bad one. In fact, file fragmentation can happen on almost any file system, unless it was made to NOT fragment files (which is pretty rare). Even Linux users need to defragment their hard drives from time to time.
Unfortunately, many popular websites on the Internet keep spreading the idea that “Linux is immune.” This is only half true. Linux file systems do get file system fragmentation, but it happens less often than with Microsoft’s NTFS. This doesn’t mean that Linux file systems are immune.
How to Defrag Linux System
Some small businesses save money by running Linux, which is a free and open-source operating system, on their servers and workstations. This is because money is tight right now.
Linux can do almost everything that Windows and Mac computers can, like defragmenting NTFS (New Technology File System) drives. NTFS is a format that is only available on Windows, but with the right flags, you can defragment NTFS drives from within Linux.
- Log in to your Linux system.
- Open a terminal window if you are using a Graphical User Interface (GUI) Linux flavor such as Ubuntu.
- Type “sudo su” (without the quotes) at the prompt. Enter your password when prompted. This will give you superuser privileges so you can run the defragmenting process.
- Identify your NTFS drive by running the “df -T” command at the prompt. Look for the line with the NTFS label. For example, an NTFS external drive might be identified as “/mnt/sda2 NTFS“.
- Type “fsck -t ntfs mnt/sda2” (without the quotes) and substitute the drive identifier as the last parameter.
- Allow the defrag time to run. The larger drive you have, the longer it will take.
What Fragmentation Is
Even people who have never used Windows before think that defragmenting their file systems will make their computers run faster. Not many people know why this is the case. In short, a hard disk drive has a number of areas called sectors. Each sector can hold a small amount of data. Files, especially big ones, need to be spread out over a number of sectors.
Let’s say that you save several files to your file system. Each of these files will be stored in a group of sectors that are all next to each other. Later, you make changes to one of the files you saved, which makes the file bigger. The file system will try to put the new parts of the file right next to the old parts.
If there isn’t enough space for the file to be saved in one piece, it has to be broken up into multiple pieces. You don’t see any of this happening. When your hard drive reads the file, its heads have to move to different parts of the hard drive to read each chunk of sectors. This slows things down.