How to Compile Ports/iPXE w/ Embedded Script?

Hello. I've been working on how to have FreeBSD 13.0 act as a Network Boot SAN by hosting iSCSI/DHCP/TFTP services. I found a means to get DHCP to identify individual clients based on MAC address and I'm able to chain-load the updated iPXE image from TFTP where each client then reads an embedded script compiled into each unique iPXE file telling it to boot to a specific iSCSI LUN. All of this has been working relatively well with the exception that the only way I found resources to make iPXE w/ embedded script was through Linux and if possible I'd like to stay on the same platform with future installments.

The script itself is a simple document containing 4~5 lines of code:

#!ipxe dhcp set initiator-iqn iqn.2021-11.ipxe.com:lun1 sanboot iscsi:10.0.0.1::::iqn.2021-11.ipxe.com:lun1

I investigated /usr/ports/net/ipxe and was able to compile undionly.kpxe but no combination of make EMBED=script or make IPXE_EMBED=script seems to do the trick...any ideas on how this might be achievable? I have a test network that I can use for experiments.
 
just compile it on linux
should be the same, there is no OS at that point
or just fetch the script from a http server (that works with the ipxe port)
 
just compile it on linux
should be the same, there is no OS at that point
or just fetch the script from a http server (that works with the ipxe port)
The clients are Linux and I only need as many unique undionly.kpxe copies as I have clients/LUNs but I was wondering if it was currently possible on FreeBSD. I found very old forum posts from years ago outlining a process showing it's doable but it seems it's since been discontinued/depreciated. For Linux clients there's a github repo where you can pull the latest version of iPXE. Would you happen to know if there's one for UNIX/FreeBSD?

The thought to use HTTP intrigues me but because I use chain-loading something would still have to tell iPXE to stop chain-loading and query HTTP. If I used a global variable for undionly.kpxe and instead pointed each client to a unique script from HTTP depending on the "Boot Order" DHCP would still either cause a iPXE boot loop or the default un-updated iPXE image on the NIC would immediately go to HTTP without updating iPXE from TFTP.

I don't currently have a workaround for this so HTTP is out of the question unless I can code the DHCP config to only give out the HTTP address after iPXE updates and that I don't know how.
 
i dont know if you can build the latest iPXE on freebsd but if you can compile it on linux it is just as good
the final undionly.kpxe should be the same
dhcpd.conf
Code:
              option root-path "tftp://10.1.1.1/";
                if exists user-class and option user-class = "iPXE" {
                      filename "http://10.1.1.1/boot/rb.php";
                      option root-path "10.1.1.1:/wtf";
                  } elsif option client-architecture = 00:00 {
                      filename "undionly.kpxe";
                  } else {
                      filename "ipxe.efi";
                  }
rb.php
Code:
#!ipxe
  initrd http://10.1.1.1/boot/13/mfbsd.iso
  kernel http://10.1.1.1/boot/memdisk
  imgargs memdisk iso raw
  boot
you can use the example here https://serverfault.com/questions/625071/isc-dhcpd-dynamic-bootfile-name-is-this-possible
to send client mac address to the php/cgi script and return the appropriate ipxe script
 
Back
Top