The root filesystem of my Kubuntu (mounted under
/) is Btrfs. I don't use
-o discard as a mount option. This means I need to run
fstrim on demand.
In the past I hit this problem: btrfs, no diskspace left. I noticed
fstrim -v / showed almost no space being trimmed. My solution was to run
btrfs balance start / before
fstrim. This is the gist of my answer there.
Today it's different. Maybe I'm too late with the maintenance. This is what happens:
# fstrim -v / /: 24 KiB (24576 bytes) trimmed # btrfs balance start / ERROR: error during balancing '/': No space left on device
I deleted few subvolumes (snapshots) with
btrfs subvolume delete … and it didn't help. I cannot remember details very well but I think previously I could run
btrfs balance … because preliminary
fstrim trimmed at least few MiB, not as little as 24 KiB like today. Now it seems like a catch-22 situation where
btrfs balance would only work if the other did its job first.
For the record, these are some stats that show I have in fact plenty of space:
# df -h / Filesystem Size Used Avail Use% Mounted on /dev/sda1 112G 43G 68G 39% / # btrfs fi df / Data, single: total=108.73GiB, used=41.00GiB System, single: total=64.00MiB, used=16.00KiB Metadata, single: total=3.00GiB, used=1.02GiB GlobalReserve, single: total=352.00MiB, used=0.00B
Note I haven't got "no space left on device" during normal operation yet. I think Btrfs keeps fitting new writes inside already taken chunks. However in the past I hit "no space left …" during
apt-get upgrade, then I recovered with
btrfs balance and
fstrim. I don't know when (if) this strikes me again. I'd like to do my maintenance before I get "no space left …" when doing something important.
How to recover from this situation so
btrfs balance do not block each other? Can I fix this from within my running system?
In fact I have already fixed this, my answer is below. The question is for future reference. Feel free to add another solution.
$ uname -a Linux foobar 4.4.0-78-generic #99-Ubuntu SMP […] x86_64 x86_64 x86_64 GNU/Linux $ cat /etc/issue Ubuntu 16.04.3 LTS \n \l # dpkg -l | grep btrfs ii btrfs-tools 4.4-1ubuntu1 amd64 Checksumming Copy on Write Filesystem utilities