5

I have a linux machine which was booted via PXE. Can I determine the network interface which was used for booting?

2 Answers 2

6

If assume you're using PXELINUX.

There's a flag IPAPPEND; if you set it to 2, it should cause PXELINUX to append a parameter BOOTIF=<hardware-address-of-boot-interface> to your kernel command line. Then you've got the MAC address, which you can use to identify the used interface.

http://www.syslinux.org/wiki/index.php/SYSLINUX#IPAPPEND_flag_val_.5BPXELINUX_only.5D

0

I have used PXELINUX with IPAPPEND=2 for years. But I recently had to switch to EFI PXE boot, where most people seem to prefer GRUB to PXELINUX.

The GRUB EFI PXE bootloader defines a $net_default_mac variable that contains the MAC address of the boot interface. You can use this to add the MAC address to your kernel command line, but it differs from the PXELINUX IPAPPEND=2 value in two ways:

  1. It does not include the hardware type prefix byte (01 = Ethernet)
  2. It uses colons to separate octets instead of dashes (e.g. ba:98:76:54:32:10 instead of 01-ba-98-76-54-32-10)

We have some scripts that expect the PXELINUX BOOTIF format, so I wanted to replicate that in the GRUB configuration.

Unfortunately, GRUB's text manipulation functions seem to be nearly non-existent. I would up using the regexp command like so:

set dd="[0-9a-f][0-9a-f]"

regexp --set 1:o1 --set 2:o2 --set 3:o3 --set 4:o4 --set 5:o5 --set 6:o6 \
    ($dd):($dd):($dd):($dd):($dd):($dd) \
    $net_default_mac

set hwaddr="01-$o1-$o2-$o3-$o4-$o5-$o6"

menuentry  'My Linux' --class fedora --class gnu-linux --class gnu --class os {
   linuxefi my-kernel-image BOOTIF=$hwaddr
   initrdefi my-initramfs.img
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .