Page 1 of 1

Hey, I defragmented my first Linux system today!

Posted: 17 Feb 2015, 13:14
by viking60
Linux does not need defragmentation - at least it has not so far. With the btrfs filesystem we do get the option to defragment though.

I am not sure if this is because data get more fragmented with btrfs or if the small fragmentations that do occur can be eliminated.

So I decided to defrag OpenSuse that comes with Btrfs.

Code: Select all

sudo btrfs filesystem defragment -v -r /

I chose the entire enchilada with / at the end. It checked out the lot and came up with this message at the bottom

Code: Select all

Btrfs v3.16.2+20141003
total 80 failures


Yeah ... right eh is that good or bad?

I decided to only defrag my home like this

Code: Select all

sudo btrfs filesystem defragment -v -r /home/viking

and that came up with a clean

Code: Select all

Btrfs v3.16.2+20141003
so no errors there and it was blistering fast.
The btrfs command allows to control important portions of your system.

I wish I could find a log somewhere regarding those 80 defrag failures though :confused

Checking /usr reveals that most of the errors are there:

Code: Select all

sudo btrfs filesystem defragment -v -r /usr

There were 75 errors.
Checking /usr/bin came up with 18 failures but this cannot be the way to do it - there must be a log somewhere that provides an overview of the defragment failures. :think:

My proceedings above will only defragment files; the excellent Arch wiki told me that I could do this to directory metadata with:

Code: Select all

 sudo find / -xdev -type d -print -exec btrfs filesystem defragment '{}' \;

It works and comes up with no errors.

In any case I feel good because I have defragmented my first Linux system :smug

(Edit: It does seem to be the case Btrfs can fragment more than Ext4 so hence the defrag possibilities)