Categories
Linux

cleanup Btrfs volumes

Sometimes your Btrfs disk can reported to be full or nearly full but you haven’t that amount of data saved on that volume.

To solve this you have to rebalance parts of your Btrfs volume. This is something like defragmentation. I had different parts, which needed rebalanced.

You can show currently used space with (/ is here mount path of your Btrfs volume):

btrfs filesystem df /

You will get something similar to this output:

Data, single: total=437.00GiB, used=388.76GiB<br>System, single: total=4.00MiB, used=64.00KiB<br>Metadata, single: total=6.01GiB, used=4.17GiB<br>GlobalReserve, single: total=512.00MiB, used=0.00B

The difference between total and used can be freed. For metadata you have to call:

btrfs balance start -m /

And for Data you have to call:

btrfs balance start -dusage=90 -v /

The option -dusage=90 filters all data blocks which are maximum filled by 90 %. Pay attention that a full rebalance could took some time and uses many IO resources, because everything would be rewritten. So you should start with lower values and rerun with large values if there was not freed enough space.

You can also combine -m and -dusage=90 into one task.

A long running rebalancing can be monitored with:

btrfs balance status /