btrfs 解决设备没有空间的问题-No space left on device

有时候btrfs会提示 没有空间的问题。这时往往是metadata快满了,扩容metadata即可

get “No space left on device” errors, but df says I’ve got lots of space

First, check how much space has been allocated on your filesystem:

$ sudo btrfs fi show
Label: ‘media’ uuid: 3993e50e-a926-48a4-867f-36b53d924c35
Total devices 1 FS bytes used 61.61GB
devid 1 size 133.04GB used 133.04GB path /dev/sdf

Note that in this case, all of the devices (the only device) in the filesystem are fully utilised. This is your first clue.

Next, check how much of your metadata allocation has been used up:

$ sudo btrfs fi df /mount/point
Data: total=127.01GB, used=56.97GB
System, DUP: total=8.00MB, used=20.00KB
System: total=4.00MB, used=0.00
Metadata, DUP: total=3.00GB, used=2.32GB
Metadata: total=8.00MB, used=0.00

Note that the Metadata used value is fairly close (75% or more) to the Metadata total value, but there’s lots of Data space left. What has happened is that the filesystem has allocated all of the available space to either data or metadata, and then one of those has filled up (usually, it’s the metadata space that does this). For now, a workaround is to run a partial balance:

$ sudo btrfs fi balance start -dusage=5 /mount/point

Note that there should be no space between the -d and the usage. This command will attempt to relocate data in empty or near-empty data chunks (at most 5% used, in this example), allowing the space to be reclaimed and reassigned to metadata.

If the balance command ends with “Done, had to relocate 0 out of XX chunks”, then you need to increase the “dusage” percentage parameter till at least one chunk is relocated. More information is available elsewhere in this wiki, if you want to know what a balance does, or what options are available for the balance command.