2008-07-25 02:32:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#%stage: softraid
|
2009-12-16 09:01:21 +01:00
|
|
|
#%programs: /sbin/mdadm /sbin/mdmon
|
2010-01-11 15:06:42 +01:00
|
|
|
#%modules: raid0 raid1 raid10 raid456
|
2008-07-25 02:32:37 +02:00
|
|
|
#%if: -n "$need_mdadm"
|
|
|
|
#
|
|
|
|
##### MD (Software-)Raid
|
|
|
|
##
|
|
|
|
## This activates and waits for an MD software raid.
|
|
|
|
##
|
|
|
|
## Command line parameters
|
|
|
|
## -----------------------
|
|
|
|
##
|
|
|
|
## need_mdadm=1 use MD raid
|
|
|
|
## md_uuid the uuid of the raid to activate
|
|
|
|
##
|
|
|
|
|
|
|
|
# load the necessary module before we initialize the raid system
|
|
|
|
load_modules
|
|
|
|
|
|
|
|
[ "$mduuid" ] && md_uuid="$mduuid"
|
|
|
|
|
|
|
|
md_major=$(sed -ne 's/\s*\([0-9]\+\)\s*md$/\1/p' /proc/devices)
|
|
|
|
if [ -n "$md_major" -a "$md_major" = "$maj" ]; then
|
|
|
|
md_minor="$min"
|
|
|
|
md_dev="/dev/md$md_minor"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Always start md devices read/only. They will get set to rw as soon
|
|
|
|
# as the first write occurs. This way we can guarantee that no
|
|
|
|
# restore occurs before resume.
|
|
|
|
if [ -f /sys/module/md_mod/parameters/start_ro ]; then
|
|
|
|
echo 1 > /sys/module/md_mod/parameters/start_ro
|
|
|
|
fi
|
|
|
|
|
2010-01-11 15:06:42 +01:00
|
|
|
md_assemble()
|
|
|
|
{
|
|
|
|
local dev=$1 mdconf container
|
|
|
|
|
|
|
|
case "$dev" in
|
|
|
|
/dev/md[0-9]*p[0-9]*)
|
|
|
|
dev=${dev%p[0-9]*}
|
|
|
|
esac
|
|
|
|
if test -f /etc/mdadm.conf; then
|
|
|
|
mdconf="-c /etc/mdadm.conf"
|
|
|
|
container=$( \
|
|
|
|
sed -rn "s:^ARRAY +$dev .*container=([^ ]*).*:\\1:p" \
|
|
|
|
/etc/mdadm.conf)
|
|
|
|
else
|
|
|
|
mdconf="-c partitions"
|
|
|
|
fi
|
|
|
|
if test -n "$container"; then
|
|
|
|
mdadm -A $mdconf --uuid="$container" /dev/md/container
|
2008-07-25 02:32:37 +02:00
|
|
|
fi
|
2010-01-11 15:06:42 +01:00
|
|
|
mdadm -A $mdconf $mdarg "$dev"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "$need_mdadm" ]; then
|
2008-07-25 02:32:37 +02:00
|
|
|
|
|
|
|
if [ -n "$md_uuid" ] ; then
|
|
|
|
mdarg="--uuid=$md_uuid"
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $resumedev in
|
2010-01-11 15:06:42 +01:00
|
|
|
/dev/md*)
|
|
|
|
md_assemble "$resumedev"
|
2008-07-25 02:32:37 +02:00
|
|
|
esac
|
|
|
|
|
2010-01-11 15:06:42 +01:00
|
|
|
if [ -n "$md_dev" ] ; then
|
|
|
|
md_assemble "$md_dev"
|
2008-07-25 02:32:37 +02:00
|
|
|
fi
|
2008-12-05 16:04:23 +01:00
|
|
|
wait_for_events
|
2008-07-25 02:32:37 +02:00
|
|
|
fi
|