How to repair and Defragment partitions in ubuntu

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Generally there is a misconception among the linux community that it doesn’t need Defragmentation. Now in recent times most of the linux distributions use journalized File systems such as EXT2, EXT3, EXT4 ,JFS, ZFS,BTRFS etc. All of these file systems empowers the operating system with smart ways and techniques for file allocation. Hence as a result all of these minimize the fragmentation problems. Fragmentation though can still be an issue for those who use space limited disks that may not offer file allocation options. In this tutorial I will help you to defragment ubuntu partition , when a system reaches critical levels of fragmentation. Here I would help you to Defragment ubuntu partition.

The practical point to do defragmentation is to improve input-output operations such as

  • Allowing local videos to load faster
  • Extraction of archives with faster speed

The File system used in linux distribution such as EXT2, EXT3, EXT4 doesn’t give you much pain. As we know that EXT2, EXT3, EXT4 in ubuntu use various techniques to prevent fragmentation. But with time after many read/write operations its performance goes down. So if we want to improve the performance, we have to do a proper optimization. Otherwise on some day we will feel the performance of the hard disk is slower. As a result the performance of entire system would be affected. So here we will learn a few of various techniques to perform defragmentation in ubuntu. now with the help of some tools , we can perform defragmentation in ubuntu.

Checking if the File system requires Defragmentation or not?

Before performing a Defragmentation, let’s check if its needed or not? now we can do this easily with the help of e2fsck tool. Before that we have to umount the partition as well. Surprisingly I would not recommend an umount but to be on safe side we should do that.

Enter the following to check the available File sytem.

# df -hT
Defragment ubuntu partition

Next enter the following command to unmount. now here I had selected the partition /dev/sdb1

 # sudo unmount /dev/sdb1

Now use the e2fsck command to check fragmentation.

# sudo e2fsck -fn /dev/sdb1
Defragment ubuntu partition

Now if we get the output as shown above , then health of the partition is ok . We don’t need to do a Defragmentation. But if we get the output as shown below , we get to know that the health of the file system is in a critical phase. So here we need to perform a Defragmentation.

Repairing File system using e2fsck

If an error appears as shown above we can perform a Repair operation using the command as shown below

# sudo e2fsck -p /dev/sdb1
Defragment ubuntu partition

then answer with ‘Yes’ on each of the prompt. After that we will get the file system repaired as shown below.

Defragmenting ubuntu partitions

now we can Defragment the available partition using the below command.

# sudo e4defrag /dev/sdb1

Conclusion

In this tutorial I had taught you all the tips to repair and perform defragmentation of the partitions in ubuntu. I hope this article would help you to get a better understanding of repair and defragmentation of partitions in ubuntu. You can also look at some of my ubuntu articles as well.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

2 COMMENTS

    • indeed.

      Also a small comment: for system partitions (in this tutorial /dev/mapper/ubuntu–vg-root ) you better do it from a live cd/usb to be sure the partition is unmonted.
      @mel: ¿I don’t know if with lvm works the same?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook