Skip to content

Instantly share code, notes, and snippets.

@andrearug
Forked from robinsmidsrod/_README.md
Created May 1, 2018 01:45
Show Gist options
  • Save andrearug/46d6d4cc1c5120a1d25cd8397f657a40 to your computer and use it in GitHub Desktop.
Save andrearug/46d6d4cc1c5120a1d25cd8397f657a40 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 ..
#!ipxe
:menu
menu Network boot options for ${uuid}
item --key d all Try to boot (a)ll adapters in turn
item
item --gap -- --- Detected network adapters ---
ifopen net0 && goto setup-net0 || ifclose net0 ||
:menu-net1
ifopen net1 && goto setup-net1 || ifclose net1 ||
:menu-net2
ifopen net2 && goto setup-net2 || ifclose net2 ||
:menu-net3
ifopen net3 && goto setup-net3 || ifclose net3 ||
:menu-bottom
item
item --gap -- --- Alternatives ---
item --key s shell Drop to iPXE (s)hell
item --key x exit E(x)it and continue BIOS boot order
choose --timeout 2000 --default all selected && goto ${selected} || goto default
goto menu
:setup-net0
item --key 0 net0 Boot adapter (0): ${net0/busid} - ${net0/mac}
ifclose net0 ||
goto menu-net1
:setup-net1
item --key 1 net1 Boot adapter (1): ${net1/busid} - ${net1/mac}
ifclose net1 ||
goto menu-net2
:setup-net2
item --key 2 net2 Boot adapter (2): ${net2/busid} - ${net2/mac}
ifclose net2 ||
goto menu-net3
:setup-net3
item --key 3 net3 Boot adapter (3): ${net3/busid} - ${net3/mac}
ifclose net3 ||
goto menu-bottom
:shell
shell
goto menu
:exit
exit
:all
:default
goto autoboot
:net0
ifopen net0
dhcp net0
set nic net0
goto specific
:net1
ifopen net1
dhcp net1
set nic net1
goto specific
:net2
ifopen net2
dhcp net2
set nic net2
goto specific
:net3
ifopen net3
dhcp net3
set nic net3
goto specific
:specific
set use-cached 1
:autoboot
autoboot
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment