SHA256
1
0
forked from pool/mdadm
mdadm/mkinitrd-setup.sh
Neil Brown 984ab4d563 - mkinitrd-setup.sh: copy new udev rules files into
the initrd.
  The "mkinitrd" package does this for the old name.
  It is easier if this packages does it for the files
  this package installs.
  (bnc#838777)

OBS-URL: https://build.opensuse.org/package/show/Base:System/mdadm?expand=0&rev=90
2013-09-06 04:05:58 +00:00

119 lines
3.0 KiB
Bash

#!/bin/bash
#
#%stage: softraid
#
mdblockdev=
# Full mdadm.conf generated by mdadm.
# Contains all created MD RAIDs
mdadm_conf=
cont_list=
md_devs=
declare -A md_conf
# blockdev contains real devices (/dev/X) for root, resume, journal, dumb
for bd in $blockdev ; do
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=`mdadm -D --export $bd | sed -n -e 's/^MD_DEVNAME=//p'`
if [ -z "$md_dev" ]; then
md_dev=${bd##/dev/}
else
bd="/dev/md/$md_dev"
fi
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
mdconf=$(mdadm -Db "$bd")
if test -z "$mdconf"; then
mdblockdev="$mdblockdev $bd"
continue
fi
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"
cont_list="$cont_list $container"
;;
[0-9a-f]*[0-9a-f])
if test -z "$mdadm_conf"; then
mdadm_conf=$(mdadm --examine --brief --scan)
fi
mdconf="$(echo "$mdadm_conf" | grep "UUID=$container")\\n$mdconf"
cont_list="$cont_list $container"
;;
*)
echo "unrecognized container for $md_dev: $container"
;;
esac
md_conf["$md_dev"]="$mdconf"
root_md=1
done
# Any 'md' device is replaced by it's component disks.
blockdev="$mdblockdev"
if [ -n "$root_md" ] ; then
need_mdadm=1
echo "AUTO -all" > $tmp_mnt/etc/mdadm.conf
for md in $md_devs; do
echo -e "${md_conf["$md"]}" >> $tmp_mnt/etc/mdadm.conf
done
fi
# Remember which arrays are needed for the root or swap device and assemble
# them all during boot. The root= or resume= option might not directly refer to
# the array.
if test -n "$md_devs"; then
md_devs=$(printf '/dev/%s ' $md_devs)
fi
if [ "x$need_mdadm" = "x1" ] ; then
for rule in \
63-md-raid-arrays.rules \
64-md-raid-assembly.rules; do
if [ -f /usr/lib/udev/rules.d/$rule ]; then
cp /usr/lib/udev/rules.d/$rule $tmp_mnt/usr/lib/udev/rules.d
elif [ -f /lib/udev/rules.d/$rule ]; then
cp /lib/udev/rules.d/$rule $tmp_mnt/lib/udev/rules.d
fi
done
fi
save_var need_mdadm
save_var md_devs