Snapper - should .snapshots subvolumes be created automatically?

I am trying to configure snapper using btrfs subvolumes. I notice that there are no .snapshots subvolumes created automatically, and it leads to errors like below, when trying to create a snapshot.

IO Error (open failed path:/srv/.snapshots errno:2 (No such file or directory)).

According to snapper documentation, .snapshots subvolumes would be created by the “snapper create-config” command. But on NixOS, there is configuration to define this and I think it is not intended to create config using this command.

Am I supposed to create the .snapshots subvolumes manually?
Or should NixOS package for snapper take care of that?

Snapper’s NixOS module should ideally take care of that.

I notice the following in the documentation for services.snapper.configs..subvolume

“Path of the subvolume or mount point. This path is a subvolume and has to contain a subvolume named .snapshots”

It makes me think that I need to do it myself

Well yes, you currently do need to do that yourself. Ideally, the module would take care of that however; obviating that string of documentation.

I opened a PR to do it a long time ago nixos/snapper: automatically create the .snapshots subvolume with correct permissions by symphorien · Pull Request #78046 · NixOS/nixpkgs · GitHub but in the end I lost interest because I started using btrbk instead. Feel free to fix the merge conflicts and reopen in your name :slight_smile:

1 Like

I just found btrbk service (for BTRFS snaps) also don’t create the snap directory :thinking:

since it’s just a normal directory (not a subvolume) it’s easy to create with systemd.tmpfiles.rules. (or with the StateDirectory of the service)

2 Likes

since it’s just a normal directory (not a subvolume) it’s easy to create with systemd.tmpfiles.rules. (or with the StateDirectory of the service)

systemd.tmpfiles can also create subvolumes.

3 Likes

Unfortunately not when / is not btrfs, and you are attempting to snapshot another filesystem.

Let’s say you have / on ext4 and then /home as btrfs. As long as the subvolume you are trying to create is under /home it should work.
Or maybe I’m just misunderstanding what you are trying to do.

man tmpfiles.d says:

       v
           Create a subvolume if the path does not exist yet, the file system supports subvolumes
           (btrfs), and the system itself is installed into a subvolume (specifically: the root
           directory / is itself a subvolume). Otherwise, create a normal directory, in the same
           way as d.

My understanding is that when / is ext4 it will create a regular directory.

My understanding is that when / is ext4 it will create a regular directory.

That does seem to be what the man page says.

TIL something new.