diff options
author | Janne Heß <janne@hess.ooo> | 2022-04-11 19:28:09 +0100 |
---|---|---|
committer | Janne Heß <janne@hess.ooo> | 2022-04-13 23:00:19 +0100 |
commit | 2633e82e1a1cb73e83f7d8d6c70fbe125d182005 (patch) | |
tree | adc1da2112c1b80b133474641550145b19cec7eb /nixos/tests/lvm2 | |
parent | 65cc198539f7c78f13c6003339ed2928ce0ac6f0 (diff) |
nixos/stage-1-systemd: Add LVM2 support
Diffstat (limited to 'nixos/tests/lvm2')
-rw-r--r-- | nixos/tests/lvm2/default.nix | 20 | ||||
-rw-r--r-- | nixos/tests/lvm2/systemd-stage-1.nix | 104 |
2 files changed, 123 insertions, 1 deletions
diff --git a/nixos/tests/lvm2/default.nix b/nixos/tests/lvm2/default.nix index 2ba17809569a6..1eb9f572a4d6d 100644 --- a/nixos/tests/lvm2/default.nix +++ b/nixos/tests/lvm2/default.nix @@ -11,6 +11,24 @@ let thinpool = { test = callTest ./thinpool.nix; kernelFilter = lib.id; }; # we would like to test all versions, but the kernel module currently does not compile against the other versions vdo = { test = callTest ./vdo.nix; kernelFilter = lib.filter (v: v == "5.15"); }; + + + # systemd in stage 1 + raid-sd-stage-1 = { + test = callTest ./systemd-stage-1.nix; + kernelFilter = lib.id; + flavour = "raid"; + }; + thinpool-sd-stage-1 = { + test = callTest ./systemd-stage-1.nix; + kernelFilter = lib.id; + flavour = "thinpool"; + }; + vdo-sd-stage-1 = { + test = callTest ./systemd-stage-1.nix; + kernelFilter = lib.filter (v: v == "5.15"); + flavour = "vdo"; + }; }; in lib.listToAttrs ( @@ -20,7 +38,7 @@ lib.listToAttrs ( v' = lib.replaceStrings [ "." ] [ "_" ] version; in lib.flip lib.mapAttrsToList tests (name: t: - lib.nameValuePair "lvm-${name}-linux-${v'}" (lib.optionalAttrs (builtins.elem version (t.kernelFilter kernelVersionsToTest)) (t.test { kernelPackages = pkgs."linuxPackages_${v'}"; })) + lib.nameValuePair "lvm-${name}-linux-${v'}" (lib.optionalAttrs (builtins.elem version (t.kernelFilter kernelVersionsToTest)) (t.test ({ kernelPackages = pkgs."linuxPackages_${v'}"; } // builtins.removeAttrs t [ "test" "kernelFilter" ]))) ) ) ) diff --git a/nixos/tests/lvm2/systemd-stage-1.nix b/nixos/tests/lvm2/systemd-stage-1.nix new file mode 100644 index 0000000000000..617ba77b1796c --- /dev/null +++ b/nixos/tests/lvm2/systemd-stage-1.nix @@ -0,0 +1,104 @@ +{ kernelPackages ? null, flavour }: let + preparationCode = { + raid = '' + machine.succeed("vgcreate test_vg /dev/vdc /dev/vdd") + machine.succeed("lvcreate -L 512M --type raid0 test_vg -n test_lv") + ''; + + thinpool = '' + machine.succeed("vgcreate test_vg /dev/vdc") + machine.succeed("lvcreate -L 512M -T test_vg/test_thin_pool") + machine.succeed("lvcreate -n test_lv -V 16G --thinpool test_thin_pool test_vg") + ''; + + vdo = '' + machine.succeed("vgcreate test_vg /dev/vdc") + machine.succeed("lvcreate --type vdo -n test_lv -L 6G -V 12G test_vg/vdo_pool_lv") + ''; + }.${flavour}; + + extraConfig = { + raid = { + boot.initrd.kernelModules = [ + "dm-raid" + "raid0" + ]; + }; + + thinpool = { + services.lvm = { + boot.thin.enable = true; + dmeventd.enable = true; + }; + }; + + vdo = { + services.lvm = { + boot.vdo.enable = true; + dmeventd.enable = true; + }; + }; + }.${flavour}; + + extraCheck = { + raid = '' + "test_lv" in machine.succeed("lvs --select segtype=raid0") + ''; + + thinpool = '' + "test_lv" in machine.succeed("lvs --select segtype=thin-pool") + ''; + + vdo = '' + "test_lv" in machine.succeed("lvs --select segtype=vdo") + ''; + }.${flavour}; + +in import ../make-test-python.nix ({ pkgs, ... }: { + name = "lvm2-${flavour}-systemd-stage-1"; + meta.maintainers = with pkgs.lib.maintainers; [ das_j ]; + + nodes.machine = { pkgs, lib, ... }: { + imports = [ extraConfig ]; + # Use systemd-boot + virtualisation = { + emptyDiskImages = [ 8192 8192 ]; + useBootLoader = true; + useEFIBoot = true; + }; + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + environment.systemPackages = with pkgs; [ e2fsprogs ]; # for mkfs.ext4 + boot = { + initrd.systemd = { + enable = true; + emergencyAccess = true; + }; + initrd.services.lvm.enable = true; + kernelPackages = lib.mkIf (kernelPackages != null) kernelPackages; + }; + + specialisation.boot-lvm.configuration.virtualisation.bootDevice = "/dev/test_vg/test_lv"; + }; + + testScript = '' + machine.wait_for_unit("multi-user.target") + # Create a VG for the root + ${preparationCode} + machine.succeed("mkfs.ext4 /dev/test_vg/test_lv") + machine.succeed("mkdir -p /mnt && mount /dev/test_vg/test_lv /mnt && echo hello > /mnt/test && umount /mnt") + + # Boot from LVM + machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-lvm.conf") + machine.succeed("sync") + machine.crash() + machine.wait_for_unit("multi-user.target") + + # Ensure we have successfully booted from LVM + assert "(initrd)" in machine.succeed("systemd-analyze") # booted with systemd in stage 1 + assert "/dev/mapper/test_vg-test_lv on / type ext4" in machine.succeed("mount") + assert "hello" in machine.succeed("cat /test") + ${extraCheck} + ''; +}) |