[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Booting fro an iso image over the net and http boot fix



Hello

These patches still apply to the live script (with some fuzz) in spite
of it being reworked.

The first one adds .iso as a valid filesystem image extension and
looks inside for a filesystem.squashfs, the second one adds iscsi
support (which does not work due to a stupid assumption in iscsid that
/etc/passwd is always available and getpwent() can get valid data from
it) and the last one sets the NETBOOT variable when booting from http
and prevents falling through to nfs when http boot fails.

Thanks

Michal
--- usr/share/initramfs-tools/scripts/live.orig	2009-09-03 23:25:10.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-03 23:26:30.000000000 +0200
@@ -768,7 +768,7 @@
 		if [ -n "$url" ]
 		then
 			case "${extension}" in
-				squashfs|tgz|tar)
+				iso|squashfs|tgz|tar)
 					if [ "${webfile}" = "FETCH" ]
 					then
 						case "$url" in
@@ -797,6 +797,12 @@
 					fi
 					[ ${?} -eq 0 ] && rc=0
 					[ "${extension}" = "tgz" ] && live_dest="ram"
+					if [ "${extension}" = "iso" ]
+					then
+					    isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
+					    mount -t iso9660 "${isoloop}" "${mountpoint}"
+					    rc=${?}
+					fi
 					break
 					;;
 
--- usr/share/initramfs-tools/scripts/live~	2009-09-07 05:36:51.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-07 16:08:41.000000000 +0200
@@ -8,6 +8,7 @@
 echo "/root/usr/lib" >> /etc/ld.so.conf
 
 mountpoint="/live/image"
+ext_mountpoint="/ext_volume"
 LIVE_MEDIA_PATH="live"
 
 root_persistence="live-rw"
@@ -756,19 +757,25 @@
 do_httpmount ()
 {
 	rc=1
-	dest="${mountpoint}/${LIVE_MEDIA_PATH}"
-	mount -t ramfs ram "${mountpoint}"
-	mkdir -p "${dest}"
 
 	for webfile in HTTPFS FTPFS FETCH
 	do
-		url="$(eval echo \"\$\{${webfile}\}\")"
-		extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
+		local url="$(eval echo \"\$\{${webfile}\}\")"
+		local extension="$(echo "${url}" | sed 's/\(.*\)\.\(.*\)/\2/')"
 
 		if [ -n "$url" ]
 		then
 			case "${extension}" in
 				iso|squashfs|tgz|tar)
+					if [ "${extension}" = "iso" ]
+					then
+						mkdir -p "${ext_mountpoint}"
+						dest="${ext_mountpoint}"
+					else
+						local dest="${mountpoint}/${LIVE_MEDIA_PATH}"
+						mount -t ramfs ram "${mountpoint}"
+						mkdir -p "${dest}"
+					fi
 					if [ "${webfile}" = "FETCH" ]
 					then
 						case "$url" in
@@ -799,9 +806,9 @@
 					[ "${extension}" = "tgz" ] && live_dest="ram"
 					if [ "${extension}" = "iso" ]
 					then
-					    isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
-					    mount -t iso9660 "${isoloop}" "${mountpoint}"
-					    rc=${?}
+						isoloop=$(setup_loop "${dest}/$(basename "${url}")" "loop" "/sys/block/loop*" "" '')
+						mount -t iso9660 "${isoloop}" "${mountpoint}"
+						rc=${?}
 					fi
 					break
 					;;
@@ -815,7 +822,12 @@
 
 	if [ ${rc} != 0 ]
 	then
-	    umount "${mountpoint}"
+		if [ -d "${ext_mountpoint}" ]
+		then
+		        umount "${ext_mountpoint}"
+			rmdir "${ext_mountpoint}"
+		fi
+		umount "${mountpoint}"
 	fi
 
 	return ${rc}
--- usr/share/initramfs-tools/scripts/live-bottom/05mountpoints~	2009-09-07 16:23:01.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live-bottom/05mountpoints	2009-09-07 16:25:02.000000000 +0200
@@ -33,4 +33,10 @@
 	mount --move /live/image /root/live/image
 fi
 
+if [ -d /ext_volume ]
+then
+      mkdir -p /root/live/ext_volume
+      mount --move /ext_volume /root/live/ext_volume
+fi
+
 log_end_msg
--- usr/share/initramfs-tools/hooks/live.0	2009-09-09 17:33:41.000000000 +0200
+++ usr/share/initramfs-tools/hooks/live	2009-09-09 17:36:47.000000000 +0200
@@ -176,3 +176,13 @@
 then
 	copy_exec /usr/bin/curlftpfs /bin
 fi
+
+# iSCSI
+if [ -x /usr/bin/iscsiadm ] && [ -x /usr/sbin/iscsid ]
+then
+    copy_exec /usr/bin/iscsiadm /bin
+    copy_exec /usr/sbin/iscsid /bin
+    #manual_add_modules ib_iser
+    manual_add_modules iscsi_tcp
+    manual_add_modules crc32c
+fi
--- usr/share/initramfs-tools/scripts/live.0	2009-09-09 17:33:25.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 17:37:58.000000000 +0200
@@ -87,6 +87,15 @@
 				export HTTPFS
 				;;
 
+			iscsi=*)
+				ISCSI="${ARGUMENT#iscsi=}"
+				#ip:port - separated by ,
+				ISCSI_PORTAL="${ISCSI%,*}"
+				#target name
+				ISCSI_TARGET="${ISCSI#*,}"
+				export ISCSI ISCSI_PORTAL ISCSI_TARGET
+				;;
+
 			hostname=*)
 				HOSTNAME="${ARGUMENT#hostname=}"
 				LIVECONF="changed"
@@ -688,7 +697,7 @@
 	return 0
 }
 
-do_netmount ()
+do_netsetup ()
 {
 	rc=1
 
@@ -713,6 +722,11 @@
 	[ -z ${HOSTNAME} ] && HOSTNAME=${OLDHOSTNAME}
 	export HOSTNAME
 
+	if [ -n "${DEVICE}" ]
+	then
+		HWADDR="$(cat /sys/class/net/${DEVICE}/address)"
+	fi
+
 	# Check if we have a network device at all
 	if ! ls /sys/class/net/eth0 > /dev/null 2>&1 && \
 	   ! ls /sys/class/net/wlan0 > /dev/null 2>&1 && \
@@ -721,6 +735,11 @@
 	then
 		panic "No supported network device found, maybe a non-mainline driver is required."
 	fi
+}
+
+do_netmount()
+{
+	do_netsetup
 
 	if [ "${NFSROOT}" = "auto" ]
 	then
@@ -754,6 +773,24 @@
 	return ${rc}
 }
 
+do_iscsi()
+{
+	do_netsetup
+	#modprobe ib_iser
+	modprobe iscsi_tcp
+	mkdir -p /etc/iscsi
+	#FIXME this name is supposed to be unique - some date + ifconfig hash?
+	echo "InitiatorName=iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)" > /etc/iscsi/initiatorname.iscsi
+	iscsid -f &
+	iscsiadm --mode discovery --type sendtargets --portal "${ISCSI_PORTAL}" -I default
+	iscsiadm --mode node --targetname "${ISCSI_TARGET}" --portal "${ISCSI_PORTAL}" --login
+	if [ $? != 0 ]
+	then
+		panic "Failed to log into iscsi target"
+	fi
+	#FIXME set the iscsi device name into ROOT
+}
+
 do_httpmount ()
 {
 	rc=1
@@ -1580,6 +1617,10 @@
 			panic "Unable to find a live file system on the network"
 		fi
 	else
+		if [ -n "${ISCSI_PORTAL}" ]
+		then
+			do_iscsi
+		fi
 		if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
 			# Do a local boot from hd
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 18:04:25.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 18:09:24.000000000 +0200
@@ -779,11 +779,13 @@
 	#modprobe ib_iser
 	modprobe iscsi_tcp
 	mkdir -p /etc/iscsi
+	local debugopt=""
+	[ "${DEBUG}" == "Yes" ] && debugopt="-d 8"
 	#FIXME this name is supposed to be unique - some date + ifconfig hash?
 	echo "InitiatorName=iqn.1993-08.org.debian.live:01:$(echo "${HWADDR}" | sed -e s/://g)" > /etc/iscsi/initiatorname.iscsi
-	iscsid -f &
-	iscsiadm --mode discovery --type sendtargets --portal "${ISCSI_PORTAL}" -I default
-	iscsiadm --mode node --targetname "${ISCSI_TARGET}" --portal "${ISCSI_PORTAL}" --login
+	iscsid $debugopt -f &
+	iscsiadm $debugopt --mode discovery --type sendtargets --portal "${ISCSI_PORTAL}" -I default
+	iscsiadm $debugopt --mode node --targetname "${ISCSI_TARGET}" --portal "${ISCSI_PORTAL}" --login
 	if [ $? != 0 ]
 	then
 		panic "Failed to log into iscsi target"
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 19:05:55.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 20:08:49.000000000 +0200
@@ -790,7 +790,21 @@
 	then
 		panic "Failed to log into iscsi target"
 	fi
-	#FIXME set the iscsi device name into ROOT
+	local host="$(ls -d /sys/class/scsi_host/host?/device/iscsi_host:host? | sed -e 's:/device.*::' -e 's:.*host::')"
+	if [ -n "${host}" ]
+	then
+		local devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* | sed -e 's/.*://')"
+		for dev in $devices
+		do
+			if check_dev "null" "/dev/$dev"
+			then
+				return 0;
+			fi
+		done
+		panic "Failed to locate a live device on iSCSI devices (tried: $devices)."
+	else
+		panic "Failed to locate iSCSI host in /sys"
+	fi
 }
 
 do_httpmount ()
@@ -1623,6 +1637,7 @@
 		if [ -n "${ISCSI_PORTAL}" ]
 		then
 			do_iscsi
+			livefs_root="${mountpoint}"
 		fi
 		if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 20:08:49.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 20:17:45.000000000 +0200
@@ -793,7 +793,15 @@
 	local host="$(ls -d /sys/class/scsi_host/host?/device/iscsi_host:host? | sed -e 's:/device.*::' -e 's:.*host::')"
 	if [ -n "${host}" ]
 	then
-		local devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* | sed -e 's/.*://')"
+		local devices=""
+		local i=0
+		while [ -z "${devices}" -a $i -lt 60 ]
+		do
+			sleep 1
+			devices="$(ls -d /sys/class/scsi_device/${host}*/device/block:* | sed -e 's/.*://')"
+			i=$(expr $i + 1)
+			echo -ne $i\\r
+		done
 		for dev in $devices
 		do
 			if check_dev "null" "/dev/$dev"
--- usr/share/initramfs-tools/scripts/live~	2009-09-09 21:11:21.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-09 23:03:16.000000000 +0200
@@ -1642,10 +1642,8 @@
 	else
 		if [ -n "${ISCSI_PORTAL}" ]
 		then
-			do_iscsi
-			livefs_root="${mountpoint}"
-		fi
-		if [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
+		    livefs_root="$(do_iscsi)"
+		elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
 			# Do a local boot from hd
 			livefs_root=${ROOT}
--- usr/share/initramfs-tools/scripts/live~	2009-09-10 13:08:01.000000000 +0200
+++ usr/share/initramfs-tools/scripts/live	2009-09-10 14:13:17.000000000 +0200
@@ -1641,9 +1641,9 @@
 			panic "Unable to find a live file system on the network"
 		fi
 	else
-		if [ -n "${ISCSI_PORTAL}" ]
+		if [ -n "${ISCSI_PORTAL}" ]
 		then
-		    livefs_root="$(do_iscsi)"
+			do_iscsi && livefs_root="${mountpoint}"
 		elif [ -n "${PLAIN_ROOT}" ] && [ -n "${ROOT}" ]
 		then
 			# Do a local boot from hd
--- usr/share/initramfs-tools/scripts/live.orig	2009-11-04 16:31:29.000000000 +0100
+++ usr/share/initramfs-tools/scripts/live	2009-11-04 16:51:55.000000000 +0100
@@ -699,8 +699,6 @@
 
 do_netsetup ()
 {
-	rc=1
-
 	modprobe -q af_packet # For DHCP
 
 	if [ -x /sbin/udevadm ]
@@ -746,10 +744,12 @@
 		NFSROOT=${ROOTSERVER}:${ROOTPATH}
 	fi
 
-	if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] ) && do_httpmount
+	rc=1
+
+	if ( [ -n "${FETCH}" ] || [ -n "${HTTPFS}" ] || [ -n "${FTPFS}" ] )
 	then
-		rc=0
-		return ${rc}
+		do_httpmount
+		return $?
 	fi
 
 	if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
#@@ -813,6 +813,8 @@
 	else
 		panic "Failed to locate iSCSI host in /sys"
 	fi
+	NETBOOT="iscsi"
+	export NETBOOT
 }
 
 do_httpmount ()
#@@ -889,6 +891,9 @@
 			rmdir "${ext_mountpoint}"
 		fi
 		umount "${mountpoint}"
+	elif [ "${webfile}"  != "FETCH" ] ; then
+		NETBOOT="${webfile}"
+		export NETBOOT
 	fi
 
 	return ${rc}

Reply to: