Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Mar 2004 14:25:56 -0800
From:      Chris Roehrig <soekris@house.org>
To:        freebsd-questions@freebsd.org
Cc:        soekris-tech@lists.soekris.com
Subject:   Re: Diskless PXE clients: switching FreeBSD kernels based on MAC address
Message-ID:  <B8DA9ED2-7B86-11D8-9391-000A95791556@house.org>
In-Reply-To: <9E8C857C-7AA0-11D8-A650-000A95791556@house.org>
References:  <9E8C857C-7AA0-11D8-A650-000A95791556@house.org>

next in thread | previous in thread | raw e-mail | index | archive | help
I'm following up on my original question and cross-posting it to the  
Soekris list in case this is useful for anyone else.      If there's an  
easier way to do this, I'd like to know!

Here's a bootloader script I wrote that works for me (FreeBSD  
4.9_RELEASE).

================== kern_switch.4th  
=============================================
\
\     kern_switch.4th
\                   -- MAC-based kernel switching for PXE clients
\
\     Allows PXE booting of different kernels for different MAC  
addresses
\     using a shared NFS root partition.
\     Will use the default kernel if not booting from PXE or no HW MAC
\     addresses are matched.
\
\     USAGE:
\     1.  Place this in /boot on the NFS server.
\     2.  Include this from /boot/loader.conf using the following line:
\               exec="include /boot/kern_switch.4th"
\     3.  Edit the MAC address and kernel definitions below.
\     4.  Make sure you have an alternate boot device handy when  
installing
\         so you can undo things if you make a mistake!
\
\     v 1.0; Mar_21_2004;  Chris Roehrig <croehrig@house.org>


: switch_kernel ( kern_addr kern_n -- )
     2dup ." kern_switch DBG: switching kernel to " type cr
     s" kernel" setenv
;

\ Check environment for loaddev...
s" loaddev" getenv  dup -1 = [if]
	drop		\ the -1 retval
	.( kern_switch: no loaddev present in environment!) cr
[else]
     2dup .( kern_switch: loaddev = ) type cr

     s" pxe0:" compare 0= [if]
	\ PXE Boot; get the hardware MAC address...
	s" boot.netif.hwaddr" getenv  dup -1 = [if]
	    drop		\ the -1 retval
	    .( kern_switch: no boot.netif.hwaddr present in environment!) cr
	[else]
	    2dup .( kern_switch: boot.netif.hwaddr = ) type cr

	    \ switch on HW address...
	    \ ===================================================
	    \ ENTER YOUR MAC ADDRESSES AND KERNEL NAMES HERE
	    \   Pad all MAC bytes to 2-digit, lower-case.
	    \   Be careful to preserve the space after s" !

	    2dup s" 00:00:24:c1:2a:64" compare 0= [if]
		s" /kernel.NET4501"  switch_kernel [then]

	    2dup s" 00:00:24:c1:35:50" compare 0= [if]
		s" /kernel.NET4801"  switch_kernel [then]
	    \ ===================================================

	    2drop \ environment HW string

	[then]
     [then]
[then]



\ Display the kernel to be used...
s" kernel" getenv  dup -1 <> [if]
     .( kern_switch: using kernel = ) type cr
[else]
     drop
     .( kern_switch: no kernel present in environment!) cr
[then]

======================================================================== 
====



On Mar 20, 2004, at 10:58, Chris Roehrig wrote:
> I'm running FreeBSD 4.9_RELEASE and I'd like to share my server's root  
> partition as the root partition for some diskless PXE clients, but I  
> need different kernels for the server and clients.    The /conf  
> structure works great for providing different /etc environments for  
> each machine, but I can't figure out how to boot a different kernel  
> for my PXE clients.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B8DA9ED2-7B86-11D8-9391-000A95791556>