How to delete btrfs subvolume

btrfs

I have a snapshot that I'd like to delete:

04:03:21::mlissner@pounamu::~ 
↪ sudo btrfs subvolume list /
ID 257 gen 267078 top level 5 path @badroot
ID 258 gen 267151 top level 5 path @home
ID 422 gen 267151 top level 5 path @

The one called @badroot is bad and must go. But:

04:03:23::mlissner@pounamu::~ 
↪ sudo btrfs subvolume delete \@badroot
ERROR: error accessing '@badroot'
04:03:31::mlissner@pounamu::~ 

So I don't know where to proceed. I tried reading the help file:

↪ sudo btrfs subvolume delete --help
usage: btrfs subvolume delete <subvolume> [<subvolume>...]

    Delete subvolume(s)

But that's useless too. Perhaps the kind people of the Internet have ideas.

Best Answer

First possibility

It seems like you are referring to @badroot using the wrong path.

If I am reading your shell prompt correctly, your current directory is ~, your home directory — which is probably /home/mlissner or similar. You are specifying the path to the subvolume as a relative path (does not start with /), so you are effectively asking to delete something like /home/mlissner/@badroot... which does not exist.

Try an absolute path instead:

sudo btrfs subvolume delete /@badroot

Second possibility

Perhaps you have a non-default subvolume mounted on /, for example number 422, @. In this case, only that subvolume appears under / and you cannot see anything above that path, including the other two subvolumes plus any regular files located in the root of the Btrfs.

In this case, mount the true Btrfs root somewhere else so that you can access its contents. The Btrfs's true root is known as subvolume ID 0 (and is not listed by btrfs subvolume list). Find or create a free mount point and mount as follows:

mount -o subvolid=0 /dev/some-device /mnt

Now you should be able to see /mnt/@, /mnt/@badroot, /mnt/@home, plus maybe some other files under /mnt. You can delete subvolume /mnt/@badroot as usual.

Related Question