]> git.pld-linux.org Git - projects/geninitrd.git/blobdiff - mod-md.sh
no need to mess with magic values, let the "magic" be value
[projects/geninitrd.git] / mod-md.sh
index 925b636cfb083a66068f3ea182d01e6007a941ca..0c06e7285377bc7a32357122c1ad89ad59f778c5 100644 (file)
--- a/mod-md.sh
+++ b/mod-md.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
-#
+MD_RCSID='$Revision$ $Date::                            $'
+
 # geninitrd mod: mdadm
+USE_MD=${USE_MD:-yes}
 
 # if we should init md (softraid) at boot
 have_md=no
@@ -9,9 +11,11 @@ have_md=no
 # @access      public
 setup_mod_md() {
        mdassemble=$(find_tool $initrd_dir/mdassemble /sbin/initrd-mdassemble)
-       if [ -x /sbin/mdadm -a -x "$mdassemble" ]; then
-               USE_MD=yes
-       else
+       if [ ! -x "$mdassemble" ]; then
+               USE_MD=no
+       fi
+       mdadm=$(find_tool /sbin/mdadm $initrd_dir/mdadm /sbin/initrd-mdadm)
+       if [ ! -x "$mdadm" ]; then
                USE_MD=no
        fi
 }
@@ -43,20 +47,32 @@ find_modules_md() {
 
        if [ -f /etc/mdadm.conf ]; then
                debug "Finding RAID details using mdadm for rootdev=$1"
-               eval `(/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf;/sbin/mdadm -v --detail --scan --config=/etc/mdadm.conf) | awk -v rootdev="$1" '
+               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" '
                BEGIN {
                        found = "no";
                        dev_list = "";
                        raidlevel = ""
-                       rootdev_devfs = rootdev;
-                       if (rootdev ~ /\/dev\/md\/[0-9]/) {
-                               gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
+                       rootdev_new = rootdev
+                       rootdev_alias = rootdev;
+                       # alternative name: normalize from /dev/md/X to /dev/mdX
+                       if (rootdev_alias ~ /\/dev\/md\/[0-9]+/) {
+                               gsub(/\/dev\/md\//,"/dev/md",rootdev_alias);
+                       }
+                       # alternative name: normalize from /dev/mdXpY to /dev/mdX
+                       if (rootdev_alias ~/\/dev\/md[0-9]+p[0-9]+/) {
+                               gsub(/p[0-9]+/,"",rootdev_alias);
                        }
                }
 
                /^ARRAY/ {
-                       if (($2 == rootdev) || ($2 == rootdev_devfs)) {
+                       arr_device = $2
+                       # normalize to /dev/mdX form
+                       if (arr_device ~ /\/dev\/md\/[0-9]+/) {
+                               gsub(/\/dev\/md\//,"/dev/md",arr_device);
+                       }
+                       if ((arr_device == rootdev) || (arr_device == rootdev_alias)) {
                                raidlevel=$3;
+                               rootdev_new=arr_device
                                gsub(/level=/,NUL,raidlevel);
                                if (raidlevel ~ /^raid([0-6]|10)/) {
                                        gsub(/raid/,NUL,raidlevel);
@@ -72,6 +88,7 @@ find_modules_md() {
                }
 
                END {
+                       print "rootdev_new=" rootdev_new;
                        print "have_md=" found;
                        print "raidlevel=" raidlevel;
                        print "dev_list=\"" dev_list "\"";
@@ -102,8 +119,10 @@ find_modules_md() {
                die "RAID devices not found for \"$1\", check your configuration!"
        fi
 
+       debug "md: found rootdev=$1 on device $rootdev_new with devices list ${dev_list}"
+
        rootdev_nr=$(( $rootdev_nr + 1 ))
-       eval "rootdev${rootdev_nr}=\"$1\""
+       eval "rootdev${rootdev_nr}=\"$rootdev_new\""
        eval "dev_list${rootdev_nr}=\"${dev_list}\""
 
        for device in $dev_list; do
@@ -115,6 +134,9 @@ find_modules_md() {
 # generate initrd fragment for md
 # @access      public
 initrd_gen_md() {
+       if ! is_yes "$have_md"; then
+               return
+       fi
        debug "Setting up mdadm..."
 
        inst_exec $mdassemble /bin/mdassemble
@@ -122,15 +144,18 @@ initrd_gen_md() {
        # LVM on RAID case
        local dev_list_extra ex_dev
        dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf | xargs)
-       if [ "$dev_list_extra" = "partitions" ]; then
-               # FIXME: handle this case (see man mdadm.conf)
-               echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
-               dev_list_extra=""
-       else
-               for ex_dev in $dev_list_extra; do
-                       echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
-               done
-       fi
+       new_dev_list_extra=""
+       for ex_dev in $dev_list_extra; do
+               if [ "$ex_dev" = "partitions" ]; then
+                       echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
+                       # FIXME: find and copy partition devices from /proc/partitions
+                       #        - best if done at runtime, now initrd gen time
+                       continue
+               fi
+               echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
+               new_dev_list_extra="$new_dev_list_extra $ex_dev"
+       done
+       dev_list_extra=$new_dev_list_extra
 
        local cr_rootdev cr_dev_list do_md0=1 nr cr_dev_list_md f cr_md_conf
        for nr in `seq 1 $rootdev_nr`; do
@@ -142,7 +167,7 @@ initrd_gen_md() {
 
                echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
                cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
-               cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
+               cr_md_conf=$($mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
                if [ -n "$cr_md_conf" ]; then
                        echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
                else
@@ -158,7 +183,13 @@ initrd_gen_md() {
                done
        done
 
-       echo "mdassemble" | add_linuxrc
+       add_linuxrc <<-EOF
+       mdassemble
+
+       if [ "$DEBUGINITRD" ]; then
+               [ -e /proc/mdstat ] && echo "/proc/mdstat contents:" && cat /proc/mdstat
+       fi
+       EOF
 
        # needed to determine md-version
        if [ "$do_md0" -eq 1 ]; then
This page took 0.087493 seconds and 4 git commands to generate.