[readonly/geninitrd: 551/1068] - parse CMDLINE for root=something once and put it into ROOT - when blkid is used and in ROOT is som

draenog draenog at pld-linux.org
Sat Nov 2 19:58:44 CET 2013


commit fc787d457df420ed7fd448a328e0911911203922
Author: undefine <undefine at pld-linux.org>
Date:   Mon Jan 28 00:27:21 2008 +0000

    - parse CMDLINE for root=something once and put it into ROOT
    - when blkid is used and in ROOT is something like UUID or LABEL -
      put into ROOT real device (detected by blkid)
    
    
    svn-id: @9204

 geninitrd | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)
---
diff --git a/geninitrd b/geninitrd
index 47f28ea..03b6bad 100755
--- a/geninitrd
+++ b/geninitrd
@@ -1461,20 +1461,15 @@ initrd_gen_lvm() {
 		EOF
 		add_linuxrc <<-'EOF'
 			# parse rootdev from kernel commandline
-			for arg in $CMDLINE; do
-				if [ "${arg##root=}" != "${arg}" ]; then
-					local rdev=${arg##root=}
-					if [ "$rdev" != "$ROOTDEV" ]; then
-						ROOTDEV=$rdev
-						echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
-						local tmp=${ROOTDEV#/dev/}
-						if [ "$tmp" != "$ROOTDEV" ]; then
-							VGVOLUME=${tmp%/*}
-							echo "LVM: Using Volume Group '$VGVOLUME'"
-						fi
-					fi
+			if [ "$ROOT" != "$ROOTDEV" ]; then
+				ROOTDEV=$ROOT
+				echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
+				local tmp=${ROOTDEV#/dev/}
+				if [ "$tmp" != "$ROOTDEV" ]; then
+					VGVOLUME=${tmp%/*}
+					echo "LVM: Using Volume Group '$VGVOLUME'"
 				fi
-			done
+			fi
 
 			# disable noise from LVM accessing devices that aren't ready.
 			read printk < /proc/sys/kernel/printk
@@ -1518,17 +1513,18 @@ initrd_gen_blkid()
 	inst /sbin/initrd-blkid /bin/blkid
 	initrd_gen_devices
 	add_linuxrc <<-'EOF'
-		device=/dev/no_partition_found
-		label="$(echo "$CMDLINE" | busybox awk '/root=LABEL=/ { gsub(/.*root=/,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ')"
-		[ -n $label ] && root="$(/bin/blkid -t $label -o device -l | busybox awk '/dev/ { gsub(/\/dev\//,NIL,$0); print $0; } ' )"
-		[ -n "$root" ] && device=/dev/$root
+		# if built with blkid change ROOT=LABEL=something into ROOT=/dev/somethingelse - 
+		# parsed by blkid
+		if [ "${ROOT##LABEL=}" != "${ROOT}" -o "${ROOT##UUID=}" != "${ROOT}" ]; then
+			ROOT="$(/bin/blkid -t $ROOT -o device -l)"
+		fi
 	EOF
 }
 
 initrd_gen_procdata() {
 	debug "Adding rootfs finding based on kernel cmdline root= option support."
 	add_linuxrc <<-'EOF'
-		[ -z "$root" ] && root="$(echo "$CMDLINE" | busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ')"
+		[ "${ROOT##/dev/}" != "${ROOT}" ] && root="${ROOT##/dev/}"
 		if [ -n "$root" ]; then
 			rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
 			if [ -n "$rootnr" ]; then
@@ -1902,6 +1898,9 @@ add_linuxrc <<-'EOF'
 		if [ "${arg##debuginitrd=}" != "${arg}" ]; then
 			DEBUGINITRD=${arg##debuginitrd=}
 		fi
+		if [ "${arg##root=}" != "${arg}" ]; then
+			ROOT=${arg##root=}
+		fi
 	done
 
 	# make debugshell() invoke subshell if $DEBUGINITRD=sh
@@ -1988,9 +1987,8 @@ if [ "$INITRDFS" = "initramfs" ]; then
 	# Parsing root parameter
 	# We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
 	add_linuxrc <<-'EOF'
-		[ -z "$device" ] && device=/dev/no_partition_found 
-		if [ "$device" = '/dev/no_partition_found' ]; then
-			eval "$(busybox awk -v c="$CMDLINE" '
+		device=/dev/no_partition_found 
+		eval "$(busybox awk -v c="$ROOT" '
 			BEGIN {
 				num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
 				num_pattern = "[0-9a-f]" num_pattern_short;
@@ -1998,9 +1996,6 @@ if [ "$INITRDFS" = "initramfs" ]; then
 				partition = "no_partition_found";
 				min = -1; maj = -1;
 
-				gsub(/.*root=/,NIL,c);
-				gsub(/ .*/,NIL,c);
-
 				sub("^0x", "", c);
 				if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
 				if (c ~ "^" num_pattern  "$") {
@@ -2019,7 +2014,6 @@ if [ "$INITRDFS" = "initramfs" ]; then
 					partition, maj, min);
 			}
 			' /proc/partitions)"
-		fi
 		if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
 			mknod $device b $maj $min
 		fi
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/readonly/geninitrd.git/commitdiff/147754ca159d40ca5eb541074dc043d8cbd92090



More information about the pld-cvs-commit mailing list