Resize btrfs filesystem to the minimum size in a single step
The best solution I've come across so far is to get the minimum free space (using -b
for bytes):
sudo btrfs filesystem usage -b /mountpoint
Free (estimated): 71890542592 (min: 71890542592)
And then resize by the negative of the min
amount:
sudo btrfs filesystem resize -71890542592 /mountpoint
Alternatively, if there is a big difference between the min free and the unallocated, you may choose to use (unallocated * 0.9) since resizing by the exact unallocated bytes seems to fail.
You can then repeatedly shrink by small amounts until the resize fails:
while sudo btrfs filesystem resize -200M /mountpoint; do true; done
This is not exactly a single step, but at least mostly automated. The loop by itself could be a single step, but it will probably take longer doing small incremental resizes rather than initially shrinking by a large chunk.