iPXE script to boot from certain interface based on busid

We built network wireshark appliances that are diskless and boot Linux (Debian) from the network.  We can deploy these appliances very quickly with little setup.  The appliances have 6 ethernet interfaces (2 on motherboard and 4 on NIC).  We use one interface to boot the system, and the rest are used to monitor network traffic (SPAN).

The problem we ran into is that depending on which NIC we used, iPXE would enumerate the ethernet interfaces differently.  So, we could not guarantee that “net0” is the name of the port we wanted to boot from.  Sometimes, it was “net1” or “net2” depending on the NICs we used.  To solve this issue, we  used a variable that iPXE provides “netX/busid” where X is a number, in our case 0 to 5, and matched on that to determine which “netX” we should boot from.  The following is the iPXE script that we embed:

 

#!ipxe
set mybusid 01:80:86:10:9a

:retry_dhcp
iseq ${net0/busid} ${mybusid} || goto try_a
dhcp net0 || goto retry_dhcp
set macboot ${net0/mac}
goto gotip

:try_a
iseq ${net1/busid} ${mybusid} || goto try_b
dhcp net1 || goto retry_dhcp
set macboot ${net1/mac}
goto gotip

:try_b
iseq ${net2/busid} ${mybusid} || goto try_c
dhcp net2 || goto retry_dhcp
set macboot ${net2/mac}
goto gotip

:try_c
iseq ${net3/busid} ${mybusid} || goto try_d
dhcp net3 || goto retry_dhcp
set macboot ${net3/mac}

:try_d
iseq ${net4/busid} ${mybusid} || goto try_e
dhcp net4 || goto retry_dhcp
set macboot ${net4/mac}

:try_e
iseq ${net5/busid} ${mybusid} || goto retry_dhcp
dhcp net5 || goto retry_dhcp
set macboot ${net5/mac}

:gotip
echo Booting from http://ipxe.mycompany.edu/boot.asp
chain http://ipxe.mycompany.edu/boot.asp?mac=${macboot} ||
echo .
echo .
prompt –key 0x03 –timeout 25000 Press Ctrl-C for the iPXE shell… || reboot
echo .
echo .
shell

Permanent link to this article: https://daherlabs.mywire.org/wordpress/?p=47

1 comment

  1. Inspiring story there. What occurred after? Take care!

Leave a Reply

Your email address will not be published.