BTRFS subvolumes: mount failed: Operation not permitted

Hello all!

I’ve been toiling away trying to adapt make-btrfs-fs.nix (kindly provided by @c00w – thank you!) to create subvolumes (instead of populating everything into the root subvolume).

Unfortunately, AFAICT one cannot create a BTRFS subvolume directly on an image; it must be mounted, and then can be created via btrfs subvol create /path/to/mount/subvolname.

Also unfortunately, it doesn’t seem that I’m able to mount anything in a script due to absence of root privileges, and fakeroot doesn’t seem to work around the issue:

++ mkdir ./btrfsmount
++ fakeroot ${pkgs.mount}/bin/mount $img ./btrfsmount
mount: ./btrfsmount: mount failed: Operation not permitted

Is there another way to go about creating btrfs subvolumes within a derivation?

Please forgive mistakes in terminology; made it through Nix Pills this week and obviously still have a lot to learn.

TIA for any help!

Fakeroot won’t help you since mounting things needs real root.

You can’t use operations that require superuser privileges in the sandbox.

What you can do is run a VM inside the sandbox and modify the images inside the VM.

Looks like I can just create the subvolumes in boot.postBootCommands; since it is running as root there and the root subvolume is already mounted, it seems to work.

Yeah - that’s probably your best bet - One question that might be worth emailing the btrfs list, is if there is a way to make subvolumes with mkfs.btrfs - I doubt anyone has wanted it before (and I personally don’t use them at all), but it does seem like something that should be technically possible with mkfs.btrfs and may have a use case for people who use subvolumes.

1 Like

A few years later…