BTRFS defrag

Hello Kevin,

I was looking at the Kaisen documentation regarding BTRFS and I am wondering why it states that there is a need to delete the snapshots before defragmentation.

It seems to make more sense to keep the snapshots in case something goes wrong with the defragmentation!?

Is it not possible to defragment a BTRFS system without deleting the snapshots first?

Thanks for any information you may be able to give about this.


Hello @MidGe ,

Nice question !

Even if btrfs main advantage are snapshots of subvolumes on a fly, it is not possible to defragment btrfs subvolume without deleting snapshots.

Defragmentation will cause existing reflinks to break for the target subvolume.

Take a look at this forum discussion :

But why would you defragment your subvolumes ? Where is no benefits to do it on a modern file systems, even on HDDs.

Thanks for that answer, niki.

I will not defrag then and will completely re-install an O/S from scratch on another drive every year or so. :slight_smile:

You are welcome !

As for the reinstallation, you don’t need to do it. Just consider using good practicies when using apt :

  • When removing an app, do the following to delete user configs and app dependencies :
sudo apt autoremove --purge app_name
  • To update your system, please use the following command :
sudo kaisen-update

If you are following these simple steps, you shouldn’t reinstall your system every year.

Have a good night