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

nbd support



Hey

Today I have written a patch that would be add nbd support to the current unstable live-initramfs package.

So I would ask for any suggestions for improvement.

The patch will be send with this email

Thanks Sebastian
diff -burN live-initramfs-1.157.4.orig/debian/changelog live-initramfs-1.157.4/debian/changelog
--- live-initramfs-1.157.4.orig/debian/changelog	2009-12-29 15:53:47.000000000 +0100
+++ live-initramfs-1.157.4/debian/changelog	2009-12-30 00:10:40.000000000 +0100
@@ -1,3 +1,10 @@
+live-initramfs (1.157.4-2+nbd) unstable; urgency=high
+
+  [ Sebastian Ortwein ]
+  * added nbd support
+
+ -- Sebastian Ortwein <kron@animeland.de>  Wed, 30 Dez 2009 00:09:21 +0100
+
 live-initramfs (1.157.4-2) unstable; urgency=high
 
   [ Michael Prokop ]
diff -burN live-initramfs-1.157.4.orig/debian/control live-initramfs-1.157.4/debian/control
--- live-initramfs-1.157.4.orig/debian/control	2009-12-29 15:53:47.000000000 +0100
+++ live-initramfs-1.157.4/debian/control	2009-12-30 00:09:45.000000000 +0100
@@ -14,7 +14,7 @@
 Architecture: all
 Depends: ${misc:Depends}, busybox, file, initramfs-tools, sudo, udev, user-setup
 Recommends: cryptsetup, eject, uuid-runtime, wget
-Suggests: loop-aes-utils, curlftpfs, genext2fs (>= 1.4.1), httpfs2, squashfs-tools, mtd-tools
+Suggests: loop-aes-utils, curlftpfs, genext2fs (>= 1.4.1), httpfs2, squashfs-tools, mtd-tools, nbd-client
 Description: Debian Live initramfs hook
  live-initramfs is a hook for the initramfs-tools, used to generate a initramfs
  capable to boot live systems, such as those created by live-helper. This
diff -burN live-initramfs-1.157.4.orig/hooks/live live-initramfs-1.157.4/hooks/live
--- live-initramfs-1.157.4.orig/hooks/live	2009-10-18 17:59:40.000000000 +0200
+++ live-initramfs-1.157.4/hooks/live	2009-12-29 19:34:37.000000000 +0100
@@ -189,3 +189,11 @@
 then
 	copy_exec /usr/bin/curlftpfs /bin
 fi
+
+# NBD-CLIENT and modules
+if [ -x /sbin/nbd-client ]
+then
+	copy_exec /sbin/nbd-client /sbin
+	manual_add_modules nbd
+fi
+
diff -burN live-initramfs-1.157.4.orig/manpages/live-initramfs.en.7.txt live-initramfs-1.157.4/manpages/live-initramfs.en.7.txt
--- live-initramfs-1.157.4.orig/manpages/live-initramfs.en.7.txt	2009-10-17 08:01:37.000000000 +0200
+++ live-initramfs-1.157.4/manpages/live-initramfs.en.7.txt	2009-12-30 00:08:42.000000000 +0100
@@ -170,6 +170,11 @@
 
 This lets you specify custom nfs options.
 
+  nbdroot=*IP*:*PORT*::
+
+This tells live-initramfs to perform a network mount with nbd, nbd-client must
+be installed to get the option working.
+
   noautologin::
 
 This parameter disables the automatic terminal login only, not touching gdk/kdm.
diff -burN live-initramfs-1.157.4.orig/scripts/live live-initramfs-1.157.4/scripts/live
--- live-initramfs-1.157.4.orig/scripts/live	2009-12-29 15:53:47.000000000 +0100
+++ live-initramfs-1.157.4/scripts/live	2009-12-30 00:03:46.000000000 +0100
@@ -216,6 +216,11 @@
 				export NFS_COW
 				;;
 
+			nbdroot=*)
+				NBDROOT="${ARGUMENT#nbdroot=}"
+				export NBDROOT
+				;;
+
 			noaccessibility)
 				NOACCESSIBILITY="Yes"
 				export NOACCESSIBILITY
@@ -745,6 +750,18 @@
 		return ${rc}
 	fi
 
+	if [ ! -z "${NBDROOT}" ]
+	then
+		if do_nbdmount
+		then
+			log_end_msg
+			return ${rc}
+		else
+			rc=0
+			return ${rc}
+		fi
+	fi
+
 	if [ "${NFSROOT#*:}" = "${NFSROOT}" ] && [ "$NETBOOT" != "cifs" ]
 	then
 		NFSROOT=${ROOTSERVER}:${NFSROOT}
@@ -766,6 +783,48 @@
 	return ${rc}
 }
 
+do_nbdmount ()
+{
+	rc=1
+
+	modprobe -q nbd
+
+	nbdsrv="${NBDROOT%:*}"
+	nbdport="${NBDROOT#*:}"
+	nbdbasedev=nbd0
+	nbdrootdev=/dev/${nbdbasedev}
+
+	log_begin_msg "Trying do mount filesystem on ${nbdsrv}:${nbdport}"
+
+	if [ -x /sbin/nbd-client ]
+	then
+		if [ -z "$nbdport" -o -z "$nbdsrv" ]
+		then
+			log_warning_msg "Insufficient information to set up nbd, quitting (nbdsrv=${nbdsrv} nbdport=${nbdport} )"
+			rc=0
+		else
+			if /sbin/nbd-client ${nbdsrv} ${nbdport} ${nbdrootdev} -persist
+			then
+				# This should be removed once the cfq scheduler no longer deadlocks nbd devices
+				if grep '\[cfq\]' /sys/block/${nbdbasedev}/queue/scheduler >/dev/null
+				then
+					echo deadline > /sys/block/${nbdbasedev}/queue/scheduler
+				fi
+				mountpoint=${nbdrootdev}
+				PLAIN_ROOT="Yes"
+				export PLAIN_ROOT
+			else
+				rc=0
+				log_warning_msg "error while executing nbd-client ( /sbin/nbd-client ${nbdsrv} ${nbdport} ${nbdrootdev} -persist )"
+			fi
+		fi
+	else
+		rc=0
+		log_warning_msg "error nbd-client not found install it and recreate initrd )"
+	fi
+	return ${rc}
+}
+
 do_httpmount ()
 {
 	rc=1
@@ -1587,7 +1646,7 @@
 
 	set_usplash_timeout
 
-	if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ]
+	if [ ! -z "${NETBOOT}" ] || [ ! -z "${FETCH}" ] || [ ! -z "${HTTPFS}" ] || [ ! -z "${FTPFS}" ] || [ ! -z "${NBDROOT}" ]
 	then
 		if do_netmount
 		then

Reply to: