4

So I'm trying to wrap my head around BTRFS and set up my fileserver using BTRFS filesystems. Here is my setup:

  • /dev/sda1 : BTRFS filesystem, contains @, @home subvolumes mounted to / and /home.

  • /dev/sdb1 and /dev/sdc1 : BRTFS pooled filesystem, 2x3GB HDD's,
    contains all my media files. Currently mounted to /mnt/media

I have them setup this way because I do not want any of my media files taking up space on /dev/sda1 which is a 120GB SSD; I'd like to only reserve that for system files. I'd like to mount this secondary BTRFS filesystem to a top-level subvolume labeled @media so I can do snapshots. However, every time I try to mount either /dev/sdb1 or /dev/sdc1 using subvolid, I get this error:

peetipablo@flexo:/$ sudo mount -t btrfs -o subvolid=354 /dev/sdb1 /mnt/media
mount: mount(2) failed: No such file or directory

Here's the subvolume list:

peetipablo@flexo:/$ sudo btrfs subvolume list /
ID 257 gen 142548 top level 5 path @
ID 258 gen 142527 top level 5 path @home
ID 310 gen 113715 top level 5 path @apt-snapshot-release-upgrade-utopic-2015-04-30_08:11:14
ID 311 gen 113766 top level 5 path @apt-snapshot-release-upgrade-vivid-2015-04-30_08:39:50
ID 312 gen 134632 top level 257 path var/lib/machines
ID 313 gen 142500 top level 257 path root_snapshot_5_13_15
ID 354 gen 142517 top level 5 path @media

If I try to make @media the default subvolume for directory /mnt/media, I am able to mount sdb1 without the -o subvolid, but when I try to snapshot I get an error:

peetipablo@flexo:/$ sudo btrfs subvolume set-default 354 /mnt/media
peetipablo@flexo:/$ sudo btrfs subvolume get-default /mnt/media
ID 354 gen 142517 top level 5 path @media
peetipablo@flexo:/$ sudo mount -t btrfs /dev/sdb1 /mnt/media
peetipablo@flexo:/$ sudo btrfs subvolume snapshot @media /mnt/media_snap
ERROR: error accessing '@media'
peetipablo@flexo:/$ sudo btrfs subvolume snapshot /mnt/media /mnt/media_snap
Create a snapshot of '/mnt/media' in '/mnt/media_snap'
ERROR: cannot snapshot '/mnt/media' - Invalid cross-device link

I have a feeling that I'm not understanding something or am using this newer filesystem type in a way that it's not meant to be used. Should I just merge all 3 devices into one BTRFS filesystem and not worry about filling up my SSD with media? Is there a way to achieve my end goal using a different method than the one I'm currently using?

1 Answer 1

5

Btrfs filesystems do not interact with each other, so you cannot mount the @media subvolume on /dev/sd{b,c}1 because the @media subvolume is currently on /dev/sda1, and you get a cross-device error when you try to snapshot /mnt/media to /mnt/media_snap because /mnt/media is on /dev/sd{b,c}1 whereas /mnt/media_snap is on /dev/sda1.

Instead of having the @media subvolume on the /dev/sda1 btrfs filesystem, you want to create an @media subvolume on the btrfs filesystem on /dev/sd{b,c}1:

sudo mount /dev/sdb1 /mnt/media/
sudo btrfs subvol create /mnt/media/@media
sudo umount /mnt/media/
sudo mount -o subvol=@media /dev/sdb1 /mnt/media/

You can create snapshots of /mnt/media/, but you can place the snapshot only on the /dev/sd{b,c}1 filesystem. So you can create a read-only snapshot like this:

sudo btrfs subvol snap -r /mnt/media/ /mnt/media/<snapshot_name>

But I recommend placing each snapshot of a subvolume outside the subvolume itself, because this simplifies things when you need to revert to a snapshot. To do this, you will need to mount the root of the /dev/sd{b,c}1 filesystem:

sudo mkdir /mnt/media_root/
sudo mount -o subvol=/ /dev/sdb1 /mnt/media_root/
sudo btrfs subvol snap -r /mnt/media_root/@media/ /mnt/media_root/<snapshot_name>
2
  • Hey, thanks for the reply! I forgot I had posted this question. That is a great explanation, thanks so much. Jul 10, 2015 at 4:07
  • What do I've to do to make subvol of one partition to another? I've separate root and /home partitions, both Btrfs. I get the cross-device link error when I try btrfs subvolume snapshot / Downloads/root. Both partitions are on the same physical drive.
    – Oxwivi
    Nov 14, 2018 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .