diff options
author | Janne Heß <janne@hess.ooo> | 2022-04-15 16:28:41 +0100 |
---|---|---|
committer | Janne Heß <janne@hess.ooo> | 2022-04-15 19:57:16 +0100 |
commit | 01bc138a8ef25314e08843845655480c9b04e879 (patch) | |
tree | 15d2185ce3368430d95f862c947b225c6d05170e /nixos/tests/systemd-initrd-swraid.nix | |
parent | 0efb6720a4bbd88fa0e678cc43ba9971ea54991f (diff) |
nixos/stage-1-init: Merge mdraid module into swraid
Diffstat (limited to 'nixos/tests/systemd-initrd-swraid.nix')
-rw-r--r-- | nixos/tests/systemd-initrd-swraid.nix | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/nixos/tests/systemd-initrd-swraid.nix b/nixos/tests/systemd-initrd-swraid.nix new file mode 100644 index 0000000000000..28a0fb3192aed --- /dev/null +++ b/nixos/tests/systemd-initrd-swraid.nix @@ -0,0 +1,50 @@ +import ./make-test-python.nix ({ lib, pkgs, ... }: { + name = "systemd-initrd-swraid"; + + nodes.machine = { pkgs, ... }: { + # Use systemd-boot + virtualisation = { + emptyDiskImages = [ 512 512 ]; + useBootLoader = true; + useEFIBoot = true; + }; + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + environment.systemPackages = with pkgs; [ mdadm e2fsprogs ]; # for mdadm and mkfs.ext4 + boot.initrd = { + systemd = { + enable = true; + emergencyAccess = true; + }; + services.swraid = { + enable = true; + mdadmConf = '' + ARRAY /dev/md0 devices=/dev/vdc,/dev/vdd + ''; + }; + kernelModules = [ "raid0" ]; + }; + + specialisation.boot-swraid.configuration.virtualisation.bootDevice = "/dev/disk/by-label/testraid"; + }; + + testScript = '' + # Create RAID + machine.succeed("mdadm --create --force /dev/md0 -n 2 --level=raid0 /dev/vdc /dev/vdd") + machine.succeed("mkfs.ext4 -L testraid /dev/md0") + machine.succeed("mkdir -p /mnt && mount /dev/md0 /mnt && echo hello > /mnt/test && umount /mnt") + + # Boot from the RAID + machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-swraid.conf") + machine.succeed("sync") + machine.crash() + machine.wait_for_unit("multi-user.target") + + # Ensure we have successfully booted from the RAID + assert "(initrd)" in machine.succeed("systemd-analyze") # booted with systemd in stage 1 + assert "/dev/md0 on / type ext4" in machine.succeed("mount") + assert "hello" in machine.succeed("cat /test") + assert "md0" in machine.succeed("cat /proc/mdstat") + ''; +}) |