]> git.pld-linux.org Git - projects/geninitrd.git/commitdiff
Detect broken tool (lvdisplay) and fail early instead of generating invalid initrd
authorElan Ruusamäe <glen@pld-linux.org>
Mon, 22 May 2006 14:11:32 +0000 (14:11 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Mon, 22 May 2006 14:11:32 +0000 (14:11 +0000)
svn-id: @7430

geninitrd

index a44a1331ad793a3a6559d7147748563fc8629ccb..7200d3f7861081a942644bc2855d7353a17e0717 100755 (executable)
--- a/geninitrd
+++ b/geninitrd
@@ -506,6 +506,39 @@ END {
        fi
 }
 
+# return true if node is lvm node
+_check_lvm() {
+       local node="$1"
+       if [ ! -e "$node" ]; then
+               return 1
+       fi
+
+       # block-major-58 is lvm1
+       ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
+       rc=$?
+
+       if [ $rc = 0 ]; then
+               [ -n "$verbose" ] && echo "$node is LVM1 node"
+               # is lvm1
+               return 0
+       fi
+
+       /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
+       rc=$?
+       if [ $rc -gt 127 ]; then
+               # lvdisplay terminated by signal! most likely it segfaulted.
+               echo >&2 "ERROR: Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
+               exit 1
+       fi
+
+       if [ $rc = 0 ]; then
+               [ -n "$verbose" ] && echo "$node is lvm2 node"
+       else
+               [ -n "$verbose" ] && echo "$node is not any lvm node"
+       fi
+       return $rc
+}
+
 find_modules_for() {
         if [ -z "$1" ]; then
                echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
@@ -574,8 +607,7 @@ find_modules_for() {
                BASICMODULES="$BASICMODULES -loop"
                findmodule "-$loopFs"
                BASICMODULES="$BASICMODULES -${loopFs}"
-               # don't have any clue, how is this supposed to work
-       elif [ -e "$1" ] && ls -l "$1" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}' || /sbin/lvm lvdisplay "$1" > /dev/null 2>&1 ; then
+       elif _check_lvm "$1"; then
                if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
                        echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
                        echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
@@ -611,6 +643,7 @@ find_modules_for() {
                        echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
                        exit 1
                fi
+               [ -n "$verbose" ] && echo "LVM $LVMTOOLSVERSION enabled"
                uselvm="yes"
        fi
 }
This page took 0.040424 seconds and 4 git commands to generate.