mdadm/mkinitrd-setup.sh
Michal Marek b3e37df068 Accepting request 29126 from home:michal-m:branches:Base:System
Copy from home:michal-m:branches:Base:System/mdadm via accept of submit request 29126 revision 2.
Request was accepted with message:
Reviewed ok

OBS-URL: https://build.opensuse.org/request/show/29126
OBS-URL: https://build.opensuse.org/package/show/Base:System/mdadm?expand=0&rev=10
2010-01-11 14:06:42 +00:00

101 lines
2.6 KiB
Bash

#!/bin/bash
#
#%stage: softraid
#
mdblockdev=
# Full mdadm.conf generated by mdadm.
# Contains all created MD RAIDs
mdadm_conf=$(mdadm --examine --brief --scan)
cont_list=
md_devs=
# blockdev contains real devices (/dev/X) for root, resume, journal, dumb
echo "blockdev: $blockdev"
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=${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
# Get UUID of block device
tmp_uuid=$(mdadm -D $bd --export 2>/dev/null | grep UUID=)
if [ -n "$tmp_uuid" ]; then
md_tmpblockdev=$(mdadm -Dbv $bd 2> /dev/null | sed -n "1D;s/,/ /g;s/^ *devices=\(.*\)/\1/p")
uuid=${tmp_uuid##MD_}
# Get the corresponding line from config
arr_line=$(echo "$mdadm_conf" | grep "$uuid")
if test -z "$arr_line"; then
continue
fi
# Check for container
cont_line=
cont=$(echo "$arr_line" | sed -n "s/.*container=\([0-9a-z]\{8\}:[0-9a-z]\{8\}:[0-9a-z]\{8\}:[0-9a-z]\{8\}\).*/\1/p")
if [ -n "$cont" ]; then
cnt_dup=0
for cnt in $cont_list; do
if [ x"$cont"= x"$cnt" ]; then
cnt_dup=1
fi
done
if [ $cnt_dup -eq 0 ]; then
cont_list="$cont_list $cont"
cont_line=$(echo "$mdadm_conf" | grep "UUID=$cont")
cont_line="$cont_line\n"
fi
fi
# add a line with the "real" md device name so that boot-md.sh finds it
cfg_dev=$(echo "$arr_line" | sed -rn 's/^ARRAY +([^ ]*).*/\1/p; T; q')
real_dev=$(readlink -f "$cfg_dev")
if test -n "$real_dev" -a "$real_dev" != "$cfg_dev"; then
arr_line="$arr_line$(echo -e "\\n$arr_line" | \
sed -r "s:^(ARRAY +)$cfg_dev:\\1$real_dev:")"
fi
mdblockdev="$mdblockdev $md_tmpblockdev"
# Add ARRAY line (with container line before if needed).
cfg_line=$(echo -e "$cont_line$arr_line")
eval md_conf_${md_dev}=\""$cfg_line"\"
md_devs="$md_devs $md_dev"
root_md=1
fi
done
# Any 'md' device is replaced by it's component disks.
blockdev="$mdblockdev"
if [ -n "$root_md" ] ; then
need_mdadm=1
echo -n "" > $tmp_mnt/etc/mdadm.conf
for md in $md_devs; do
eval echo -e \"\$md_conf_$md\" >> $tmp_mnt/etc/mdadm.conf
done
fi
save_var need_mdadm
save_var root_md