[readonly/geninitrd: 485/1068] - add function add_linuxrc() and generate all output via that function - add debuginitrd=sh possibil

draenog draenog at pld-linux.org
Sat Nov 2 19:53:09 CET 2013


commit c6c6ce01f110f38322a8294c8bf53518780cb67f
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Tue Oct 30 15:08:43 2007 +0000

    - add function add_linuxrc() and generate all output via that function
    - add debuginitrd=sh possibility to invoke shell at some points in initrd
    
    svn-id: @8899

 geninitrd | 475 +++++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 252 insertions(+), 223 deletions(-)
---
diff --git a/geninitrd b/geninitrd
index b8e6f75..332f6b3 100755
--- a/geninitrd
+++ b/geninitrd
@@ -116,6 +116,12 @@ die() {
 	exit $rc
 }
 
+# append text to /linuxrc
+# takes STDIN as input
+add_linuxrc() {
+	cat >> "$s"
+}
+
 # Checks if busybox has support for APPLET(s)
 # Exits from geninitrd if the support is not present.
 #
@@ -800,8 +806,7 @@ find_modules_for_device() {
 
 firmware_install_module_pre() {
 	local module="$1"
-	local linuxrc="$2"
-	local firmware_files="$3"
+	local firmware_files="$2"
 
 	debug "Adding Firmwares ($firmware_files) to initrd for module $module"
 	inst_d /proc
@@ -823,17 +828,19 @@ EOF
 		inst /lib/firmware/$firmware /lib/firmware/$firmware
 	done
 
-	echo "mount -t proc none /proc" >> "$linuxrc"
-	echo "mount -t sysfs none /sys" >> "$linuxrc"
-	echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" >> "$linuxrc"
+	echo "mount -t proc none /proc" | add_linuxrc
+	echo "mount -t sysfs none /sys" | add_linuxrc
+	echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
 }
 
 firmware_install_module_post() {
 	local module="$1"
-	local linuxrc="$2"
-	local firmware_files="$3"
-	echo "umount /sys" >> "$linuxrc"
-	echo "umount /proc" >> "$linuxrc"
+	local firmware_files="$2"
+
+	add_linuxrc <<-'EOF'
+		umount /sys
+		umount /proc
+	EOF
 }
 
 modules_install() {
@@ -850,7 +857,6 @@ modules_install() {
 
 modules_add_linuxrc() {
 	local modules="$1"
-	local linuxrc="$2"
 	local mod
 
 	for mod in $modules; do
@@ -879,14 +885,14 @@ modules_add_linuxrc() {
 		fi
 
 		if [ -n "$firmware_var" ]; then
-			firmware_install_module_pre "$module" "$linuxrc" "$firmware_var"
+			firmware_install_module_pre "$module" "$firmware_var"
 		fi
-		echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
+		echo "$insmod /lib/modules/$kernel/$MODULE2 $options" | add_linuxrc
 		if [ -n "${sleep_var}" ]; then
-			echo "usleep $sleep_var" >> "$linuxrc"
+			echo "usleep $sleep_var" | add_linuxrc
 		fi
 		if [ -n "$firmware_var" ]; then
-			firmware_install_module_post "$module" "$linuxrc" "$firmware_var"
+			firmware_install_module_post "$module" "$firmware_var"
 		fi
 	done
 }
@@ -1228,6 +1234,8 @@ mknod "$MNTIMAGE/dev/zero" c 1 5
 inst_d /dev/pts /dev/shm
 
 s="$RCFILE"
+> "$s"
+chmod 755 "$s"
 ln -s /linuxrc $MNTIMAGE/init
 
 inst /bin/initrd-busybox /bin/initrd-busybox
@@ -1238,18 +1246,26 @@ if is_yes "$USEINSMODSTATIC"; then
 	inst "$INSMOD" /bin/insmod.static
 fi
 
-cat > "$s" <<'EOF'
-#! /bin/sh
-mount -t proc none /proc
-CMDLINE="$(cat /proc/cmdline)"
-if [[ "$CMDLINE" = *debuginitrd* ]]; then
-	set -x
-fi
-umount /proc
+add_linuxrc <<-'EOF'
+	#!/bin/sh
+	mount -t proc none /proc
+	export CMDLINE="$(cat /proc/cmdline)"
+	if [ "$(awk '/debuginitrd/ { print "yes" }' /proc/cmdline)" = "yes" ]; then
+		export DEBUGINITRD=yes
+		debugshell() {
+			: 'Entering debug shell. Type Ctrl-D to exit it.'
+			sh
+		}
+		set -x
+	else
+		debugshell() {
+			:
+		}
+	fi
+	umount /proc
 EOF
-chmod 755 "$s"
 
-modules_add_linuxrc "$MODULES" "$s"
+modules_add_linuxrc "$MODULES"
 
 # TODO: rewrite for busybox
 #if [ -n "$loopDev" ]; then
@@ -1279,24 +1295,22 @@ initrd_gen_suspend() {
 	else
 		inst /usr/sbin/resume /bin/resume
 	fi
-	echo "resume" >> "$s"
+	echo "resume" | add_linuxrc
 }
 
 initrd_gen_tuxonice() {
 	inst_d /sys /proc
-cat << 'EOF' >> "$s"
-mount -t proc none /proc
-mount -t sysfs none /sys
-if [ "$(awk ' /resume2=/  { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
-EOF
-cat << EOF >> "$s"
-		[ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
-		[ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
-		[ -e /sys/power/tuxonice/do_resume ] && echo >  /sys/power/tuxonice/do_resume
-fi
-umount /sys
-umount /proc
-EOF
+	add_linuxrc <<-'EOF'
+		mount -t proc none /proc
+		mount -t sysfs none /sys
+		if [ "$(echo "$CMDLINE" | awk ' /resume2=/  { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
+			[ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
+			[ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
+			[ -e /sys/power/tuxonice/do_resume ] && echo >  /sys/power/tuxonice/do_resume
+		fi
+		umount /sys
+		umount /proc
+	EOF
 }
 
 # generate code to mount /dev on tmpfs and create initial nodes
@@ -1316,15 +1330,15 @@ initrd_gen_tmpfs_dev() {
 	tmpfs_dev=yes
 
 	busybox_applet mount mknod mkdir
-	cat >> "$s" <<-EOF
-: 'Creating /dev'
-mount -o mode=0755 -t tmpfs none /dev
-mknod /dev/console c 5 1
-mknod /dev/null c 1 3
-mknod /dev/zero c 1 5
-mkdir /dev/pts
-mkdir /dev/shm
-EOF
+	add_linuxrc <<-EOF
+		: 'Creating /dev'
+		mount -o mode=0755 -t tmpfs none /dev
+		mknod /dev/console c 5 1
+		mknod /dev/null c 1 3
+		mknod /dev/zero c 1 5
+		mkdir /dev/pts
+		mkdir /dev/shm
+	EOF
 }
 
 initrd_gen_udev() {
@@ -1340,7 +1354,7 @@ initrd_gen_udev() {
 
 	if is_yes "$USE_UDEV"; then
 		initrd_gen_tmpfs_dev
-		cat >> "$s" <<- 'EOF'
+		add_linuxrc <<-'EOF'
 			mount -t proc none /proc
 			mount -t sysfs none /sys
 			: 'Starting udev'
@@ -1349,14 +1363,14 @@ initrd_gen_udev() {
 		if is_yes "$PROBESTATICMODS"; then
 			inst /sbin/initrd-udevtrigger /sbin/udevtrigger
 			inst /sbin/initrd-udevsettle /sbin/udevsettle
-			cat >> "$s" <<-'EOF'
+			add_linuxrc <<-'EOF'
 				/sbin/udevtrigger
 				/sbin/udevsettle
 			EOF
 		fi
 
 		busybox_applet killall
-		cat >> "$s" <<-'EOF'
+	   	add_linuxrc	<<-'EOF'
 			killall udevd
 			umount /proc
 			umount /sys
@@ -1378,26 +1392,28 @@ initrd_gen_multipath() {
 		inst /var/lib/multipath/bindings /var/lib/multipath
 	fi
 
-	cat <<-'EOF' >> "$s"
-	mount -t proc none /proc
-	mount -t sysfs none /sys
-EOF
+	add_linuxrc <<-'EOF'
+		mount -t proc none /proc
+		mount -t sysfs none /sys
+	EOF
 
 	initrd_gen_tmpfs_dev
 	initrd_gen_devices
 
-	echo "export multipath_id=$MULTIPATH_ID" >> "$s"
-	cat <<-'EOF' >> "$s"
-	/sbin/multipath -v 0 $multipath_id
+	echo "export multipath_id=$MULTIPATH_ID" | add_linuxrc
+	add_linuxrc <<-'EOF'
+		/sbin/multipath -v 0 $multipath_id
 
-	for a in /dev/mapper/*; do
-		[ $a = /dev/mapper/control ] && continue
-		/sbin/kpartx -a $a
-	done
+		for a in /dev/mapper/*; do
+			[ $a = /dev/mapper/control ] && continue
+			/sbin/kpartx -a $a
+		done
 
-	umount /sys
-	umount /proc
-EOF
+		debugshell
+
+		umount /sys
+		umount /proc
+	EOF
 }
 
 initrd_gen_dmraid() {
@@ -1410,21 +1426,24 @@ initrd_gen_dmraid() {
 
 	inst_d /sbin /sys
 	inst /sbin/dmraid-initrd /sbin/dmraid
-	cat <<-EOF >> "$s"
-	mount -t proc none /proc
-	mount -t sysfs none /sys
-EOF
+	add_linuxrc <<-EOF
+		mount -t proc none /proc
+		mount -t sysfs none /sys
+	EOF
 
 	initrd_gen_devices
 
-	cat <<-EOF >> "$s"
-	# 2 secs was enough for my system to initialize. but really this is udev issue?
-	usleep 2000000
-	: 'Activating Device-Mapper RAID(s)'
-	/sbin/dmraid -ay -i
-	umount /sys
-	umount /proc
-EOF
+	add_linuxrc <<-EOF
+		# 2 secs was enough for my system to initialize. but really this is udev issue?
+		usleep 2000000
+		: 'Activating Device-Mapper RAID(s)'
+		/sbin/dmraid -ay -i
+
+		debugshell
+
+		umount /sys
+		umount /proc
+	EOF
 }
 
 # Generates /dev nodes based on /proc/partitions information.
@@ -1436,16 +1455,19 @@ initrd_gen_devices() {
 	fi
 	proc_partitions=yes
 
-	cat <<-'EOF' >> "$s"
-	: 'Making device nodes'
-	# ignore first two lines, header, empty line and process rest
-	cat /proc/partitions | (read b; read b; while read major minor blocks dev rest; do
-		node=/dev/$dev
-		mkdir -p ${node%/*}
-		mknod $node b $major $minor
-	done
-	)
-EOF
+	add_linuxrc <<-'EOF'
+		: 'Making device nodes'
+		cat /proc/partitions | (
+			# ignore first two lines, header, empty line and process rest
+			read b; read b
+
+			while read major minor blocks dev rest; do
+				node=/dev/$dev
+				mkdir -p ${node%/*}
+				mknod $node b $major $minor
+			done
+		)
+	EOF
 }
 
 initrd_gen_md() {
@@ -1488,7 +1510,7 @@ initrd_gen_md() {
 		done
 	done
 
-	echo "mdassemble" >> "$s"
+	echo "mdassemble" | add_linuxrc
 
 	# needed to determine md-version
 	if [ "$do_md0" -eq 1 ]; then
@@ -1503,45 +1525,49 @@ initrd_gen_nfs() {
 	mknod "$MNTIMAGE/dev/urandom" c 1 9
 	mkdir "$MNTIMAGE/newroot"
 	mkdir "$MNTIMAGE/proc"
-	echo "ifconfig lo 127.0.0.1 up" >> "$s"
-	echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
-	echo "ifconfig eth0 0.0.0.0 up" >> "$s"
-	echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
-	cat << 'EOF' > "$MNTIMAGE/bin/setdhcp"
-#!/bin/sh
-[ "$1" != "bound" ] && exit
-[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
-[ -n "$subnet" ] && NETMASK="netmask $subnet"
-ifconfig $interface $ip $BROADCAST $NETMASK up
-if [ -n "$router" ]; then
-	for r in $router; do
-		route add default gw $r dev $interface
-	done
-fi
+	echo "ifconfig lo 127.0.0.1 up" | add_linuxrc
+	echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" | add_linuxrc
+	echo "ifconfig eth0 0.0.0.0 up" | add_linuxrc
+	echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" | add_linuxrc
+
+	cat <<-'EOF' > "$MNTIMAGE/bin/setdhcp"
+		#!/bin/sh
+		[ "$1" != "bound" ] && exit
+		[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
+		[ -n "$subnet" ] && NETMASK="netmask $subnet"
+		ifconfig $interface $ip $BROADCAST $NETMASK up
+		if [ -n "$router" ]; then
+			for r in $router; do
+				route add default gw $r dev $interface
+			done
+		fi
 
-mount -t proc none /proc
-for o in $(cat /proc/cmdline); do
-	case $o in
-	nfsroot=*)
-		rootpath=${o#nfsroot=}
-		;;
-	esac
-done
-umount /proc
+		mount -t proc none /proc
+		for o in $(cat /proc/cmdline); do
+			case $o in
+			nfsroot=*)
+				rootpath=${o#nfsroot=}
+				;;
+			esac
+		done
+		umount /proc
+
+		if [ -n "$rootpath" ]; then
+			mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
+		else
+			echo "Missing rootpath in what DHCP server sent to us. Failing..."
+			echo "All seen variables are listed below:"
+			set
+		fi
+	EOF
 
-if [ -n "$rootpath" ]; then
-	mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
-else
-	echo "Missing rootpath in what DHCP server sent to us. Failing..."
-	echo "All seen variables are listed below:"
-	set
-fi
-EOF
 	chmod 755 "$MNTIMAGE/bin/setdhcp"
-	echo "cd /newroot" >> "$s"
-	echo "pivot_root . initrd" >> "$s"
-	echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
-	echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
+	add_linuxrc <<-'EOF'
+		cd /newroot
+		pivot_root . initrd
+		[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
+		exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
+	EOF
 }
 
 initrd_gen_lvm() {
@@ -1563,16 +1589,20 @@ initrd_gen_lvm() {
 			inst $device /dev
 		done
 	fi
-	echo "mount -t proc none /proc" >> "$s"
-	echo "mount -t tmpfs none /tmp" >> "$s"
+	add_linuxrc <<-'EOF'
+		mount -t proc none /proc
+		mount -t tmpfs none /tmp
+	EOF
 	if [ "$LVMTOOLSVERSION" = "1" ]; then
-		echo "lvm vgscan -T" >> "$s"
-		echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
-		echo "umount /tmp" >> "$s"
-		# fail to umount
-		echo "umount /proc" >> "$s"
+		add_linuxrc <<-EOF
+			lvm vgscan -T
+			lvm vgchange -T -a y $VGVOLUME
+			umount /tmp
+			# fail to umount
+			umount /proc
+		EOF
 	else
-		echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
+		echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
 		echo "global {" > "$MNTIMAGE/etc/lvm.conf"
 		echo "	locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
 		echo "	locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
@@ -1601,50 +1631,49 @@ initrd_gen_lvm() {
 
 		initrd_gen_devices
 
-		cat <<-EOF >> "$s"
-
-		# disable noise from lvm accessing devices that aren't ready.
-		printk=\$(cat /proc/sys/kernel/printk)
-		echo 0 > /proc/sys/kernel/printk
-
-		export LVM_SYSTEM_DIR=/tmp
-		: 'Scanning for Volume Groups'
-		lvm vgscan --mknodes --ignorelockingfailure 2>/dev/null
-
-		: 'Activating Volume Groups'
-		lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
-
-		echo "\$printk" > /proc/sys/kernel/printk
-
-		# Find out major/minor
-		majmin="\$(lvm lvdisplay --ignorelockingfailure -c $rootdev 2>/dev/null)"
-		majmin="\${majmin#*/}"
-		majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
-		major="\${majmin%:*}"
-		minor="\${majmin#*:}"
-		# Pass it to kernel
-		val=\$((256 * \$major + \$minor))
-		echo \$val > /proc/sys/kernel/real-root-dev
-		umount /tmp
-		umount /proc
-EOF
+		add_linuxrc <<-EOF
+			# disable noise from lvm accessing devices that aren't ready.
+			printk=\$(cat /proc/sys/kernel/printk)
+			echo 0 > /proc/sys/kernel/printk
+
+			export LVM_SYSTEM_DIR=/tmp
+			: 'Scanning for Volume Groups'
+			lvm vgscan --mknodes --ignorelockingfailure 2>/dev/null
+
+			: 'Activating Volume Groups'
+			lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
+
+			echo "\$printk" > /proc/sys/kernel/printk
+
+			# Find out major/minor
+			majmin="\$(lvm lvdisplay --ignorelockingfailure -c $rootdev 2>/dev/null)"
+			majmin="\${majmin#*/}"
+			majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
+			major="\${majmin%:*}"
+			minor="\${majmin#*:}"
+			# Pass it to kernel
+			val=\$((256 * \$major + \$minor))
+			echo \$val > /proc/sys/kernel/real-root-dev
+			umount /tmp
+			umount /proc
+		EOF
 	fi
 }
 
 initrd_gen_procdata() {
 	debug "Adding rootfs finding based on root= option support."
 	inst_d /proc
-cat << 'EOF' >> "$s"
-mount -t proc none /proc
-root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
-if [ -n "$root" ]; then
-	rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
-	if [ -n "$rootnr" ]; then
-		echo "$rootnr" > /proc/sys/kernel/real-root-dev
-	fi
-fi
-umount /proc
-EOF
+	add_linuxrc <<-'EOF'
+		mount -t proc none /proc
+		root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
+		if [ -n "$root" ]; then
+			rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
+			if [ -n "$rootnr" ]; then
+				echo "$rootnr" > /proc/sys/kernel/real-root-dev
+			fi
+		fi
+		umount /proc
+	EOF
 }
 
 # main generation
@@ -1686,9 +1715,9 @@ fi
 
 # finally umount /dev if it was on tmpfs
 if is_yes "$tmpfs_dev"; then
-	cat <<-EOF >> "$s"
-	umount /dev
-EOF
+	add_linuxrc <<-EOF
+		umount /dev
+	EOF
 	tmpfs_dev=no
 fi
 
@@ -1700,65 +1729,65 @@ if [ "$INITRDFS" = "initramfs" ]; then
 	[ ! -e "$MNTIMAGE/$rootdev" ] && inst $rootdev /dev
 	# Parsing root parameter
 	# We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
-	cat << 'EOF' >> "$s"
-mount -t proc none /proc
-
-eval "$(busybox awk -v c="$CMDLINE" '
-BEGIN {
-	num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
-	num_pattern = "[0-9a-f]" num_pattern_short;
-	dev_pattern = "[hms][a-z][a-z]([0-9])+";
-	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  "$") {
-		maj = sprintf("%s",substr(c,1,2));
-		min = sprintf("%s",substr(c,3));
-	}
-	if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
-	if (c ~ "^" dev_pattern "$") partition = c;
-}
+	add_linuxrc <<-'EOF'
+		mount -t proc none /proc
 
-$4 ~ partition { maj = $1; min = $2; }
-$1 ~ maj && $2 ~ min { partition = $4; }
+		eval "$(busybox awk -v c="$CMDLINE" '
+		BEGIN {
+			num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
+			num_pattern = "[0-9a-f]" num_pattern_short;
+			dev_pattern = "[hms][a-z][a-z]([0-9])+";
+			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  "$") {
+				maj = sprintf("%s",substr(c,1,2));
+				min = sprintf("%s",substr(c,3));
+			}
+			if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
+			if (c ~ "^" dev_pattern "$") partition = c;
+		}
 
-END {
-	print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
-		partition, maj, min);
-}
-' /proc/partitions)"
-if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
-	mknod $device b $maj $min
-fi
-EOF
+		$4 ~ partition { maj = $1; min = $2; }
+		$1 ~ maj && $2 ~ min { partition = $4; }
+
+		END {
+			print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
+				partition, maj, min);
+		}
+		' /proc/partitions)"
+		if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
+			mknod $device b $maj $min
+		fi
+	EOF
 
 	busybox_applet switch_root
-	cat << EOF >> "$s"
-if [ "\$device" = '/dev/no_partition_found' ]; then
-	device="$rootdev"
-fi
+	add_linuxrc <<-EOF
+		if [ "\$device" = '/dev/no_partition_found' ]; then
+			device="$rootdev"
+		fi
 
-mount -t $rootFs -r \$device /newroot
-init="\$(busybox awk ' /init=\// { gsub(/.*init=/,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; }  ' /proc/cmdline )"
-if [ -z "\$init" -o ! -x "/newroot\$init" ]; then
-	init=/sbin/init
-fi
-umount /proc
-exec switch_root /newroot \$init
+		mount -t $rootFs -r \$device /newroot
+		init="\$(busybox awk ' /init=\// { gsub(/.*init=/,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; }  ' /proc/cmdline )"
+		if [ -z "\$init" -o ! -x "/newroot\$init" ]; then
+			init=/sbin/init
+		fi
+		umount /proc
+		exec switch_root /newroot \$init
 
-echo "Error ! initramfs should not reach this place."
-echo "It probably means you've got old version of busybox, with broken"
-echo "initramfs support. Trying to boot anyway, but won't promise anything."
+		echo "Error ! initramfs should not reach this place."
+		echo "It probably means you've got old version of busybox, with broken"
+		echo "initramfs support. Trying to boot anyway, but won't promise anything."
 
-exec chroot /newroot \$init
+		exec chroot /newroot \$init
 
-echo "Failed to chroot !"
-EOF
+		echo "Failed to chroot !"
+	EOF
 	# we need real file, not symlink
 	rm -f $MNTIMAGE/init
 	cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list