* Activate software RAID devices from udev. This makes the swraid
Upstart jobs unnecessary. * Support having the root filesystem on swraid. svn path=/nixos/trunk/; revision=21807
This commit is contained in:
parent
edee370883
commit
7484774172
|
@ -34,7 +34,6 @@ let
|
|||
pkgs.less
|
||||
pkgs.libcap
|
||||
pkgs.man
|
||||
pkgs.mdadm
|
||||
pkgs.module_init_tools
|
||||
pkgs.nano
|
||||
pkgs.ncurses
|
||||
|
|
|
@ -113,6 +113,7 @@ fi
|
|||
echo "running udev..."
|
||||
export UDEV_CONFIG_FILE=@udevConf@
|
||||
mkdir -p /dev/.udev # !!! bug in udev?
|
||||
mkdir -p /dev/.mdadm
|
||||
udevd --daemon
|
||||
udevadm control --env=STARTUP=1
|
||||
udevadm trigger --action=add
|
||||
|
|
|
@ -213,6 +213,7 @@ let
|
|||
cp ${pkgs.udev}/libexec/rules.d/60-persistent-storage.rules $out/
|
||||
cp ${pkgs.udev}/libexec/rules.d/80-drivers.rules $out/
|
||||
cp ${pkgs.lvm2}/lib/udev/rules.d/*.rules $out/
|
||||
cp ${pkgs.mdadm}/lib/udev/rules.d/*.rules $out/
|
||||
|
||||
for i in $out/*.rules; do
|
||||
substituteInPlace $i \
|
||||
|
@ -225,7 +226,8 @@ let
|
|||
--replace /sbin/blkid ${extraUtils}/bin/blkid \
|
||||
--replace /sbin/modprobe ${extraUtils}/bin/modprobe \
|
||||
--replace '$env{DM_SBIN_PATH}/blkid' ${extraUtils}/bin/blkid \
|
||||
--replace 'ENV{DM_SBIN_PATH}="/sbin"' 'ENV{DM_SBIN_PATH}="${extraUtils}/bin"'
|
||||
--replace 'ENV{DM_SBIN_PATH}="/sbin"' 'ENV{DM_SBIN_PATH}="${extraUtils}/bin"' \
|
||||
--replace /sbin/mdadm ${extraUtils}/bin/mdadm
|
||||
done
|
||||
|
||||
# Remove rule preventing creation of a by-label symlink
|
||||
|
|
|
@ -1,100 +1,11 @@
|
|||
{ config, pkgs, ... }:
|
||||
|
||||
###### implementation
|
||||
|
||||
let
|
||||
|
||||
tempConf = "/var/run/mdadm.conf";
|
||||
tempStatus = "/var/run/mdadm.status";
|
||||
logFile = "/var/log/mdadmEvents.log";
|
||||
modprobe = config.system.sbin.modprobe;
|
||||
inherit (pkgs) mdadm diffutils;
|
||||
|
||||
mdadmEventHandler = pkgs.writeScript "mdadmEventHandler.sh" ''
|
||||
#!/bin/sh
|
||||
|
||||
echo "$@" >> ${logFile}
|
||||
case $1 in
|
||||
(NewArray)
|
||||
initctl emit -n new-raid-array
|
||||
;;
|
||||
(*) ;;
|
||||
esac
|
||||
'';
|
||||
|
||||
in
|
||||
|
||||
{
|
||||
|
||||
jobs.swraid = {
|
||||
startOn = [ "new-raid-array" ];
|
||||
description = "Assemble RAID arrays.";
|
||||
environment.systemPackages = [ pkgs.mdadm ];
|
||||
|
||||
script = ''
|
||||
# Load the necessary RAID personalities.
|
||||
# !!! hm, doesn't the kernel load these automatically?
|
||||
for mod in raid0 raid1 raid5; do
|
||||
${modprobe}/sbin/modprobe $mod || true
|
||||
done
|
||||
services.udev.packages = [ pkgs.mdadm ];
|
||||
|
||||
# Wait until we can fetch the status of mdadm devices.
|
||||
while ! test -e /proc/mdstat; do
|
||||
sleep 10
|
||||
done
|
||||
|
||||
# Scan /proc/partitions for RAID devices.
|
||||
${mdadm}/sbin/mdadm --examine --brief --scan -c partitions > ${tempConf}
|
||||
|
||||
# If there is some array to assemble and if the status has changed.
|
||||
if test -e /proc/mdstat -a -s ${tempConf} &&
|
||||
! ${diffutils}/bin/diff -q /proc/mdstat ${tempStatus} > /dev/null; then
|
||||
|
||||
# Keep the previous status to watch changes.
|
||||
cp ${tempStatus} ${tempStatus}.old
|
||||
|
||||
try=0
|
||||
# Loop until the status change.
|
||||
while ${diffutils}/bin/diff -q ${tempStatus} ${tempStatus}.old > /dev/null; do
|
||||
test "$try" -gt 12 && break
|
||||
test "$try" -ne 0 && sleep 10
|
||||
|
||||
# Activate each device found.
|
||||
${mdadm}/sbin/mdadm --assemble -c ${tempConf} --scan
|
||||
|
||||
# Register the new status
|
||||
cp /proc/mdstat ${tempStatus}
|
||||
|
||||
try=$(($try + 1))
|
||||
done
|
||||
|
||||
if test "$try" -le 6; then
|
||||
# Send notifications.
|
||||
initctl emit -n new-devices
|
||||
fi
|
||||
|
||||
# Remove previous status.
|
||||
rm ${tempStatus}.old
|
||||
fi
|
||||
'';
|
||||
|
||||
task = true;
|
||||
};
|
||||
|
||||
jobs.swraidEvents = {
|
||||
name = "swraid-events";
|
||||
description = "Watch mdadm events.";
|
||||
startOn = [ "startup" ];
|
||||
|
||||
postStart = ''
|
||||
echo > ${tempConf}
|
||||
echo > ${tempStatus}
|
||||
|
||||
# Assemble early raid devices.
|
||||
initctl emit -n new-raid-array
|
||||
'';
|
||||
|
||||
# !!! Someone should ensure that this is indeed doing what the manual says.
|
||||
exec = "${mdadm}/sbin/mdadm --monitor --scan --program ${mdadmEventHandler}";
|
||||
};
|
||||
boot.initrd.availableKernelModules = [ "md_mod" "raid0" "raid1" "raid456" ];
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue