Btrfs Snapshot – Fixing ‘Text File Busy’ Error

btrfslinux

Trying to create a read-only snapshot of the root subvolume using

sudo btrfs sub snap -r /mnt/@ /mnt/@_20200510

leads to error message

Create a readonly snapshot of '/mnt/@' in '/mnt/@_20200510'
ERROR: cannot snapshot '/mnt/@': Text file busy

Also, snapper and other backup tools stopped working.

Best Answer

Turn off and delete the swapfile.

Linux 5.x introduced official swapfile support for Btrfs. Unfortunately, this support appears to be, ahem, incomplete. I suppose what is happening is that a subvolume which contains an open non-COW file cannot be snapshotted (snapshot? snapfleshwounded?). On some level this makes complete sense. On another, wtf. sigh.

If you want to use a swapfile, I think it should be fine to create a separate subvolume, however I have not tested this. Otherwise, you really do need to delete the swapfile before making the snapshot otherwise the file will get reflinked, stop being non-COW even though you marked it as such, and swapon won't work.

Related Question