5 # if we should init md (softraid) at boot
8 mdassemble=$(find_tool $initrd_dir/mdassemble /sbin/initrd-mdassemble)
9 if [ -x /sbin/mdadm -a -x $mdassemble ]; then
15 # XXX wtf is this for?
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;/sbin/mdadm -v --detail --scan --config=/etc/mdadm.conf) | 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
114 # generate initrd fragment for md
117 debug "Setting up mdadm..."
119 inst_exec $mdassemble /bin/mdassemble
122 local dev_list_extra ex_dev
123 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
124 if [ "$dev_list_extra" = "partitions" ]; then
125 # FIXME: handle this case (see man mdadm.conf)
126 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
129 for ex_dev in $dev_list_extra; do
130 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
134 local cr_rootdev cr_dev_list do_md0=1 nr cr_dev_list_md f cr_md_conf
135 for nr in `seq 1 $rootdev_nr`; do
136 eval cr_rootdev="\$rootdev${nr}"
137 eval cr_dev_list="\$dev_list${nr}"
138 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
140 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
142 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
143 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
144 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
145 if [ -n "$cr_md_conf" ]; then
146 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
148 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
151 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
152 # mkdir in case of devfs name
154 [ -e "$DESTDIR/$f" ] && continue
155 # this works fine with and without devfs
160 echo "mdassemble" | add_linuxrc
162 # needed to determine md-version
163 if [ "$do_md0" -eq 1 ]; then
164 mknod $DESTDIR/dev/md0 b 9 0