You are not logged in.

#1 2023-04-16 09:17:59

Cheeto
Member
Registered: 2022-09-11
Posts: 64

help with btrfs subvolumes

Sources already read (not to imply I understood them well, as I'm a newb):
https://wiki.archlinux.org/title/btrfs#Subvolumes
https://wiki.archlinux.org/title/btrfs
https://wiki.archlinux.org/title/snapper
https://wiki.archlinux.org/title/snappe … tem_layout
Many others around the internet

I want to do something extremely simple. I want to create a subvolume to mount on a shared folder in my home directory.

Therefore I did the following:

sudo btrfs subvol create /@shared
# I made it in the root directory because that's where all the other default ones appear to be, they all have the path /@home, /@pkg, etc.

mkdir /home/username/shared

sudo nano /etc/fstab

# from nautilus, drag /@shared into the terminal so I'm certain I have it's correct path - get back /@shared
# do the same for /home/username/shared - get back /home/username/shared

# copy the following line from /etc/fstab
# /dev/mapper/ainstvda2
# UUID=71be9149-6e60-4f8b-bf05-92d70941a931	/home     	btrfs     	rw,relatime,space_cache=v2,subvol=/@home	0 0

# change it according to my goal of mounting /@shared to /home/username/shared, the result being the following line, but uncommented:
# UUID=71be9149-6e60-4f8b-bf05-92d70941a931	/home/username/shared     	btrfs     	rw,relatime,space_cache=v2,subvol=/@shared	0 0

reboot

At this point it fails to boot, and I have to uncomment the new line in /etc/fstab, so my fstab looks like this:

~$ cat /etc/fstab
# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir> <type> <options> <dump> <pass>
# /dev/mapper/ainstvda2
UUID=71be9149-6e60-4f8b-bf05-92d70941a931	/         	btrfs     	rw,relatime,space_cache=v2,subvol=/@	0 0

# /dev/vda1
UUID=30F2-24A4      	/boot     	vfat      	rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro	0 2

# /dev/mapper/ainstvda2
UUID=71be9149-6e60-4f8b-bf05-92d70941a931	/.snapshots	btrfs     	rw,relatime,space_cache=v2,subvol=/@.snapshots	0 0

# /dev/mapper/ainstvda2
UUID=71be9149-6e60-4f8b-bf05-92d70941a931	/home     	btrfs     	rw,relatime,space_cache=v2,subvol=/@home	0 0

# /dev/mapper/ainstvda2
UUID=71be9149-6e60-4f8b-bf05-92d70941a931	/var/cache/pacman/pkg	btrfs     	rw,relatime,space_cache=v2,subvol=/@pkg	0 0

# /dev/mapper/ainstvda2
UUID=71be9149-6e60-4f8b-bf05-92d70941a931	/var/log  	btrfs     	rw,relatime,space_cache=v2,subvol=/@log	0 0

# /dev/mapper/ainstvda2
# UUID=71be9149-6e60-4f8b-bf05-92d70941a931       /home/user1/shared           btrfs           rw,relatime,space_cache=v2,subvol=/@shared   0 0

The weird thing is, I did this several times and the first time I booted with no issues (I did it several more times because the ultimate goal of getting the passthrough shared drive wasn't working, but that's unrelated to this topic which is about learning what I'm doing wrong with btrfs). It even booted after I made some changes to it. So I'm not sure what I'm doing now that's so wrong it won't boot, though I'm sure it will be super obvious if someone can point it out and offer some guidance.

Thanks in advance.

Last edited by Cheeto (2023-04-16 09:30:03)

Offline

#2 2023-04-16 10:40:24

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: help with btrfs subvolumes

No error message on screen/in journal?

Cheeto wrote:
sudo btrfs subvol create /@shared
# I made it in the root directory because that's where all the other default ones appear to be, they all have the path /@home, /@pkg, etc.

Each subvol appears as an independent file/directory hierarchy. The subvol mount parameter specifies a path relative to the root of the top-level subvol. According to fstab, you have the subvol /@ mounted on /. This subvol create command would then create a subvol nested in that /@ subvol, so you'd have to use subvol=/@/@shared to mount it. If you want it to be subvol=/@shared, you need to mount the top-level subvolume (subvol=/) somewhere and then create the @shared subvol there.

Last edited by Raynman (2023-04-16 10:41:12)

Offline

#3 2023-04-16 11:31:11

Cheeto
Member
Registered: 2022-09-11
Posts: 64

Re: help with btrfs subvolumes

Raynman wrote:

No error message on screen/in journal?

Cheeto wrote:
sudo btrfs subvol create /@shared
# I made it in the root directory because that's where all the other default ones appear to be, they all have the path /@home, /@pkg, etc.

Each subvol appears as an independent file/directory hierarchy. The subvol mount parameter specifies a path relative to the root of the top-level subvol. According to fstab, you have the subvol /@ mounted on /. This subvol create command would then create a subvol nested in that /@ subvol, so you'd have to use subvol=/@/@shared to mount it. If you want it to be subvol=/@shared, you need to mount the top-level subvolume (subvol=/) somewhere and then create the @shared subvol there.

Wow.....

A couple questions:

1. Why don't the default subvolumes appear in / then? They have their paths listed as, for example, /@home. If the answer is, "they aren't in /@ like yours is, they're in /" then how can I make one in / in the same way so that it doesn't show up in my files in / ?
2. I mount it as you suggested, and it works (I can't thank you enough, this stumped several people I was talking to online). After correcting permissions, I can create/delete files in either directory and the changes will reflect in the other. But now, if I mount a shared folder on /@shared (the idea being that if the shared folder is mounted on a subvolume, then restoring to a snapshot won't fuck with the shared folder because subvolumes aren't captured in root config snapshots), and update /etc/fsatb by adding the line:

/sharepoint     /@shared     /virtiofs

it mounts and the files are in /@shared as expected, but then for some reason whatever's the connection between /@shared  and /home/username/shared seems broken (i.e. what's in one is no longer what's in the other, so /home/username/shared is now just an empty directory and /@shared has all the shared folder contents from the host machine).

---

EDIT: ya I'm kind of confused, I thought the whole reason for mounting subvolumes is that you don't see them, you only see what they're mounted to, so in order to access their contents they need to be mounted to a local directory. Now I don't even know why anyone would ever mount a subvolume if they can just create one and boom it's there being a subvolume doing all the things that a subvolume does....??

Last edited by Cheeto (2023-04-16 11:38:17)

Offline

#4 2023-04-16 15:34:01

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: help with btrfs subvolumes

I think I already answered 1, but it hasn't fully sunk in yet, although you got "they aren't in /@ like yours is, they're in /" right. Have you read https://archive.kernel.org/oldwiki/btrf … Subvolumes ?

I don't quite follow 2, but it might be mostly unrelated to subvolumes and more a misunderstanding of mounts?

Cheeto wrote:

(the idea being that if the shared folder is mounted on a subvolume, then restoring to a snapshot won't fuck with the shared folder because subvolumes aren't captured in root config snapshots)

If a directory in subvol X is used as a mountpoint for some other filesystem, snapshotting X is not magically going to include the contents of that other filesystem?

update /etc/fsatb by adding the line:

/sharepoint     /@shared     /virtiofs

it mounts and the files are in /@shared as expected, but then for some reason whatever's the connection between /@shared  and /home/username/shared seems broken

There isn't much of a connection. The same file hierarchy was visible in both those places. The subvol /@/@shared is nested in the /@ subvol and you mounted the latter (the parent subvol) at /, so you can see the nested subvol at /@shared and you also mounted /@/@shared indepedently at /home/username/shared. This new mount would just hide whatever was at /@shared, but that doesn't affect other mounts such as /home/username/shared.

Offline

#5 2023-04-16 16:29:41

Cheeto
Member
Registered: 2022-09-11
Posts: 64

Re: help with btrfs subvolumes

Raynman wrote:

I think I already answered 1, but it hasn't fully sunk in yet, although you got "they aren't in /@ like yours is, they're in /" right. Have you read https://archive.kernel.org/oldwiki/btrf … Subvolumes ?

I don't quite follow 2, but it might be mostly unrelated to subvolumes and more a misunderstanding of mounts?

Cheeto wrote:

(the idea being that if the shared folder is mounted on a subvolume, then restoring to a snapshot won't fuck with the shared folder because subvolumes aren't captured in root config snapshots)

If a directory in subvol X is used as a mountpoint for some other filesystem, snapshotting X is not magically going to include the contents of that other filesystem?

update /etc/fsatb by adding the line:

/sharepoint     /@shared     /virtiofs

it mounts and the files are in /@shared as expected, but then for some reason whatever's the connection between /@shared  and /home/username/shared seems broken

There isn't much of a connection. The same file hierarchy was visible in both those places. The subvol /@/@shared is nested in the /@ subvol and you mounted the latter (the parent subvol) at /, so you can see the nested subvol at /@shared and you also mounted /@/@shared indepedently at /home/username/shared. This new mount would just hide whatever was at /@shared, but that doesn't affect other mounts such as /home/username/shared.


Damn dude, a lot of what you said just went way over my head. If you were chatgpt I'd just ask you to rephrase it to be more understandable instead of using so much technical jargon, but I can't expect you to just focus on me exclusively. Ya, I read that link, it's the first one I mentioned in the OP with the disclaimer that I didn't necessarily understand all of it. How can I create a subvolume at the same location as the default ones? In btrfs subv list / it shows them as the same as mine: /@home for example, like mine is /@shared.

> If a directory in subvol X is used as a mountpoint for some other filesystem, snapshotting X is not magically going to include the contents of that other filesystem?

I don't know what that means...I'm so sorry hmm

> There isn't much of a connection. The same file hierarchy was visible in both those places. The subvol /@/@shared is nested in the /@ subvol and you mounted the latter (the parent subvol) at /, so you can see the nested subvol at /@shared and you also mounted /@/@shared indepedently at /home/username/shared. This new mount would just hide whatever was at /@shared, but that doesn't affect other mounts such as /home/username/shared.

I also don't know what that means........ hmm

Offline

Board footer

Powered by FluxBB