How to create a BTRFS subvolume with a name containing ‘@’

btrfsopensuse

I'm trying to automate creation and mounting of btrfs subvolumes. It's easy for me to create them and create the fstab entry, but harder to parse the subvolume id.

I've noticed that other subvolumes have predictable names prefixed with '@' and they are mounted this way in /etc/fstab

UUID=280d6f04-6ad0-4647-96b9-580aec12bbdc /var/log btrfs noatime,subvol=@/var/log 0 0

Indeed, mounting by such a label works

$ mount -o subvol=@/var/log photoshop-32

Mounting a subvolume with a 'regular' name fails

$ mount -o subvol=var/users/robert/wines/photoshop-32 /var/users/robert/wines/photoshop-32/
mount: mount(2) failed: /var/users/robert/wines/photoshop-32: No such file or directory

I've therefore tried to create a subvolume with such a name but failed

# btrfs subvolume create /var/users/robert/wines/blah/@/var/users/robert/wines/blah
ERROR: cannot access '/var/users/robert/wines/blah/@/var/users/robert/wines': No such file or directory

# btrfs subvolume create /@/var/users/robert/wines/blah
ERROR: cannot access '/@/var/users/robert/wines': No such file or directory

# btrfs subvolume create //@/var/users/robert/wines/blah
# ERROR: cannot access '//@/var/users/robert/wines': No such file or directory

How can I create subvolumes with a '@' in their name? Alternatively, how can I mount subvolumes without the need to find the subvolume id?

Best Answer

Thanks to the #btrfs channel on IRC (full reference), I found out the following:

  • these subvolumes subvolumes are created under the subvolid=0 subvolume, which is not mounted by default
  • to create such subvolumes, first mount that top-level subvolume, and then create the subvolume under it

For instance, in my scenario:

# mount UUID=280d6f04-6ad0-4647-96b9-580aec12bbdc -o subvolid=0 btrfs-sys/
# tree -L 2 /mnt/btrfs-sys/
/mnt/btrfs-sys/
└── @
    ├── boot
    ├── etc
    ├── opt
    ├── srv
    ├── tmp
    ├── usr
    └── var
Related Question