From 4346558fd4ce8ef2c3ce3ce690d6e4ca6846ce9b Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 19 Dec 2023 23:44:00 +1100 Subject: [PATCH 1/2] tests: add test for running ZFS as not the rootfs --- example/non-root-zfs.nix | 79 ++++++++++++++++++++++++++++++++++++++++ tests/non-root-zfs.nix | 26 +++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 example/non-root-zfs.nix create mode 100644 tests/non-root-zfs.nix diff --git a/example/non-root-zfs.nix b/example/non-root-zfs.nix new file mode 100644 index 0000000..7434e62 --- /dev/null +++ b/example/non-root-zfs.nix @@ -0,0 +1,79 @@ +{ + disko.devices = { + disk = { + x = { + type = "disk"; + device = "/dev/sdx"; + content = { + type = "gpt"; + partitions = { + ESP = { + size = "64M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + y = { + type = "disk"; + device = "/dev/sdy"; + content = { + type = "gpt"; + partitions = { + zfs = { + size = "100%"; + content = { + type = "zfs"; + pool = "storage"; + }; + }; + }; + }; + }; + z = { + type = "disk"; + device = "/dev/sdz"; + content = { + type = "gpt"; + partitions = { + zfs = { + size = "100%"; + content = { + type = "zfs"; + pool = "storage"; + }; + }; + }; + }; + }; + }; + zpool = { + storage = { + type = "zpool"; + mode = "mirror"; + mountpoint = "/storage"; + + datasets = { + dataset = { + type = "zfs_fs"; + mountpoint = "/storage/dataset"; + }; + }; + }; + }; + }; +} + diff --git a/tests/non-root-zfs.nix b/tests/non-root-zfs.nix new file mode 100644 index 0000000..e4fe24c --- /dev/null +++ b/tests/non-root-zfs.nix @@ -0,0 +1,26 @@ +{ pkgs ? import { } +, diskoLib ? pkgs.callPackage ../lib { } +}: +diskoLib.testLib.makeDiskoTest { + inherit pkgs; + name = "non-root-zfs"; + disko-config = ../example/non-root-zfs.nix; + extraInstallerConfig.networking.hostId = "8425e349"; + extraSystemConfig.networking.hostId = "8425e349"; + postDisko = '' + machine.succeed("mountpoint /mnt/storage") + machine.succeed("mountpoint /mnt/storage/dataset") + + filesystem = machine.execute("stat --file-system --format=%T /mnt/storage")[1].rstrip() + print(f"/mnt/storage {filesystem=}") + assert filesystem == "zfs", "/mnt/storage is not ZFS" + ''; + extraTestScript = '' + machine.succeed("mountpoint /storage") + machine.succeed("mountpoint /storage/dataset") + + filesystem = machine.execute("stat --file-system --format=%T /storage")[1].rstrip() + print(f"/mnt/storage {filesystem=}") + assert filesystem == "zfs", "/storage is not ZFS" + ''; +} From 9f9ff673d126858bc8de6f0c08f9d1b1adcc1097 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Tue, 19 Dec 2023 23:49:30 +1100 Subject: [PATCH 2/2] zpool: fix default dataset getting shadowed If the zpool's root dataset is not the rootfs and gets mounted on creation, the actual rootfs will get mounted later and shadow the current mountpoint. Running `zfs unmount` is the easiest way to unmount the zpool's root dataset on creation without messing up the value of the `mountpoint` setting. --- lib/types/zpool.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/types/zpool.nix b/lib/types/zpool.nix index 0bf97c9..7654ca5 100644 --- a/lib/types/zpool.nix +++ b/lib/types/zpool.nix @@ -67,6 +67,9 @@ ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ "''${zfs_devices[@]}" + ${lib.optionalString ((config.rootFsOptions.mountpoint or "") != "none") '' + zfs unmount ${config.name} + ''} ${lib.concatMapStrings (dataset: dataset._create) (lib.attrValues config.datasets)} ''; };