Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
iPXE hardware inventory script (from svenx)
# Run a PCI/SMBios/net inventory scan and upload the results. This gives us a
# way of tracking nodes to some extent, leaving us less blind than usual.
# We use the iPXE pciscan command to enumerate the PCI bus. For each device, we
# check the 'header type' register at offset 0x0e. If it's type 0 (endpoint),
# we can read the subsystem vendor and device registers too. Unfortunately, if
# the 7th bit of the header type field is set (0x80), it indicates a
# multi-function device. So to check the type, this bit should be masked out.
# Masking is not possible with iPXE commands, so we have to duplicate some of
# the iseq tests.
# The ${pci/${addr}.offset.length} syntax allows us to fetch arbitrary data
# from the configuration space.
# Ref:
# ${addr:busdevfn} bus:device.function
# ${pci/${addr}.0x00.2} vendor
# ${pci/${addr}.0x02.2} device
# ${pci/${addr}.0x04.2} command
# ${pci/${addr}.0x06.2} status
# ${pci/${addr}.0x09.1} class code: programming interface
# ${pci/${addr}.0x0a.1} class code: subclass
# ${pci/${addr}.0x0b.1} class code: baseclass
# ${pci/${addr}.0x0e.1} header type
# ${pci/${addr}.0x2c.2} subsystem vendor, if header type 0
# ${pci/${addr}.0x2e.2} subsystem device, if header type 0
pciscan addr || goto pciscan_done
iseq ${pci/${addr}.0x0e.1} 00 && param pci:${addr}:${addr:busdevfn} ${pci/${addr}.0x00.2}:${pci/${addr}.0x02.2}:${pci/${addr}.0x2c.2}:${pci/${addr}.0x2e.2}:${pci/${addr}.0x0b.1}:${pci/${addr}.0x0a.1}:${pci/${addr}.0x09.1} ||
iseq ${pci/${addr}.0x0e.1} 80 && param pci:${addr}:${addr:busdevfn} ${pci/${addr}.0x00.2}:${pci/${addr}.0x02.2}:${pci/${addr}.0x2c.2}:${pci/${addr}.0x2e.2}:${pci/${addr}.0x0b.1}:${pci/${addr}.0x0a.1}:${pci/${addr}.0x09.1} ||
iseq ${pci/${addr}.0x0e.1} 01 && param pci:${addr}:${addr:busdevfn} ${pci/${addr}.0x00.2}:${pci/${addr}.0x02.2}:::${pci/${addr}.0x0b.1}:${pci/${addr}.0x0a.1}:${pci/${addr}.0x09.1} ||
iseq ${pci/${addr}.0x0e.1} 81 && param pci:${addr}:${addr:busdevfn} ${pci/${addr}.0x00.2}:${pci/${addr}.0x02.2}:::${pci/${addr}.0x0b.1}:${pci/${addr}.0x0a.1}:${pci/${addr}.0x09.1} ||
iseq ${pci/${addr}.0x0e.1} 02 && param pci:${addr}:${addr:busdevfn} ${pci/${addr}.0x00.2}:${pci/${addr}.0x02.2}:::${pci/${addr}.0x0b.1}:${pci/${addr}.0x0a.1}:${pci/${addr}.0x09.1} ||
iseq ${pci/${addr}.0x0e.1} 82 && param pci:${addr}:${addr:busdevfn} ${pci/${addr}.0x00.2}:${pci/${addr}.0x02.2}:::${pci/${addr}.0x0b.1}:${pci/${addr}.0x0a.1}:${pci/${addr}.0x09.1} ||
goto pciscan_loop
clear addr
param smbios:uuid ${smbios/uuid}
param smbios:asset ${smbios/asset}
param smbios:board-serial ${smbios/board-serial}
param smbios:manufacturer ${smbios/manufacturer}
param smbios:product ${smbios/product}
param smbios:serial ${smbios/serial}
param net:busid ${netX/busid}
param net:busloc ${netX/busloc}
param net:bustype ${netX/bustype}
param net:mac ${netX/mac}
param net:ip ${netX/ip}
param net:netmask ${netX/netmask}
param net:gateway ${netX/gateway}
param net:dns ${netX/dns}
param net:hostname ${netX/hostname}
param net:domain ${netX/domain}
param net:dhcp-server ${netX/dhcp-server}
param net:next-server ${netX/next-server}
param net:filename ${netX/filename}
imgfetch ${baseurl}/ ||
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.