From aac666e302807805154190ebe105711d585c90ee Mon Sep 17 00:00:00 2001 From: kklas Date: Thu, 25 Feb 2016 14:08:27 +0100 Subject: [PATCH] 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. --- nixos/modules/system/boot/stage-1.nix | 1 + nixos/modules/tasks/swraid.nix | 41 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index f31620df1d8..757d883373a 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -58,6 +58,7 @@ let # Add RAID mdadm tool. copy_bin_and_libs ${pkgs.mdadm}/sbin/mdadm + copy_bin_and_libs ${pkgs.mdadm}/sbin/mdmon # Copy udev. copy_bin_and_libs ${udev}/lib/systemd/systemd-udevd diff --git a/nixos/modules/tasks/swraid.nix b/nixos/modules/tasks/swraid.nix index 8e972891971..18df0e224d5 100644 --- a/nixos/modules/tasks/swraid.nix +++ b/nixos/modules/tasks/swraid.nix @@ -12,4 +12,45 @@ cp -v ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/ ''; + systemd.services.mdadmShutdown = { + wantedBy = [ "final.target"]; + after = [ "umount.target" ]; + + unitConfig = { + DefaultDependencies = false; + }; + + serviceConfig = { + Type = "oneshot"; + ExecStart = ''${pkgs.mdadm}/bin/mdadm --wait-clean --scan''; + }; + }; + + systemd.services."mdmon@" = { + description = "MD Metadata Monitor on /dev/%I"; + + unitConfig.DefaultDependencies = false; + + serviceConfig = { + Type = "forking"; + Environment = "IMSM_NO_PLATFORM=1"; + ExecStart = ''${pkgs.mdadm}/bin/mdmon --offroot --takeover %I''; + KillMode = "none"; + }; + }; + + systemd.services."mdadm-grow-continue@" = { + description = "Manage MD Reshape on /dev/%I"; + + unitConfig.DefaultDependencies = false; + + serviceConfig = { + ExecStart = ''${pkgs.mdadm}/bin/mdadm --grow --continue /dev/%I''; + StandardInput = "null"; + StandardOutput = "null"; + StandardError = "null"; + KillMode = "none"; + }; + }; + }