SVN: geninitrd/trunk/geninitrd

glen glen at pld-linux.org
Wed Feb 7 11:51:26 CET 2007


Author: glen
Date: Wed Feb  7 11:51:26 2007
New Revision: 8235

Modified:
   geninitrd/trunk/geninitrd
Log:
- use only blkid to resolve UUID and LABEL, so now it works with any fs not just xfs,ext{2,3}
- cleanup find_root() function

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Wed Feb  7 11:51:26 2007
@@ -43,6 +43,8 @@
 insmod="insmod"
 modext=".o"
 rootdev_nr=0
+# device node for rootfs from fstab
+rootdev=""
 # default bootsplash is off, if it have to be on, install bootsplash package
 BOOT_SPLASH=no
 # default same as bootsplash, if on install splashutils and some splashutils theme
@@ -219,157 +221,51 @@
 	cp "$1" "$2"
 }
 
-get_label_ext2 () {
-	/sbin/e2label $1 2> /dev/null
-}
-
-get_uuid_ext2 () {
-	/sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
-}
-
-get_label_xfs () {
-	/usr/sbin/xfs_admin -l "$1"  2>/dev/null | awk -F'"' '/label =/{print $2}'
-}
-
-get_uuid_xfs () {
-	/usr/sbin/xfs_admin -u "$1" 2>/dev/null | awk -F= '{print $2}' | xargs
-}
-
+# sets globals:
+# - $rootdev
+# - $rootFS
 find_root() {
-	eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
+	eval $(awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab)
+	if [ -z "$rootdev" ]; then
+		echo >&2 "geninitrd can't find real device for rootfs"
+		exit 1
+	fi
+
 	case $rootdev in
 	LABEL=*)
-		# new way, using blkid
-		if [ -x /sbin/blkid ]; then
-			label=${rootdev#"LABEL="}
-			dev=$(/sbin/blkid -t LABEL="$label" -o device)
-
-			if [ "$dev" -a -r "$dev" ]; then
-				debug "Using $dev as device for rootfs"
-				rootdev=$dev
-				rootdev_found=1
-				rootdev1=${rootdev} # XXX neccessary?
-				return
-			fi
-			echo >&2 "geninitrd can't find real device for LABEL=$label"
+		if [ ! -x /sbin/blkid ]; then
+			echo >&2 "/sbin/blkid is missing"
 			exit 1
 		fi
 
-		# old way, using various tools
-		if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
-			rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
-			if [ -n "$rootdev2" ] ; then
-				rootdev=$rootdev2
-				rootdev_found=1
-			fi
-		fi
-		if [ "$rootdev_found." != "1." ] ; then
-			case $rootFs in
-			ext2|ext3)
-				if [ ! -x /sbin/e2label ] ; then
-					echo >&2 "/sbin/e2label is missing"
-					exit 1
-				fi
-				get_label="get_label_ext2"
-				;;
-			xfs)
-				if [ ! -x /usr/sbin/xfs_db ] ; then
-					echo >&2 "/usr/sbin/xfs_db is missing"
-					exit 1
-				fi
-				get_label="get_label_xfs"
-				;;
-			*)
-				echo >&2 "LABEL on $rootFs in not supported by geninitrd"
-				exit 1
-				;;
-			esac
-			if [ ! -r /proc/partitions ] ; then
-				echo >&2 '/proc/partitions is not readable'
-				exit 1
-			fi
-			label=${rootdev#"LABEL="}
-			for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
-				if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
-					debug "Using $dev as device for rootfs"
-					rootdev=$dev
-					rootdev_found=1
-					break
-				fi
-			done
-			if [ "$rootdev_found." != "1." ] ; then
-				echo >&2 "geninitrd can't find real device for LABEL=$label"
-				exit 1
-			fi
+		local label=${rootdev#"LABEL="}
+		local dev=$(/sbin/blkid -t LABEL="$label" -o device)
+		if [ "$dev" -a -r "$dev" ]; then
+			debug "Using $dev as device for rootfs"
+			rootdev=$dev
 		fi
 		;;
+
 	UUID=*)
-		# new way, using blkid
-		if [ -x /sbin/blkid ]; then
-			uuid=${rootdev#"UUID="}
-			dev=$(/sbin/blkid -t UUID="$uuid" -o device)
-
-			if [ "$dev" -a -r "$dev" ]; then
-				debug "Using $dev as device for rootfs"
-				rootdev=$dev
-				rootdev_found=1
-				rootdev1=${rootdev} # XXX neccessary?
-				return
-			fi
-			echo >&2 "geninitrd can't find real device for UUID=$uuid"
+		if [ ! -x /sbin/blkid ]; then
+			echo >&2 "/sbin/blkid is missing"
 			exit 1
 		fi
 
-		# old way, using various tools
-		if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
-			rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
-			if [ -n "$rootdev2" ] ; then
-				rootdev=$rootdev2
-				rootdev_found=1
-			fi
-		fi
-		if [ "$rootdev_found." != "1." ] ; then
-			case $rootFs in
-			ext2|ext3)
-				if [ ! -x /sbin/tune2fs ] ; then
-					echo >&2 "/sbin/tune2fs is missing"
-					exit 1
-				fi
-				get_uuid="get_uuid_ext2"
-				;;
-			xfs)
-				if [ ! -x /usr/sbin/xfs_admin ] ; then
-					echo >&2 "/usr/sbin/xfs_admin is missing"
-					exit 1
-				fi
-				get_uuid="get_uuid_xfs"
-				;;
-			*)
-				echo >&2 "UUID on $rootFs in not supported by geninitrd"
-				exit 1
-				;;
-			esac
-			if [ ! -r /proc/partitions ] ; then
-				echo >&2 '/proc/partitions is not readable'
-				exit 1
-			fi
-			uuid=${rootdev#"UUID="}
-			for dev in $(awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions); do
-				if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
-					debug "Using $dev as device for rootfs"
-					rootdev=$dev
-					rootdev_found=1
-					break
-				fi
-			done
-			if [ "$rootdev_found" != 1 ] ; then
-				echo >&2 "geninitrd can't find real device for UUID=$uuid"
-				exit 1
-			fi
+		local uuid=${rootdev#"UUID="}
+		local dev=$(/sbin/blkid -t UUID="$uuid" -o device)
+
+		if [ "$dev" -a -r "$dev" ]; then
+			debug "Using $dev as device for rootfs"
+			rootdev=$dev
 		fi
 		;;
 	esac
-	rootdev1=${rootdev}
+
+	if [ ! -r "$rootdev" ]; then
+		echo >&2 "geninitrd can't find real device for $rootdev"
+		exit 1
+	fi
 }
 
 find_modules_softraid() {
@@ -1096,9 +992,9 @@
 
 find_root
 
-org_rootdev="$rootdev1"
+org_rootdev="$rootdev"
 
-find_modules_for "$rootdev1"
+find_modules_for "$rootdev"
 
 findmodule "-$rootFs"
 
@@ -1179,11 +1075,11 @@
 #	fi
 #
 #	cp -a "$loopDev" "$MNTIMAGE/dev"
-#	cp -a "$rootdev1" "$MNTIMAGE/dev"
+#	cp -a "$rootdev" "$MNTIMAGE/dev"
 #	echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
 #	echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
-#	echo "echo Setting up loopback device $rootdev1" >> $RCFILE
-#	echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
+#	echo "echo Setting up loopback device $rootdev" >> $RCFILE
+#	echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
 #fi
 
 initrd_gen_suspend() {


More information about the pld-cvs-commit mailing list