patch against casper-1.63+debian-1

This should get netbooting working again!

Alex Owen
diff -uNr casper-1.63+debian.ORIG/scripts/casper casper-1.63+debian/scripts/casper
--- casper-1.63+debian.ORIG/scripts/casper	2006-08-05 16:23:06.000000000 +0100
+++ casper-1.63+debian/scripts/casper	2006-08-05 16:25:24.000000000 +0100
@@ -231,80 +231,110 @@
 }
 
 do_netmount() {
+	#no debug messages as stdout is interface withh calling function
 	# Will mount a remote share and return the mountpoint
 
-	modprobe -q nfs
 	# For DHCP
 	modprobe -q af_packet
 
-	ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf
+	#REMEMBER: no debug messages as stdout is interface withh calling function	
+	ipconfig ${DEVICE} /tmp/net-${DEVICE}.conf >/dev/null
 	if [ "x${NFSROOT}" = "xauto" ]; then
 		NFSROOT=${ROOTSERVER}:${ROOTPATH}
 	fi
 
-	#choose NFS or CIFS mount 
-	if [ ${netboot} = "NFS"  ] ; then
-		echo $(do_nfsmount)
-	else
-		echo $(do_cifsmount)
-	fi
+	#choose NFS or CIFS mount
+	case ${netboot} in 
+		NFS)
+			echo $(do_nfsmount)
+			;;
+		CIFS)
+			echo $(do_cifsmount)
+			;;
+		*)
+			panic "Unrecognized casper netboot method: ${netboot}"
+			;;
+	esac
 }
 
 do_nfsmount() {
+	#no debug messages as stdout is interface withh calling function
+	modprobe -q nfs
 	if [ "x${NFSOPTS}" = "x" ]; then
 		NFSOPTS=""
 	fi
 
-	[ "$quiet" != "y" ] && log_begin_msg "Mounting NFS with nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
+	#[ "$quiet" != "y" ] && log_begin_msg "Mounting NFS with nfsmount -o nolock -o ro ${NFSOPTS} ${NFSROOT} ${mountpoint}"
+	# FIXME: This while loop is an ugly HACK round an nfs bug
 	while true ; do 
-			nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && break
+		nfsmount -o nolock -o ro ${NFSOPTS} "${NFSROOT}" "${mountpoint}" && break
 		sleep 1
 	done
 	echo "${mountpoint}"
 	# FIXME: add error check
-	[ "$quiet" != "y" ] && log_end_msg
+	#[ "$quiet" != "y" ] && log_end_msg
 }
 
 do_cifsmount() {
+	#no debug messages as stdout is interface withh calling function
+	modprobe -q cifs
 	NFSOPTS="-ouser=root,password="
 
-	[ "$quiet" != "y" ] && log_begin_msg "Mounting using mount.cifs with ${NFSROOT} ${mountpoint} ${NFSOPTS}"
+	#[ "$quiet" != "y" ] && log_begin_msg "Mounting using mount.cifs with ${NFSROOT} ${mountpoint} ${NFSOPTS}"
 	mount.cifs "${NFSROOT}" "${mountpoint}" "${NFSOPTS}" && echo "${mountpoint}"
 	# FIXME: add error check
-	[ "$quiet" != "y" ] && log_end_msg
+	#[ "$quiet" != "y" ] && log_end_msg
 }
 
 setup_unionfs() {
+    #usage setup_unionfs image_dir(can be null) rootmnt rofsstring(optional) rofslist(optional) 
 	image_directory="$1"
 	rootmnt="$2"
-	image_type="$3"
+	#OLD#image_type="$3"
+	rofsstring=""
+	rofslist=""
+	if [ "x" != "x$3" ] ; then 
+		rofsstring="$3"
+	fi
+	if [ "x" != "x$4" ] ; then 
+		rofslist="$4"
+	fi
+
+	echo Just started setup_unionfs with args:
+	echo image_directory .$image_directory.
+	echo rootmnt .$rootmnt.	
+	echo rofsstring .$rofsstring.
+
 
 	modprobe -qb unionfs
 	croot=""	# Should really be /casper, but run-init doesn't handle
 				# mount-points in subdirectories at all
 
 	# Let's just mount the read-only file systems first
-	rofsstring=""
-	rofslist=""
-	mkdir -p "${croot}"
-	for image_type in "ext2" "squashfs" "dir" ; do
-		for image in "${image_directory}"/*."${image_type}"; do
-			imagename=$(basename "${image}")
-			if [ -d "${image}" ]; then
-				# it is a plain directory: do nothing
-				rofslist="${image} ${rofslist}"
-				rofsstring="${image}=ro:${rofsstring}"
-			elif [ -f "${image}" ]; then
-				backdev=$(get_backing_device "$image")
-				fstype=$(get_fstype "${backdev}")
-				if [ "${fstype}" = "unknown" ]; then
-					panic "Unknown file system type on ${backdev} (${image})"
+	if [ "x" != "x$croot" ] ; then
+		mkdir -p "${croot}"
+	fi
+	if [ "x" != "x$image_directory" ] ; then
+		#this must not run if $image_directory is empty
+		for image_type in "ext2" "squashfs" "dir" ; do
+			for image in "${image_directory}"/*."${image_type}"; do
+				imagename=$(basename "${image}")
+				if [ -d "${image}" ]; then
+					# it is a plain directory: do nothing
+					rofslist="${image} ${rofslist}"
+					rofsstring="${image}=ro:${rofsstring}"
+				elif [ -f "${image}" ]; then
+					backdev=$(get_backing_device "$image")
+					fstype=$(get_fstype "${backdev}")
+					if [ "${fstype}" = "unknown" ]; then
+						panic "Unknown file system type on ${backdev} (${image})"
+					fi
+					mkdir -p "${croot}/${imagename}"
+					mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=ro:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
 				fi
-				mkdir -p "${croot}/${imagename}"
-				mount -t "${fstype}" -o ro "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=ro:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
-			fi
+			done
 		done
-	done
+	fi
 	rofsstring=${rofsstring%:}
 
 	mkdir -p /cow
@@ -324,9 +354,11 @@
 
 	mount ${cowdevice} -t ${cow_fstype} -o rw /cow || panic "Can not mount $cowdevice on /cow"
 	
-	mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt"
+	echo running mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" 
+	mount -t unionfs -o dirs=/cow=rw:$rofsstring unionfs "$rootmnt" || panic "Unionfs mount failed"
 	
 	for d in ${rofslist}; do
+		#this must not run if $rofslist is empty
 		mkdir -p "${rootmnt}/casper/${d}"
 		mount -o bind "${d}" "${rootmnt}/${d}"
 		case d in 
@@ -360,6 +392,7 @@
 }
 
 find_livefs() {
+	#no debug messages as stdout is interface with calling script!
 	mounted=
 	for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram); do
 		devname=$(sys2dev "${sysblock}")
@@ -424,18 +457,31 @@
 
 	set_usplash_timeout
 
-	if grep -q netboot /proc/cmdline; then
-		netboot="CIFS"
+	if [ "${ROOT}" = "/dev/nfs" ] || grep -q netboot /proc/cmdline ; then
+		# netbooting
+		if [ "${ROOT}" = "/dev/nfs" ] ; then 
+			netboot="NFS"
+		else
+			netboot="CIFS"
+		fi
 		for x in $(cat /proc/cmdline); do
 			case $x in
 				netboot=*)
-					netboot=${x#netboot=}
+				    if [ "${x#netboot=}" = "CIFS" -o "${x#netboot=}" = "cifs" ; then
+					netboot="CIFS"
+				    elif [ "${x#netboot=}" = "NFS" -o "${x#netboot=}" = "nfs" ; then
+					netboot="NFS"
+				    fi
 				;;
 			esac
 		done
-		livefs_root=$(do_netboot)
+		livefs_root=$(do_netmount)
+		sleep 1
+		echo calling setup_unionfs "" "$rootmnt" "$livefs_root=nfsro"
+		setup_unionfs "" "$rootmnt" "$livefs_root=nfsro"
+
 	else
-		# Scan devices for the image
+		# Scan local devices for the image
 		for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f 10 11 12 13; do
 			livefs_root=$(find_livefs)
 			if [ "${livefs_root}" ]; then
@@ -443,17 +489,17 @@
 			fi
 			sleep 1
 		done
-	fi
 		
-	if [ "$?" -gt 0 ]; then
-		panic "Unable to find a medium containing a live file system"
-	fi
-		
-	if grep -q toram /proc/cmdline; then
-		copy_to_ram "${livefs_root}"
-	fi
+		if [ "$?" -gt 0 ]; then
+			panic "Unable to find a medium containing a live file system"
+		fi
+
+		if grep -q toram /proc/cmdline; then
+			copy_to_ram "${livefs_root}"
+		fi
 	
-	mount_images_in_directory "$livefs_root" "$rootmnt"
+		mount_images_in_directory "$livefs_root" "$rootmnt"
+	fi
 
 	log_end_msg
 
diff -uNr casper-1.63+debian.ORIG/scripts/casper-bottom/23networking casper-1.63+debian/scripts/casper-bottom/23networking
--- casper-1.63+debian.ORIG/scripts/casper-bottom/23networking	2006-08-05 16:23:06.000000000 +0100
+++ casper-1.63+debian/scripts/casper-bottom/23networking	2006-08-05 16:27:51.000000000 +0100
@@ -33,6 +33,8 @@
 	udevtrigger
 fi
 
+if ! grep -qs netboot /proc/cmdline ; then
+
 for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*; do
     [ -e $interface ] || continue
     i="$(basename $interface)"
@@ -52,4 +54,6 @@
 EOF
 done
 
+fi
+
 log_end_msg

Reply via email to