mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-09-22 13:08:39 +03:00
Fix swraid device detection on boot.
svn path=/nixos/trunk/; revision=21661
This commit is contained in:
parent
c1f7622512
commit
43fcf8a2b2
@ -5,6 +5,7 @@
|
|||||||
let
|
let
|
||||||
|
|
||||||
tempConf = "/var/run/mdadm.conf";
|
tempConf = "/var/run/mdadm.conf";
|
||||||
|
tempStatus = "/var/run/mdadm.status";
|
||||||
logFile = "/var/log/mdadmEvents.log";
|
logFile = "/var/log/mdadmEvents.log";
|
||||||
modprobe = config.system.sbin.modprobe;
|
modprobe = config.system.sbin.modprobe;
|
||||||
inherit (pkgs) mdadm diffutils;
|
inherit (pkgs) mdadm diffutils;
|
||||||
@ -36,22 +37,43 @@ in
|
|||||||
${modprobe}/sbin/modprobe $mod || true
|
${modprobe}/sbin/modprobe $mod || true
|
||||||
done
|
done
|
||||||
|
|
||||||
# Save previous probe
|
# Wait until we can fetch the status of mdadm devices.
|
||||||
mv ${tempConf} ${tempConf}.old
|
while ! test -e /proc/mdstat; do
|
||||||
|
sleep 10
|
||||||
|
done
|
||||||
|
|
||||||
# Scan /proc/partitions for RAID devices.
|
# Scan /proc/partitions for RAID devices.
|
||||||
${mdadm}/sbin/mdadm --examine --brief --scan -c partitions > ${tempConf}
|
${mdadm}/sbin/mdadm --examine --brief --scan -c partitions > ${tempConf}
|
||||||
|
|
||||||
if ! ${diffutils}/bin/diff ${tempConf} ${tempConf}.old > /dev/null; then
|
# If the status has changed.
|
||||||
# Activate each device found.
|
if ! ${diffutils}/bin/diff -q /proc/mdstat ${tempStatus} > /dev/null; then
|
||||||
${mdadm}/sbin/mdadm --assemble -c ${tempConf} --scan
|
|
||||||
|
|
||||||
# Send notifications.
|
# Keep the previous status to watch changes.
|
||||||
initctl emit -n new-devices
|
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
|
fi
|
||||||
|
|
||||||
# Remove previous configuration.
|
|
||||||
rm ${tempConf}.old
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
task = true;
|
task = true;
|
||||||
@ -64,6 +86,7 @@ in
|
|||||||
|
|
||||||
postStart = ''
|
postStart = ''
|
||||||
echo > ${tempConf}
|
echo > ${tempConf}
|
||||||
|
echo > ${tempStatus}
|
||||||
|
|
||||||
# Assemble early raid devices.
|
# Assemble early raid devices.
|
||||||
initctl emit -n new-raid-array
|
initctl emit -n new-raid-array
|
||||||
|
Loading…
Reference in New Issue
Block a user