Skip to content

Instantly share code, notes, and snippets.

@robinsmidsrod
Last active March 30, 2024 06:13
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save robinsmidsrod/3871687 to your computer and use it in GitHub Desktop.
Save robinsmidsrod/3871687 to your computer and use it in GitHub Desktop.
Embedded iPXE menu to choose which network adapter to boot from (autodetects up to 10 adapters)

Go into your git checkout folder of ipxe.

Save the below file as nic-menu.ipxe.

Build iPXE like this:

cd src && make EMBED=../nic-menu.ipxe && cd ..

Requirements: current iPXE as of 2013-08-01 (for proper behavior of autoboot with a network device specified, netX feature, PCI vendor/device ID display and inc command)

#!ipxe
set timeout 1000
:menu
menu Network boot options for ${uuid}
item --key a default Try to boot (a)ll network adapters in turn
item
item --gap -- --- Detected network adapters ---
set i:int8 0
:loop
ifopen net${i} && item --key ${i} net${i} net(${i}): ${netX/mac} - ${netX/bustype} ${netX/busloc:busdevfn} ${pci/${netX/busloc}.0.2}:${pci/${netX/busloc}.2.2} ${netX/chip} ; ifclose
inc i
iseq ${i} 10 || goto loop
item
item --gap -- --- Alternatives ---
item --key c config Open (c)onfiguration
item --key r reboot (R)eboot computer
item --key s shell Drop to iPXE (s)hell
item --key x exit E(x)it and continue BIOS boot order
choose --timeout ${timeout} selected && goto select || goto default
goto menu
:select
isset ${${selected}/mac} && goto nic || goto label
:nic
autoboot ${selected} && goto exit ||
echo Booting '${selected}' failed, exiting iPXE...
goto exit
:label
goto ${selected} ||
echo The label '${selected}' could not be found, returning to menu...
sleep 2
goto restart
:default
autoboot && goto exit ||
echo Booting failed, exiting iPXE...
goto exit
:config
config
goto restart
:shell
shell
goto restart
:restart
set timeout 0
goto menu
:reboot
reboot
:exit
echo Continuing BIOS boot order...
sleep 1
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment