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 "$mdassemble" ]; then
16 mdadm=$(find_tool /sbin/mdadm $initrd_dir/mdadm /sbin/initrd-mdadm)
17 if [ ! -x "$mdadm" ]; then
22 # return true if mdadm is set on $devpath
23 # @param string $devpath device node to be examined
29 if ! is_yes "$USE_MD"; then
33 if [[ "$devpath" == /dev/md* ]]; then
40 # find md modules for $devpath
41 # @param $devpath device to be examined
42 # @return false if $devpath is not on md
47 if [ -f /etc/mdadm.conf ]; then
48 debug "Finding RAID details using mdadm for rootdev=$1"
49 eval `($mdadm -v --examine --scan --config=/etc/mdadm.conf 2> /dev/null;$mdadm -v --detail --scan --config=/etc/mdadm.conf 2> /dev/null) | awk -v rootdev="$1" '
54 rootdev_devfs = rootdev;
55 if (rootdev ~ /\/dev\/md\/[0-9]/) {
56 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
61 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
63 gsub(/level=/,NUL,raidlevel);
64 if (raidlevel ~ /^raid([0-6]|10)/) {
65 gsub(/raid/,NUL,raidlevel);
71 gsub(".*devices=", NUL, dev_list);
72 gsub(",", " ", dev_list);
78 print "have_md=" found;
79 print "raidlevel=" raidlevel;
80 print "dev_list=\"" dev_list "\"";
84 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
85 die "raidtools are not longer supported. Please migrate to mdadm setup!"
88 if is_yes "$have_md"; then
91 find_module "raid$raidlevel"
94 find_module "-raid$raidlevel"
95 find_module "-raid456"
101 warn "raid level $number (in mdadm config) not recognized"
105 die "RAID devices not found for \"$1\", check your configuration!"
108 debug "md: found rootdev=$1 with devices list ${dev_list}"
110 rootdev_nr=$(( $rootdev_nr + 1 ))
111 eval "rootdev${rootdev_nr}=\"$1\""
112 eval "dev_list${rootdev_nr}=\"${dev_list}\""
114 for device in $dev_list; do
115 find_modules_for_devpath $device
120 # generate initrd fragment for md
123 debug "Setting up mdadm..."
125 inst_exec $mdassemble /bin/mdassemble
128 local dev_list_extra ex_dev
129 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
130 if [ "$dev_list_extra" = "partitions" ]; then
131 # FIXME: handle this case (see man mdadm.conf)
132 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
135 for ex_dev in $dev_list_extra; do
136 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
140 local cr_rootdev cr_dev_list do_md0=1 nr cr_dev_list_md f cr_md_conf
141 for nr in `seq 1 $rootdev_nr`; do
142 eval cr_rootdev="\$rootdev${nr}"
143 eval cr_dev_list="\$dev_list${nr}"
144 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
146 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
148 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
149 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
150 cr_md_conf=$($mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
151 if [ -n "$cr_md_conf" ]; then
152 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
154 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
157 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
158 # mkdir in case of devfs name
160 [ -e "$DESTDIR/$f" ] && continue
161 # this works fine with and without devfs
166 echo "mdassemble" | add_linuxrc
168 # needed to determine md-version
169 if [ "$do_md0" -eq 1 ]; then
170 mknod $DESTDIR/dev/md0 b 9 0