You are not logged in.
Pages: 1
I recently found out by experimenting that you can mount a btrfs subvolume by making a symlink to it and attempting to mount the symlink instead. For example, if the btrfs filesystem contains
subvolume
link --> subvolume
then you can do
mount ... -t btrfs ... -o subvol=link
and you get 'subvolume' mounted instead.
Neither the man page BTRFS-SUBVOLUME(8) nor the btrfs faq seem to mention using symlinks in this way. Am I using an undocumented feature, which is hence liable to break in the future, or is it just obvious that this should work? What are the rules for how such symlinks are resolved - for example, if a symlink points to an absolute path, is that interpreted relative to the btrfs filesystem root or the system root?
Offline
Interesting. How exactly did you do this? In your example: how can "link" be a symlink file and a subvolume name?
Offline
Something like
cd /tmp
mkdir test
cd test
dd if=/dev/zero of=image.iso bs=1024 count=150000
losetup /dev/loop0 image.iso
mkfs.btrfs /dev/loop0
mkdir mnt
mount /dev/loop0 mnt
cd mnt
btrfs subvolume create subvolume
ln -sr subvolume link
cd ..
umount mnt
mount /dev/loop0 -t btrfs mnt -o subvol=link
although I pieced this together from my bash history, so it isn't actually tested.
Offline
It turns out you can even boot off one of these symlinks! (I.e. specifying it as the system root on the kernel commandline.)
I should also add for anyone wishing to try out the code sample above, don't forget to clean up by running
umount mnt
rmdir mnt
losetup -d /dev/loop0
rm image.iso
cd ..
rmdir test
and also remember to adjust if necessary if /dev/loop0 is not the first available loop device, or you'll end up wiping whatever was there.
Offline
I can confirm your findings but you don't need to use losetup or dd:
$ mkdir -p /tmp/test && cd $_
$ fallocate -l 10G image.iso
$ mkfs.btrfs image.iso
# mount image.iso /mnt && cd $_
# btrfs subvolume create subvolume
# ln -sr subvolume link && cd -
# umount /mnt
# mount -o subvol=link image.iso /mnt
And to test:
$ findmnt /mnt
TARGET SOURCE FSTYPE OPTIONS
/mnt /dev/loop0[/subvolume] btrfs rw,relatime,ssd,space_cache=v2,subvolid=256,subvol=/subvolume
$
To clean up:
# umount /mnt
$ cd
# rm -r /tmp/test
HTH
Offline
@Head_on_a_Stick: shouldn't the test check via the symlink "link" instead of "subvolume" directly?
Offline
I'm sorry, I don't understand your question
The "link" subvolume has been called from the mount command but findmnt shows the "subvolume" subvolume is actually mounted.
Offline
Nevermind. The mount is done via "subvol=link".
As far as I know the value in subvol=<value> is a path relative to the root folder of the subvolume. And <value> can optionally start with a /.
Offline
I guess any symlink, e.g. a symlink with an absolute path, in subvol=<symlink> would also be relative to the root folder of the subvolume mountpoint.
Last edited by willemw (2021-11-28 13:06:03)
Offline
Pages: 1