2008-07-25 02:32:37 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
#%stage: softraid
|
|
|
|
#
|
|
|
|
mdblockdev=
|
|
|
|
|
2010-01-11 15:50:57 +01:00
|
|
|
# Full mdadm.conf generated by mdadm.
|
|
|
|
# Contains all created MD RAIDs
|
2010-03-19 00:31:30 +01:00
|
|
|
mdadm_conf=$(mdadm --examine --brief --scan)
|
2010-01-11 15:50:57 +01:00
|
|
|
|
|
|
|
cont_list=
|
|
|
|
md_devs=
|
|
|
|
|
|
|
|
# blockdev contains real devices (/dev/X) for root, resume, journal, dumb
|
2008-07-25 02:32:37 +02:00
|
|
|
for bd in $blockdev ; do
|
2010-01-11 15:50:57 +01:00
|
|
|
is_part_dev=false
|
|
|
|
case $bd in
|
|
|
|
/dev/md[0-9]*p[0-9]*)
|
|
|
|
# Partitionable MD RAID. This is partition on RAID. Get the RAID
|
|
|
|
bd=${bd%%p[0-9]*}
|
|
|
|
is_part_dev=true
|
|
|
|
;;
|
|
|
|
/dev/md[0-9]*)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
mdblockdev="$mdblockdev $bd"
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
# Check if this device is already added (possible for partitionable).
|
|
|
|
md_dev=${bd##/dev/}
|
|
|
|
dup_found=false
|
|
|
|
for dup in $md_devs; do
|
|
|
|
if [ x"$dup" = x"$md_dev" ]; then
|
|
|
|
dup_found=true
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if $dup_found; then
|
|
|
|
if ! $is_part_dev; then
|
|
|
|
echo "setup-md.sh: $md_dev found multiple times" >&2
|
|
|
|
fi
|
|
|
|
continue
|
|
|
|
fi
|
2010-01-18 14:08:58 +01:00
|
|
|
mdconf=$(mdadm -Db "$bd")
|
|
|
|
if test -z "$mdconf"; then
|
|
|
|
mdblockdev="$mdblockdev $bd"
|
|
|
|
continue
|
2008-07-25 02:32:37 +02:00
|
|
|
fi
|
2010-01-18 14:08:58 +01:00
|
|
|
md_tmpblockdev=$(mdadm -Dbv $bd | sed -n "1D;s/,/ /g;s/^ *devices=//p")
|
|
|
|
mdblockdev="$mdblockdev $md_tmpblockdev"
|
|
|
|
md_devs="$md_devs $md_dev"
|
|
|
|
container=$(echo "$mdconf" | sed -rn 's/.* container=([^ ]*) .*/\1/p')
|
|
|
|
for cnt in $cont_list; do
|
|
|
|
if [ x"$container"= x"$cnt" ]; then
|
|
|
|
container=
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
case "$container" in
|
|
|
|
"")
|
|
|
|
;;
|
|
|
|
/dev/*)
|
|
|
|
mdconf="$(mdadm -Db "$container")\\n$mdconf"
|
|
|
|
;;
|
|
|
|
[0-9a-f]*[0-9a-f])
|
2010-03-19 00:31:30 +01:00
|
|
|
mdconf="$(mdadm -Ebs | grep "UUID=$container")\\n$mdconf"
|
2010-01-18 14:08:58 +01:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unrecognized container for $md_dev: $container"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
eval md_conf_${md_dev}=\"$mdconf\"
|
|
|
|
root_md=1
|
2008-07-25 02:32:37 +02:00
|
|
|
done
|
|
|
|
|
2010-01-11 15:50:57 +01:00
|
|
|
# Any 'md' device is replaced by it's component disks.
|
2008-07-25 02:32:37 +02:00
|
|
|
blockdev="$mdblockdev"
|
|
|
|
|
|
|
|
if [ -n "$root_md" ] ; then
|
|
|
|
need_mdadm=1
|
2010-01-11 15:50:57 +01:00
|
|
|
echo -n "" > $tmp_mnt/etc/mdadm.conf
|
2008-07-25 02:32:37 +02:00
|
|
|
for md in $md_devs; do
|
2010-01-11 15:50:57 +01:00
|
|
|
eval echo -e \"\$md_conf_$md\" >> $tmp_mnt/etc/mdadm.conf
|
2008-07-25 02:32:37 +02:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
save_var need_mdadm
|
|
|
|
save_var root_md
|