Autoboot without a DHCP-supplied boot path

gPXE can be built with an embedded image, which might be a script. That script might look like this:

dhcp net0
chain url://for.your/boot/script.gpxe

That is, obtain an IP address through DHCP on the first network interface and then load and run another script from a specific URL. However, if a network connection is only available on some other interface, dhcp net0 will fail and the script will stop executing.

gPXE also has an autoboot command, which tries to scan all the network interfaces to obtain an IP address and then boot from the server and path specified in the DHCP reply.

By patching the gPXE source code, one can however use autoboot as a more flexible dhcp command, ignoring the DHCP boot options. This is how:

Go into src/usr/autoboot.c and find the netboot() function. In that function there is a line “route();”. After that line, add “return 0;”. This causes autoboot to return when it has obtained a DHCP lease so that the next command is run.

Go into src/hci/commands/autoboot_cmd.c and find the line “/* Can never return success by definition */”. Change the following line from “return 1;” to “return 0;”.

Now build your patched gPXE with the following embedded script:

chain url://for.your/boot/script.gpxe

You now have a patched gPXE that will obtain a DHCP lease on any network interface and then load the script from the specified URL, ignoring the DHCP boot options.

This method is of course a hack which will likely be obsoleted by scripting language improvements in the future.

QR Code
QR Code appnotes:autobootchainurl (generated for current page)