2008-07-25 02:32:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#%stage: softraid
|
2011-10-06 04:24:11 +02:00
|
|
|
# grep needed for udev rules file.
|
2009-12-16 09:01:21 +01:00
|
|
|
#%programs: /sbin/mdadm /sbin/mdmon
|
2010-01-11 15:50:57 +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
|
|
|
|
##
|
|
|
|
|
|
|
|
# load the necessary module before we initialize the raid system
|
|
|
|
load_modules
|
|
|
|
|
2012-05-09 03:23:18 +02:00
|
|
|
# Create dir for socket and pid files
|
|
|
|
mkdir -p /run/mdadm
|
2008-07-25 02:32:37 +02:00
|
|
|
[ "$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-06-28 11:44:27 +02:00
|
|
|
if test -n "$debug_linuxrc"; then
|
|
|
|
mdadm="mdadm -v"
|
|
|
|
else
|
|
|
|
mdadm="mdadm"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# uuid -> array name
|
|
|
|
get_md_name()
|
|
|
|
{
|
|
|
|
local uuid=$1 res
|
|
|
|
|
|
|
|
if ! test -f /etc/mdadm.conf; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
res=$(sed -rn "s/^ARRAY +([^ ]+).* UUID=$uuid.*/\1/p" /etc/mdadm.conf)
|
|
|
|
case "$res" in
|
|
|
|
"" | \<* | *=*)
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
/*)
|
|
|
|
echo "$res"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "/dev/md/$res"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2010-01-11 15:50:57 +01:00
|
|
|
md_assemble()
|
|
|
|
{
|
2010-06-28 11:44:27 +02:00
|
|
|
local dev=$1 uuid mdconf container container_name
|
2010-01-11 15:50:57 +01:00
|
|
|
|
2010-03-26 01:36:15 +01:00
|
|
|
if test -e "$dev"; then
|
|
|
|
return
|
|
|
|
fi
|
2010-01-11 15:50:57 +01:00
|
|
|
case "$dev" in
|
|
|
|
/dev/md[0-9]*p[0-9]*)
|
|
|
|
dev=${dev%p[0-9]*}
|
2010-06-28 11:44:27 +02:00
|
|
|
;;
|
|
|
|
/dev/md*)
|
|
|
|
;;
|
|
|
|
/dev/disk/by-id/md-uuid-*)
|
|
|
|
uuid=${dev#/dev/disk/by-id/md-uuid-}
|
|
|
|
uuid=${uuid%-part*}
|
|
|
|
dev=
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
return
|
2010-01-11 15:50:57 +01:00
|
|
|
esac
|
|
|
|
if test -f /etc/mdadm.conf; then
|
|
|
|
mdconf="-c /etc/mdadm.conf"
|
2010-06-28 11:44:27 +02:00
|
|
|
local line
|
|
|
|
if test -n "$dev"; then
|
|
|
|
line=$(sed -rn "\:^ARRAY +$dev :p" /etc/mdadm.conf)
|
|
|
|
else
|
|
|
|
line=$(sed -rn "/^ARRAY .* UUID=$uuid/p" /etc/mdadm.conf)
|
|
|
|
fi
|
|
|
|
container=$(echo "$line" | \
|
|
|
|
sed -rn 's/.* container=([^ ]*).*/\1/p')
|
2010-01-11 15:50:57 +01:00
|
|
|
else
|
|
|
|
mdconf="-c partitions"
|
|
|
|
fi
|
2010-01-18 14:08:58 +01:00
|
|
|
case "$container" in
|
|
|
|
"")
|
|
|
|
;;
|
|
|
|
/dev/*)
|
2010-06-28 11:44:27 +02:00
|
|
|
$mdadm -A $mdconf $container
|
2010-01-18 14:08:58 +01:00
|
|
|
;;
|
|
|
|
[0-9a-f]*[0-9a-f])
|
2010-06-28 11:44:27 +02:00
|
|
|
container_name=$(get_md_name "$container")
|
|
|
|
if test -z "$container_name"; then
|
|
|
|
container_name=/dev/md/container
|
|
|
|
fi
|
|
|
|
$mdadm -A $mdconf --uuid="$container" "$container_name"
|
2010-01-18 14:08:58 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unrecognized container for $dev: $container"
|
|
|
|
esac
|
2010-06-28 11:44:27 +02:00
|
|
|
if test -n "$dev"; then
|
|
|
|
$mdadm -A $mdconf "$dev"
|
|
|
|
else
|
|
|
|
dev=$(get_md_name "$uuid")
|
|
|
|
if test -z "$dev"; then
|
2011-03-01 23:16:38 +01:00
|
|
|
# mdadm will pick a device name
|
|
|
|
$mdadm -A $mdconf --uuid=$uuid
|
|
|
|
else
|
|
|
|
$mdadm -A $mdconf --uuid=$uuid "$dev"
|
2010-06-28 11:44:27 +02:00
|
|
|
fi
|
|
|
|
fi
|
2010-01-11 15:50:57 +01:00
|
|
|
}
|
|
|
|
|
2010-06-28 11:44:27 +02:00
|
|
|
md_assemble "$resumedev"
|
|
|
|
md_assemble "$rootdev"
|
|
|
|
if [ -n "$md_dev" ] ; then
|
|
|
|
md_assemble "$md_dev"
|
2008-07-25 02:32:37 +02:00
|
|
|
fi
|
2010-06-28 11:44:27 +02:00
|
|
|
# assemble any md devices seen by setup-md.sh at initrd build time
|
|
|
|
for dev in $md_devs; do
|
|
|
|
md_assemble "$dev"
|
|
|
|
done
|
|
|
|
|
|
|
|
wait_for_events
|