6 # if we should init md (softraid) at boot
9 # setup geninitrd module
12 mdassemble=$(find_tool $initrd_dir/mdassemble /sbin/initrd-mdassemble)
13 if [ ! -x /sbin/mdadm ] || [ ! -x "$mdassemble" ]; then
18 # return true if mdadm is set on $devpath
19 # @param string $devpath device node to be examined
25 if ! is_yes "$USE_MD"; then
29 if [[ "$devpath" == /dev/md* ]]; then
36 # find md modules for $devpath
37 # @param $devpath device to be examined
38 # @return false if $devpath is not on md
43 if [ -f /etc/mdadm.conf ]; then
44 debug "Finding RAID details using mdadm for rootdev=$1"
45 eval `(/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf 2> /dev/null;/sbin/mdadm -v --detail --scan --config=/etc/mdadm.conf 2> /dev/null) | awk -v rootdev="$1" '
50 rootdev_devfs = rootdev;
51 if (rootdev ~ /\/dev\/md\/[0-9]/) {
52 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
57 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
59 gsub(/level=/,NUL,raidlevel);
60 if (raidlevel ~ /^raid([0-6]|10)/) {
61 gsub(/raid/,NUL,raidlevel);
67 gsub(".*devices=", NUL, dev_list);
68 gsub(",", " ", dev_list);
74 print "have_md=" found;
75 print "raidlevel=" raidlevel;
76 print "dev_list=\"" dev_list "\"";
80 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
81 die "raidtools are not longer supported. Please migrate to mdadm setup!"
84 if is_yes "$have_md"; then
87 find_module "raid$raidlevel"
90 find_module "-raid$raidlevel"
91 find_module "-raid456"
97 warn "raid level $number (in mdadm config) not recognized"
101 die "RAID devices not found for \"$1\", check your configuration!"
104 rootdev_nr=$(( $rootdev_nr + 1 ))
105 eval "rootdev${rootdev_nr}=\"$1\""
106 eval "dev_list${rootdev_nr}=\"${dev_list}\""
108 for device in $dev_list; do
109 find_modules_for_devpath $device
111 debug "md: found rootdev=$1 with devices list ${dev_list}"
115 # generate initrd fragment for md
118 debug "Setting up mdadm..."
120 inst_exec $mdassemble /bin/mdassemble
123 local dev_list_extra ex_dev
124 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
125 if [ "$dev_list_extra" = "partitions" ]; then
126 # FIXME: handle this case (see man mdadm.conf)
127 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
130 for ex_dev in $dev_list_extra; do
131 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
135 local cr_rootdev cr_dev_list do_md0=1 nr cr_dev_list_md f cr_md_conf
136 for nr in `seq 1 $rootdev_nr`; do
137 eval cr_rootdev="\$rootdev${nr}"
138 eval cr_dev_list="\$dev_list${nr}"
139 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
141 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
143 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
144 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
145 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
146 if [ -n "$cr_md_conf" ]; then
147 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
149 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
152 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
153 # mkdir in case of devfs name
155 [ -e "$DESTDIR/$f" ] && continue
156 # this works fine with and without devfs
161 echo "mdassemble" | add_linuxrc
163 # needed to determine md-version
164 if [ "$do_md0" -eq 1 ]; then
165 mknod $DESTDIR/dev/md0 b 9 0