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

pxebooting per IP address



All,

It's good to see that OpenBSD now features PXE booting of clients.
>From what I gather, this is used primarily for installing OpenBSD to
a node, but another PXE implementation can feature a running system
in a diskless and NFS-less system. To this end, it is highly
preferable to have a selection for the bsd.rd to be booted at PXE
boottime. 

Looking at other implementations, most have environment variables
such as PXE_IP address obtained from DHCP, or MAC adres used in the
DHCP request present in the boot loader.  It seems that this
information is not yet passed to boot(8) by the pxeboot loader.

To aid us in per-IP kernel selection, we patched sys/stand/boot/boot.c
to include a (semi-lame) approach on selecting /$ip/boot.conf prior
to the system-default /etc/boot.conf; If we then have a 'boot
/10.0.0.1/bsd.rd' in the per-IP boot.conf, we can select a different
kernel at boottime.

This patch is a proof-of-concept; it is in no way meant to be
something that is pushed forward to CVS. Pleae advise on the best
approach to have IP related information at boot-time for PXE clients.

Cheers,

Paul 'WEiRD' de Weerd, Pim van Pelt

Index: boot.c
===================================================================
RCS file: /cvs/src/sys/stand/boot/boot.c,v
retrieving revision 1.30
diff -u -r1.30 boot.c
--- boot.c	29 Jan 2004 00:54:08 -0000	1.30
+++ boot.c	28 Mar 2004 17:48:00 -0000
@@ -34,6 +34,9 @@
 #include <libsa.h>
 #include <lib/libsa/loadfile.h>
 #include <lib/libkern/funcs.h>
+#include <pxe.h>
+
+extern BOOTPLAYER bootplayer;
 
 #include "cmd.h"
 
@@ -66,12 +70,41 @@
 
 	devboot(bootdev, cmd.bootdev);
 	strlcpy(cmd.image, bootfile, sizeof(cmd.image));
-	cmd.boothowto = 0;
-	cmd.conf = "/etc/boot.conf";
-	cmd.addr = (void *)DEFAULT_KERNEL_ADDRESS;
-	cmd.timeout = 5;
 
-	st = read_conf();
+	if (0 == strcmp (progname, "PXEBOOT")) {
+		uint32_t ip;
+		char myconf[200];
+
+		ip = bootplayer.yip;
+
+		/* Let's be non-intrusive.. We try to get our /$IP/boot.conf
+		 * first, and if that fails, fall back to /etc/boot.conf, 
+ 		 * and if that fails, do no boot.conf at all 
+		 * Pim van Pelt / Paul de Weerd 20040328 */
+		cmd.boothowto = 0;
+		snprintf (myconf, sizeof (myconf)-1, "/%d.%d.%d.%d/boot.conf",
+       			ip & 0xff, (ip>>8) & 0xff, (ip>>16) & 0xff, (ip>>24)& 0xff);
+		cmd.conf = myconf;
+		cmd.addr = (void *)DEFAULT_KERNEL_ADDRESS;
+		cmd.timeout = 5;
+
+		printf ("boot: Attempt to read %s", cmd.conf);
+		st = read_conf();
+		if (st == 1)
+			printf (" succesful\n");
+		else
+			printf (" failed\n");
+	} else {
+		st = -1;
+	}
+	if (st < 0) {
+		cmd.boothowto = 0;
+		cmd.conf = "/etc/boot.conf";
+		cmd.addr = (void *)DEFAULT_KERNEL_ADDRESS;
+		cmd.timeout = 5;
+
+		st = read_conf();
+	}	
 	if (!bootprompt)
 		snprintf(cmd.path, sizeof cmd.path, "%s:%s",
 		    cmd.bootdev, cmd.image);

-- 
>++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+
+++++++++++>-]<.>++[<------------>-]<+.--------------.[-]
                 http://www.weirdnet.nl/                 



Visit your host, monkey.org