5 # if we should init md (softraid) at boot
8 # setup geninitrd module
11 mdassemble=$(find_tool $initrd_dir/mdassemble /sbin/initrd-mdassemble)
12 if [ -x /sbin/mdadm -a -x "$mdassemble" ]; then
19 # return true if mdadm is set on $devpath
20 # @param string $devpath device node to be examined
26 if ! is_yes "$USE_MD"; then
30 if [[ "$devpath" == /dev/md* ]]; then
37 # find md modules for $devpath
38 # @param $devpath device to be examined
39 # @return false if $devpath is not on md
44 if [ -f /etc/mdadm.conf ]; then
45 debug "Finding RAID details using mdadm for rootdev=$1"
46 eval `(/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf;/sbin/mdadm -v --detail --scan --config=/etc/mdadm.conf) | awk -v rootdev="$1" '
51 rootdev_devfs = rootdev;
52 if (rootdev ~ /\/dev\/md\/[0-9]/) {
53 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
58 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
60 gsub(/level=/,NUL,raidlevel);
61 if (raidlevel ~ /^raid([0-6]|10)/) {
62 gsub(/raid/,NUL,raidlevel);
68 gsub(".*devices=", NUL, dev_list);
69 gsub(",", " ", dev_list);
75 print "have_md=" found;
76 print "raidlevel=" raidlevel;
77 print "dev_list=\"" dev_list "\"";
81 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
82 die "raidtools are not longer supported. Please migrate to mdadm setup!"
85 if is_yes "$have_md"; then
88 find_module "raid$raidlevel"
91 find_module "-raid$raidlevel"
92 find_module "-raid456"
98 warn "raid level $number (in mdadm config) not recognized"
102 die "RAID devices not found for \"$1\", check your configuration!"
105 rootdev_nr=$(( $rootdev_nr + 1 ))
106 eval "rootdev${rootdev_nr}=\"$1\""
107 eval "dev_list${rootdev_nr}=\"${dev_list}\""
109 for device in $dev_list; do
110 find_modules_for_devpath $device
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