how to delete btrfs subvolume?

Hi,

how can I delete an existing btrfs subvolume? The documentation is poor, so I tried this:

btrfs subvol list /

ID 256 gen 114 top level 5 path @
ID 257 gen 135 top level 256 path @/.snapshots
ID 258 gen 137 top level 257 path @/.snapshots/1/snapshot
ID 259 gen 114 top level 256 path @/boot/grub2/i386-pc
ID 260 gen 114 top level 256 path @/boot/grub2/x86_64-efi
ID 261 gen 130 top level 256 path @/home
ID 262 gen 114 top level 256 path @/opt
ID 263 gen 114 top level 256 path @/srv

umount /home

btrfs subvol delete @/home

ERROR: cannot access subvolume @/home: No such file or directory

btrfs subvol delete @home

ERROR: cannot access subvolume @home: No such file or directory

btrfs subvol delete /@home

ERROR: cannot access subvolume /@home: No such file or directory

btrfs subvol delete /home

ERROR: not a subvolume: /home

btrfs subvol delete home

ERROR: cannot access subvolume home: No such file or directory

Olaf

On 22/02/18 14:14, oz42 wrote:
[color=blue]

how can I delete an existing btrfs subvolume? The documentation is poor,
so I tried this:

btrfs subvol list /

ID 256 gen 114 top level 5 path @
ID 257 gen 135 top level 256 path @/.snapshots
ID 258 gen 137 top level 257 path @/.snapshots/1/snapshot
ID 259 gen 114 top level 256 path @/boot/grub2/i386-pc
ID 260 gen 114 top level 256 path @/boot/grub2/x86_64-efi
ID 261 gen 130 top level 256 path @/home
ID 262 gen 114 top level 256 path @/opt
ID 263 gen 114 top level 256 path @/srv

umount /home

btrfs subvol delete @/home

ERROR: cannot access subvolume @/home: No such file or directory

btrfs subvol delete @home

ERROR: cannot access subvolume @home: No such file or directory

btrfs subvol delete /@home

ERROR: cannot access subvolume /@home: No such file or directory

btrfs subvol delete /home

ERROR: not a subvolume: /home

btrfs subvol delete home

ERROR: cannot access subvolume home: No such file or directory[/color]

What does “btrfs subvol show /home” output?

HTH.

Simon
SUSE Knowledge Partner


If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below. Thanks.

Hi Simon,

Sorry, I don’t mean to hijack this old thread, but it perfectly describes my scenario as well, and the originator never replied to your question. Here’s the output from executing the command on my system:

#btrfs subvol show /home
@/home
            Name:                         home
            UUID:                          70dac317-4b49-a94e-b047-39b738307260
            Parent UUID:                 -
            Received UUID:             -
            Creation time:               2019-03-09 09:02:37 -0600
            Subvolume ID:              264
            Generation:                  217
            Gen at creation:            25
            Parent ID:                    257
            Top level ID:                 257
            Flags:                          -
            Snapshot(s):
#

Thanks! Elliott

even though this thread is old, the answer needs to be documented:

  • you can’t just do btrfs subvol delete /opt (or whatever) because the parent root filesystem isn’t technically “mounted” on the system in the normal way (it’s a “Flat” layout as described in https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Flat )

  • you have to re-mount the filesystem on another path & then delete the subvolume using that path. for example:

the necessary approach is to find the mount the filesystem again on a separate mountpoint and then delete that path, for example:

# btrfs device usage /
/dev/vda2, ID: 1
Device size: 36.24GiB
Device slack: 0.00B
Data,single: 3.01GiB
Metadata,DUP: 2.00GiB
System,DUP: 16.00MiB
Unallocated: 31.22GiB

(shows us the underlying device in this case is /dev/vda2)

we then use the “magic” subvolID 5 which always refers to the root filesystem
(not sure where this is referenced)

[B]# mount -o subvolid=5 /dev/vda2 /mnt

btrfs subvolume delete /mnt/@/opt

umount /mnt[/B]

the good news is that if you use the YAST partitioner to delete the subvolumes, it will just work.