NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.29k stars 13.54k forks source link

ZFS snapshot dir not accessible in non-root `neededForBoot` mounts #257505

Open amarshall opened 11 months ago

amarshall commented 11 months ago

Describe the bug

ZFS provides a <mountpoint>/.zfs/snapshot directory that automounts snapshots for easy access. This does not work for non-root mounts that are neededForBoot = true.

Steps to reproduce

{
  fileSystems = {
    "/" = { type = "zfs"; device = "rootpool/root"; };
    # Should `zfs set mountpoint=legacy rootpool/foo`
    "/foo" = { type = "zfs"; device = "rootpool/foo"; neededForBoot = true; };
  };
}
touch /foo/bar
zfs snapshot create rootpool/foo@test
ls /foo/.zfs/snapshot/test

Expected behavior

Expected to find the snapshot files (e.g. bar) in /foo/.zfs/snapshot/test, but is empty.

Additional context

Notify maintainers

Unsure who…

Metadata

Using recent nixos-unstable (e35dcc04a3853da485a396bdd332217d0ac9054f).

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.54, NixOS, 23.11 (Tapir), 23.11.20230922.e35dcc0`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.17.0`
matthiasdotsh commented 5 months ago

Same here.

However, I have to mount the snapshots slightly differently.

The following works for me:

mkdir -p /tmp/zfsmount
sudo mount -t zfs rpool/encrypted/safe@zfs-auto-snap_hourly-2024-03-26-06h00 /tmp/zfsmount

Your suggestion

sudo mount -t zfs rpool/encrypted/safe@zfs-auto-snap_hourly-2024-03-26-06h00 -o remount

Gives me:

mount: rpool/encrypted/safe@zfs-auto-snap_hourly-2024-03-26-06h00: mount point does not exist.
Shawn8901 commented 4 months ago

actually tried to double check on my system, that is using zfsutil for mounting and it seems that i can not directly reproduce with that, so either something else has been fixed or using zfsutil (so non legacy mountpoints) does not trigger the issue

   "/persist" = {
      device = "rpool/safe/persist";
      fsType = "zfs";
      options = [
        "zfsutil"
        "X-mount.mkdir"
      ];
      neededForBoot = true;
    };
─ ls /persist/.zfs/snapshot
zrepl_20240409_202739_000  zrepl_20240410_201732_000  zrepl_20240411_195737_000