geninitrd/trunk/geninitrd

glen cvs at pld-linux.org
Mon May 22 16:11:36 CEST 2006


Author: glen
Date: Mon May 22 16:11:32 2006
New Revision: 7430

Modified:
   geninitrd/trunk/geninitrd
Log:
Detect broken tool (lvdisplay) and fail early instead of generating invalid initrd

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Mon May 22 16:11:32 2006
@@ -506,6 +506,39 @@
 	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 @@
 		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 @@
 			echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
 			exit 1
 		fi
+		[ -n "$verbose" ] && echo "LVM $LVMTOOLSVERSION enabled"
 		uselvm="yes"
 	fi
 }


More information about the pld-cvs-commit mailing list