btrfs, linux, OYB software, shell

Check disk space of your BTRFS snapshots with btrfs-du

Today I want to share a simple way to check the state of our BTRFS snapshots.


If path is omitted, it will default to / .

We can list easily our snapshots, plus have a clear view of how much data they have in common and how much total overhead are we holding.

Four months worth of snapshots for only 7.48GB!!


Get the script and make it executable. You can do this in two lines, but better inspect it first. Don’t trust anyone blindly.


Normally you can only get disk usage information through the quota info in qgroups


This is not ideal for a couple reasons:

  • First, we need to have quota enabled, which can have a performance impact with many subvolumes.
  • Second, we still have to list our subvolumes to correlate subvolume IDs to subvolume names. Two steps for a simple operation.

I was inspired by btrfs-size by Kyle Agronick, but not only the output wasn’t very clean to my taste, but also it was terribly slow on my root subvolume where docker uses BTRFS as storage driver and I have very many subvolumes. I am talking close to a minute.

Looking into the code to speed it up I decided that it would be cleaner to rewrite it as it was more complex that it needed to be. Also, quotas don’t need to be enabled for btrfs-du to work.

Keep in mind that if quotas are not enabled for the subvolume, the command can take several seconds to calculate the sizes. We can speed the execution by having quotas pre-enabled, but as mentioned before note that this can have an impact in a big subvolume with many snapshots.


Author: nachoparker

Humbly sharing things that I find useful [ github dockerhub ]

7 Comments on “Check disk space of your BTRFS snapshots with btrfs-du

  1. I get an error /home/miguel/bin/btrfs-du: line 88: EXCL_TOTAL + : syntax error: operand expected (error token is “+ “)

    1. yes. Quotas need to be enabled for the calculation. If they were enabled, then it will be fast but if not, they will be enabled and then btrfs-du will wait until the scan is finished, report disk usage and finally disable them again. This can take a couple minutes.

      you can make this faster by leaving quota enabled, as the article explains

  2. I was misguided by reading the article, the line :
    “Also, quotas don’t need to be enabled for btrfs-du to work.”
    Somehow implies that btrfs-du works without quota but on my debian install it would not start if quota are not enabled and just say “old btrfs-tools detected, need to enable quota and wait for rescan to display accurate results”

    With quota enabled it does work but then how is it better than using the classic method, as you say that a caveat is that it is using quota…

    Or maybe I got things wrong, let me know 😉

Leave a Reply

Your email address will not be published. Required fields are marked *