How can I see the disk usage with btrfs?

Thanks Linux-aarhus. I read you’re remark about btrfs.
Is there a proper way to determine the real size on disk for a btrfs subvol ?
They all have the same size on my system.

/dev/sda2            50G   14G       36G  28% /.snapshots
/dev/sda2            50G   14G       36G  28% /home
/dev/sda2            50G   14G       36G  28% /var/cache
/dev/sda2            50G   14G       36G  28% /var/log
/dev/sda3            49G    2G       47G   4% /storage
/dev/sda2            50G   14G       36G  28% /var/tmp

Please see Btrfs - Manjaro

1 Like

Because they are part of the same volume! They share space, as in “everyone lives in the same room.”
What you see is the size of the volume.

btrfs filesystem usage --help

Measuring size is not easy on btrfs because:

  • part of the files may be compressed
  • part of the files may be shared between 2 or more subvolumes
  • it gets worse if you have a lot of snapshots :wink:

What you can measure is the size of files in one of your mountpoints with du .
(But be carefull if you have nested layouts, or snapshots)

But there is btrfs fi du :

btrfs filesystem du --help             

and

 sudo btrfs filesystem du -s /home/andreas
     Total   Exclusive  Set shared  Filename
 151.88GiB    57.84MiB   142.11GiB  /home/andreas

This may be a time consuming task !!!

You can learn a lot about btrfs in the wiki, but you may have to read some things twice if you’ve never dealt with btrfs before

:footprints:

P.S.:

btrfs filesystem du

Here the full scope of btrfs’ difference becomes visible. When btrfs takes snapshots, many files are contained unchanged in several snapshots, but only take up space in the file system once. At the same time, there can be the same(!) file with different content and size in the different snapshots.

It is therefore not enough to simply add up the size of all files in a path to determine the space consumption in the file system.

For each file, it must be determined how large it is and whether all or part of it is shared with other subvolumes. Since btrfs has to read a lot of metadata for this, it can take a long time to display the results:

Total:

The sum of all files, as “du” would display them in a conventional file system

Exclusive:

The sum of the files that “only” occur in one of the subvolumes and are not shared with other subvolumes

Set shared:

The sum of files shared with other subvolumes

sudo btrfs filesystem du -s /home
     Total   Exclusive  Set shared  Filename
   8.11TiB     6.23GiB   215.76GiB  /home

Exclusive+shared

This is the actual space used in the file system

Total

This is how much space a conventional file system would use to store these files (and all the necessary copies).

:footprints:

P.S. this is now in the wiki:

4 Likes

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.