parent
65cc198539
commit
dda7e9e3ee
@ -0,0 +1,32 @@ |
||||
{ config, pkgs, lib, ... }: let |
||||
|
||||
cfg = config.boot.initrd.services.mdraid; |
||||
|
||||
in { |
||||
options.boot.initrd.services.mdraid = { |
||||
enable = (lib.mkEnableOption "mdraid support in initrd") // { |
||||
visible = false; |
||||
}; |
||||
|
||||
mdadmConf = lib.mkOption { |
||||
description = "Contents of <filename>/etc/mdadm.conf</filename> in initrd."; |
||||
type = lib.types.lines; |
||||
default = ""; |
||||
}; |
||||
}; |
||||
|
||||
config = lib.mkIf (config.boot.initrd.systemd.enable && cfg.enable) { |
||||
boot.initrd.systemd = { |
||||
contents."/etc/mdadm.conf" = lib.mkIf (cfg.mdadmConf != "") { |
||||
text = cfg.mdadmConf; |
||||
}; |
||||
|
||||
initrdBin = [ pkgs.mdadm ]; |
||||
}; |
||||
|
||||
boot.initrd.services.udev.packages = [ pkgs.mdadm ]; |
||||
boot.initrd.systemd.packages = [ pkgs.mdadm ]; |
||||
|
||||
boot.kernelModules = [ "dm-raid" ]; |
||||
}; |
||||
} |
@ -0,0 +1,50 @@ |
||||
import ./make-test-python.nix ({ lib, pkgs, ... }: { |
||||
name = "systemd-initrd-mdraid"; |
||||
|
||||
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.mdraid = { |
||||
enable = true; |
||||
mdadmConf = '' |
||||
ARRAY /dev/md0 devices=/dev/vdc,/dev/vdd |
||||
''; |
||||
}; |
||||
kernelModules = [ "raid0" ]; |
||||
}; |
||||
|
||||
specialisation.boot-mdraid.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-mdraid.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") |
||||
''; |
||||
}) |
Loading…
Reference in new issue