sw-raid: make mdmon start from initrd

Also add required systemd services for starting/stopping mdmon.

Closes #13447.
abbradar: fixed `mdadmShutdown` service name according to de facto conventions.

authored by

kklas and committed by
Nikolay Amiantov
aac666e3 b20439ef

+42
+1
nixos/modules/system/boot/stage-1.nix
··· 58 58 59 59 # Add RAID mdadm tool. 60 60 copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm 61 + copy_bin_and_libs ${pkgs.mdadm}/sbin/mdmon 61 62 62 63 # Copy udev. 63 64 copy_bin_and_libs ${udev}/lib/systemd/systemd-udevd
+41
nixos/modules/tasks/swraid.nix
··· 12 12 cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ 13 13 ''; 14 14 15 + systemd.services.mdadmShutdown = { 16 + wantedBy = [ "final.target"]; 17 + after = [ "umount.target" ]; 18 + 19 + unitConfig = { 20 + DefaultDependencies = false; 21 + }; 22 + 23 + serviceConfig = { 24 + Type = "oneshot"; 25 + ExecStart = ''${pkgs.mdadm}/bin/mdadm --wait-clean --scan''; 26 + }; 27 + }; 28 + 29 + systemd.services."mdmon@" = { 30 + description = "MD Metadata Monitor on /dev/%I"; 31 + 32 + unitConfig.DefaultDependencies = false; 33 + 34 + serviceConfig = { 35 + Type = "forking"; 36 + Environment = "IMSM_NO_PLATFORM=1"; 37 + ExecStart = ''${pkgs.mdadm}/bin/mdmon --offroot --takeover %I''; 38 + KillMode = "none"; 39 + }; 40 + }; 41 + 42 + systemd.services."mdadm-grow-continue@" = { 43 + description = "Manage MD Reshape on /dev/%I"; 44 + 45 + unitConfig.DefaultDependencies = false; 46 + 47 + serviceConfig = { 48 + ExecStart = ''${pkgs.mdadm}/bin/mdadm --grow --continue /dev/%I''; 49 + StandardInput = "null"; 50 + StandardOutput = "null"; 51 + StandardError = "null"; 52 + KillMode = "none"; 53 + }; 54 + }; 55 + 15 56 }