Comments on How to defrag your Linux system

There is a common misconception among GNU/Linux users that our systems never ever need to be defragmented. This stems from the success of the journalized filesystems used by most distributions including EXT2,3 and 4, JFS, ZFS, XFS, ReiserFS and BTRFS. Fragmentation though can still be an issue though, especially for users that use space limited disks that may not offer many file allocation options.

21 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Curtis

If you are a btrfs user, you can use the btrfs command to defragment.  This works on a directory level and has to be told to defrag recursively.  So if you wanted to defrag the whole system, you would do something like:

     #  btrfs filesystem defragment -r /

By: Van

Thank you for this and nice wallpaper.

By: Davide Repetto

Actually "sudo e4defrag /dev/*" will not work. Partitions need to be mounted for e4defrag to do its work.

By: Scott

I just ran this on my /home partition, which was created more than three years ago when I first got this computer.  I have re-installed or upgraded the OS in a separate partition many times since.  Out of tens of thousands of files only five are fragmented.  I have never heard credible stories from any source claiming that their Linux partitions were in need of defragmenting, and this check of my /home partition just adds credibility to the claim that Linux filesystems do not need defragmenting.  It's nice that there are tools available should that ever become necessary, though.  I can understand this need if someone is dedicating their computer to something like a database and after many thousands of transactions it becomes somehow fragmented and degrades performance.  But this demonstration flies in the face of your opening claim that it is a misconception on the part of Linux users that their systems do not need to be defragmented.  In the days of MS-DOS it was common to dedicate an evening to defragmenting the FAT filesystem.  It would take hours on "large" (60+ MB) partitions to defragment them.  If only they would just stay defragmented.  The Norton Utilities were a best-seller in large part because they included a defragmenting program.  But for Linux, I see this utility as an effort in completeness rather than necessity.

By: Bill_Toulas

There are use cases such as "extensive use of bittorrent tools" that may result in a lot of fragmented files. In most common scenarios though, yes there is no reason to defrag. That's what I wrote in the very first paragraph: "minimizing the fragmentation problem to a point that there is practically no reason to defrag even after many years of installing and uninstalling applications and libraries in the same system" which is exactly what you describe as well. :)

By: Gene

Totally off topic. What DE are you running? Is that Gnome Shell? On top of Fedora? Looks much better than the last time I checked it out...

By: Bill_Toulas

The DE is a GNOME-Shell fork called Panthen developed by Elementary OS developers. 

By: present_arns

Nope that looks like ElementaryOS :)

By: tehnikpc

Not relevant, because all servers have long been SSD.

By: till

Most servers still use normal hard disks, especially when you have to store large amounts of data.

By: Bryan

It should point out that defragging an SD card is important if you know the contents are less than, say, 4G and you want to copy that content to a 4G device.  For example, I have an 8G sdcard.  I know this card contains less than 4G of data.  I want to move these contents to a 4G flash part using 'dd'.   DD will fail, obviously, but at least it'll copy the contents over (only to require a little fsck fix up later, no biggy).  But, if the 8G part is not defragged data could exist at the 4G+ space and will never get copied over.

By: david

This is horrible advice, please nobody think that using dd from a larger device to a smaller one is ever a good idea.

If you really want to do it, first shrink the partition to match the smaller device, then dd just the partition, not the entire device.

By: don

It would have sure been nice if fonts in the picture of your screen had been large enough to have been readable!

By: Scott

It is a common misconception, but Pantheon is not a fork of Gnome Shell.  "...notable difference between GNOME Shell and Pantheon is choice of programming language. Pantheon is written in Vala, while GNOME Shell is written in javascript (Specifically, GJS). Just to reiterate, these are totally separate unrelated code bases and are not derived from each other at all. We’re committed to using a single language across our entire desktop and apps. This allows us to share code, enforce a consistent code style, and ensure developers writing their own apps can learn from and adapt our code to new purposes."   https://medium.com/elementaryos/busting-major-myths-around-elementary-os-bd966402a9c2

By: Inukaze

In the tittle you should pur "How to defrag your ext4 Linux partition" because, under GNU/Linux the users can select between diferents file systems like : btrfs , ext2/3/4, zfs, xfs, reiserfs, reiser4, jfs, etc . . .

 

And defrag for each filesystem is diferent

By: Bill

Thanks!

By: r.l.

Thanks for the very good job!

 

By: raoul

Thanx Bill, the linux mint system has slowed down over 1,5 years and i was looking for a method of defragging which is a step in the right direction.

i used to be a unix man - sco. most stable operating system in the world.

cool - raoul

By: Joe Zeff

Using defrag on an ext* partition is never a good idea.  Not only that, using the command "sudo e4defrag dev/*" is only going to cause trouble as it tries to defrag your keyboard, your modem, your monitor...

By: Barnaby Jonez

Thank you.  This is great!  Mu home/ partition that is nearly full and it was heavily fragmented.  The defrag took awhile and it made things faster.  And the I did a few more passes and it degraged more.  The content on that partion is moving much smoother now!

By: Herbert Bura

I used e4defrag and get at the end the explanation: success: 3322952 / 5352837 and failure: 2029885 / 5352837

What does this message mean?