Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
amarshall opened this issue Sep 26, 2023 · 14 comments
Closed

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

amarshall opened this issue Sep 26, 2023 · 14 comments
Labels
0.kind: bug Something is broken

Comments

@amarshall
Copy link
Member

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

  • /proc/spl/kstat/zfs/dbgmsg contains lines like

    zfs_ctldir.c:1109:zfsctl_snapshot_mount(): Unable to automount /.zfs/snapshot/test error=512

  • This appears to be related to Unable to access snapshot files using /.zfs/snapshot/testsnapshot/ openzfs/zfs#9461, however the dataset mounted at / does not exhibit this problem, only nested mounts.

  • Removing neededForBoot = true resolves

  • mount -t zfs rootpool/foo -o remount resolves.

Notify maintainers

Unsure who…

Metadata

Using recent nixos-unstable (e35dcc0).

 - 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`
@amarshall amarshall added the 0.kind: bug Something is broken label Sep 26, 2023
@matthiasdotsh
Copy link
Contributor

matthiasdotsh commented Mar 26, 2024

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
Copy link
Contributor

Shawn8901 commented Apr 11, 2024

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

@Enzime
Copy link
Member

Enzime commented Sep 13, 2024

@matthiasdotsh Try with the dataset instead of the snapshot

sudo mount -t zfs rpool/encrypted/safe -o remount

I've managed to reproduce this issue with both the legacy stage1 as well as the systemd stage1

The easiest workaround for this issue is to run mount -a -t zfs -o remount

In my personal setup I just add it as an extra command to the zfs-mount.service:

systemd.services.zfs-mount = {
  serviceConfig = {
    ExecStart = [ "${lib.getExe' pkgs.util-linux "mount"} -a -t zfs -o remount" ];
  };
};

This works with both legacy (mountpoint=legacy) and native (mountpoint=/...) ZFS datasets that have neededForBoot = true;

cc @ElvishJerricco

@Enzime
Copy link
Member

Enzime commented Sep 15, 2024

I did some further testing and my previous setting led to my system being broken in some weird ways, the easiest workaround I have found is to set the mountpoint on all my datasets:

$ zfs set -u mountpoint=/ rpool/root

The -u flag means it'll update the mountpoint without unmounting/mounting anything which allows you to do it on an online system

Then instead I use this snippet:

systemd.services.zfs-mount = {
  serviceConfig = {
    ExecStart = [ "${config.boot.zfs.package}/sbin/zfs mount -a -o remount" ];
  };
};

All my ZFS datasets are marked as neededForBoot, so I'm not sure if this will cause issues if you also have non-legacy ZFS datasets that aren't needed for boot

@amarshall
Copy link
Member Author

amarshall commented Oct 3, 2024

For what it’s worth, this seems to not be a problem with boot.initrd.systemd.enable = true (I haven’t A/B tested it yet, but I recently changed and no longer have that problem—or a lot of other issues tbh.)

@Shawn8901
Copy link
Contributor

Shawn8901 commented Oct 3, 2024

For what it’s worth, this seems to not be a problem with boot.initrd.systemd.enable = true (I haven’t A/B tested it yet, but I recently changed and no longer have that problem—or a lot of other issues tbh.)

I am also using systems on all of my hosts, so that could be the reason that I wasn't able to reproduce it.

@Enzime
Copy link
Member

Enzime commented Oct 3, 2024

When I tested it I believe I was able to reproduce it with systemd stage1 and with the legacy stage1.

@Shawn8901 Did you check if the contents of the /persist/.zfs/snapshot/zrepl_20240409_202739_000 is correct?

@Shawn8901
Copy link
Contributor

When I tested it I believe I was able to reproduce it with systemd stage1 and with the legacy stage1.

@Shawn8901 Did you check if the contents of the /persist/.zfs/snapshot/zrepl_20240409_202739_000 is correct?

Okay now I got it. Can repro. Hadn't read the inital content careful enough.

@amarshall
Copy link
Member Author

amarshall commented Oct 3, 2024

Scratch that, it is indeed not working with systemd initrd either, I made a mistake when spot checking.

@iynaix
Copy link
Contributor

iynaix commented Nov 6, 2024

The remount workaround used to work for me on zfs 2.2, but sadly it no longer does on zfs 2.3rc2.

Upon bisecting, the commit that introduced this regression is: openzfs/zfs@34118eac06fba83

@n-elderbroom
Copy link

This seems to be fixed for me in 2.3.0-rc3. The snapshot dirs all appeared empty for me previously, but work after updating. I didn't implement any of the workarounds for this bug, and made no config changes other than the update.

@Enzime
Copy link
Member

Enzime commented Nov 28, 2024

Looks like this is the PR that should fix it in 2.3.0-rc3 openzfs/zfs#16646

@Hyffer
Copy link

Hyffer commented Dec 5, 2024

Same here. now upgrade to zfs 2.3.0-rc3 and it works like a charm

@ElvishJerricco
Copy link
Contributor

I'll close this then. Feel free to re-open if ZFS 2.3 did not resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

8 participants