ergosteur

ergosteur / pxe-netbootxyz.sh

Last active 1 month ago

Like 0

BIOS and UEFI PXE configuration script for dnsmasq on Unifi Cloud Gateway

Revision f5fdf8d85b1240395bb61113316f289bed850bf3

pxe-netbootxyz.sh Raw
1#!/bin/sh
2#
3# Regenerate UniFi PXE override for netboot.xyz - with BIOS and UEFI support
4# Run at boot using on-boot-script-2.x
5# (see https://github.com/unifi-utilities/unifios-utilities/tree/main/on-boot-script-2.x)
6# for Ubiquiti UCG Fiber
7#
8
9OUT="/run/dnsmasq.dhcp.conf.d/99-pxe-netbootxyz.conf"
10
11# Wait until UniFi has generated DHCP configs
12i=0
13while [ ! -d /run/dnsmasq.dhcp.conf.d ] && [ $i -lt 30 ]; do
14 sleep 1
15 i=$((i+1))
16done
17
18cat > "$OUT" << 'EOF'
19# ==========================================================
20# 99-pxe-netbootxyz.conf
21# UniFi-safe PXE override for MY_LAN (br20)
22#
23# Explicitly overrides UniFi-generated dhcp-boot
24# Works with BIOS, UEFI, and UEFI64 clients
25# ==========================================================
26
27log-dhcp
28
29# ----------------------------------------------------------
30# Architecture detection (RFC 4578)
31# ----------------------------------------------------------
32# 0 = Legacy BIOS
33# 7 = UEFI (IA32)
34# 9 = UEFI64 (x86_64)
35
36dhcp-match=set:BIOS,option:client-arch,0
37dhcp-match=set:UEFI,option:client-arch,7
38dhcp-match=set:UEFI64,option:client-arch,9
39
40# ----------------------------------------------------------
41# Optional: detect iPXE (future use)
42# ----------------------------------------------------------
43dhcp-userclass=set:ipxe,iPXE
44
45# ----------------------------------------------------------
46# VLAN tag (UniFi autogenerated)
47# ----------------------------------------------------------
48# net_MY_LAN_br20_10-20-28-0-22
49# ----------------------------------------------------------
50# VLAN tag notes (UniFi autogenerated)
51#
52# UniFi creates one dnsmasq tag per network in the form:
53# net_<NAME>_<bridge>_<subnet>
54#
55# To discover available tags, run on the gateway:
56# grep -R "dhcp-range=set:net_" /run/dnsmasq.dhcp.conf.d/
57#
58# Example output:
59# dhcp-range=set:net_MY_LAN_br20_10-20-28-0-22,...
60# dhcp-range=set:net_GuestNet_br4001_192-168-28-0-24,...
61#
62# Use the FULL tag string (exact match) in dhcp-boot lines
63# to scope PXE behavior to that specific network only.
64# ----------------------------------------------------------
65
66# ----------------------------------------------------------
67# BIOS clients -> chainload iPXE (kpxe)
68# ----------------------------------------------------------
69dhcp-boot=tag:net_MY_LAN_br20_10-20-28-0-22,tag:BIOS,netboot.xyz.kpxe,,10.20.28.219
70
71# ----------------------------------------------------------
72# UEFI / UEFI64 clients -> native EFI loader
73# ----------------------------------------------------------
74dhcp-boot=tag:net_MY_LAN_br20_10-20-28-0-22,tag:UEFI,netboot.xyz.efi,,10.20.28.219
75dhcp-boot=tag:net_MY_LAN_br20_10-20-28-0-22,tag:UEFI64,netboot.xyz.efi,,10.20.28.219
76
77# ----------------------------------------------------------
78# Safety net: explicit 66/67 for noisy firmware
79# ----------------------------------------------------------
80dhcp-option=tag:net_MY_LAN_br20_10-20-28-0-22,tag:BIOS,66,10.20.28.219
81dhcp-option=tag:net_MY_LAN_br20_10-20-28-0-22,tag:BIOS,67,"netboot.xyz.kpxe"
82
83dhcp-option=tag:net_MY_LAN_br20_10-20-28-0-22,tag:UEFI,66,10.20.28.219
84dhcp-option=tag:net_MY_LAN_br20_10-20-28-0-22,tag:UEFI,67,"netboot.xyz.efi"
85
86dhcp-option=tag:net_MY_LAN_br20_10-20-28-0-22,tag:UEFI64,66,10.20.28.219
87dhcp-option=tag:net_MY_LAN_br20_10-20-28-0-22,tag:UEFI64,67,"netboot.xyz.efi"
88EOF
89
90# Reload dnsmasq cleanly
91if [ -f /run/dnsmasq-main.pid ]; then
92 kill -HUP "$(cat /run/dnsmasq-main.pid)"
93fi
94
95exit 0