PXE Boot

PXE Boot #

Einführung #

Als Preboot eXecution Environment (PXE) wird eine Technik bezeichnet, die es ermöglicht, über das Netzwerk beliebigen ausführbaren Code oder auch Nutzdaten zu verteilen. Dies kann zum Beispiel genutzt werden, um Notfallsysteme oder Installationsmedien ohne USB-Stick zur Verfügung zu haben.

Setup eines PXE Servers #

Folgende Software wird benötigt:

  • DHCP-Server (dhcpd, dnsmasq)
  • TFTP-Server (tftp-hpa, dnsmasq)
  • NFS-Server / HTTP Server (nfs-server, nginx, darkhttpd)
  • Bootloader (syslinux)

Der Client, der gebootet werden soll, muss eine PXE-fähige Netzwerkkarte haben. Der PXE Code führt dann zuerst über DHCP eine Konfiguration der Schnittstelle durch und erhält damit auch die erweiterten Informationen wie die TFTP Server- und Bootloaderdatei Adresse. Im Anschluss kann der Client das initiale Network Bootstrap Program (NBP) laden und im Arbeitsspeicher ausführen. Ein mögliches Bootloaderprogramm ist PXELinux.

sequenceDiagram participant C as PXE-Client participant S as DHCP-Server (PXE-fähig) participant T as TFTP-Server C->>+S: Extended DHCP Discover Port 67 S-->>-C: Extended DHCP Offer Port 68 C->>+S: DHCP Request Port 67 S-->>-C: DHCP Boot Ack. Reply Port 68 C->>+S: Boot Service Discover Port 67 oder 4011 S-->>-C: Boot ServiceAck. Reply Port 67 oder 4011 C->>+T: Bootstrap Program Download Request Port 69 T-->>-C: Bootstrap Program Download Port 69

Proxy DHCP #

Da der DHCP Server nicht immer unter der Kontrolle des Entwicklers ist, wird die Proxy DHCP Lösung benötigt. Dazu wird zum herkömmlichen DHCP Austausch noch ergänzende Informationen vom Proxy DHCP Server gesendet.

Beispiel Setup #

In diesem Beispiel wird Syslinux direkt vom Archlinux Iso verwendet.

Es werden 4 Images konfiguriert (2 Mal Archlinux, Clonezilla)

Dateistruktur #

Die ISO-Datei soll gemountet werden und daraus werden dann die nötigen Dateien kopiert. Der Syslinux Ordner wird der Root-Ordner. Anschliessend wird im Root-Ordner ein Verzeichnis angelegt, wo die Images (z.B. Clonezilla, Archlinux etc.) abgelegt werden sollen.

tftp
├── hdt
├── images
│   ├── arch
│   │   ├── boot
│   │   │   ├── x86_64
│   │   │   │   ├── initramfs-linux.img
│   │   │   │   └── vmlinuz-linux
│   │   ├── x86_64
│   │   │   ├── airootfs.sfs
│   │   │   ├── airootfs.sfs.sig
│   │   │   └── airootfs.sha512
│   ├── archlinux-2021.06.01-x86_64.iso
│   └── clonezilla-live-2.7.2-39-amd64.iso
├── archiso_head.cfg
├── archiso_pxe.cfg
├── archiso_pxe-linux.cfg
├── archiso_sys.cfg
├── archiso_sys-linux.cfg
├── archiso_tail.cfg
├── lpxelinux.0
├── splash.png

DHCP Server #

interface=vboxnet0
listen-address=192.168.56.1
dhcp-range=192.168.56.10,192.168.56.30,12h
dhcp-option-force=209,syslinux.cfg
dhcp-boot=lpxelinux.0
enable-tftp
tftp-root=/mnt/tftp
log-dhcp

Syslinux Config #

syslinux.cfg #

DEFAULT select

LABEL select
COM32 whichsys.c32
APPEND -pxe- pxe -sys- sys -iso- sys

LABEL pxe
CONFIG archiso_pxe.cfg

LABEL sys
CONFIG archiso_sys.cfg

archiso_pxe.cfg #

INCLUDE archiso_head.cfg

INCLUDE archiso_pxe-linux.cfg

INCLUDE archiso_tail.cfg

archiso_head.cfg #

SERIAL 0 115200
UI vesamenu.c32
MENU TITLE Arch Linux
MENU BACKGROUND splash.png

MENU WIDTH 78
MENU MARGIN 4
MENU ROWS 7
MENU VSHIFT 10
MENU TABMSGROW 14
MENU CMDLINEROW 14
MENU HELPMSGROW 16
MENU HELPMSGENDROW 29

# Refer to http://syslinux.zytor.com/wiki/index.php/Doc/menu

MENU COLOR border       30;44   #40ffffff #a0000000 std
MENU COLOR title        1;36;44 #9033ccff #a0000000 std
MENU COLOR sel          7;37;40 #e0ffffff #20ffffff all
MENU COLOR unsel        37;44   #50ffffff #a0000000 std
MENU COLOR help         37;40   #c0ffffff #a0000000 std
MENU COLOR timeout_msg  37;40   #80ffffff #00000000 std
MENU COLOR timeout      1;37;40 #c0ffffff #00000000 std
MENU COLOR msg07        37;40   #90ffffff #a0000000 std
MENU COLOR tabmsg       31;40   #30ffffff #00000000 std

MENU CLEAR
MENU IMMEDIATE

archiso_pxe-linux.cfg #


# Entpacktes ISO, es wird ein HTTP Server benötigt
LABEL arch64_http
TEXT HELP
Boot the Arch Linux live medium using HTTP.
It allows you to install Arch Linux or perform system maintenance.
ENDTEXT
MENU LABEL Arch Linux install medium (x86_64, HTTP)
LINUX /images/arch/boot/x86_64/vmlinuz-linux
INITRD /images/arch/boot/intel-ucode.img,/images/arch/boot/amd-ucode.img,/images/arch/boot/x86_64/initramfs-linux.img
APPEND archisobasedir=/images/arch archiso_http_srv=http://${pxeserver}/ checksum verify
SYSAPPEND 3

# ISOs
LABEL arch-iso
LINUX memdisk
INITRD /images/archlinux-2021.06.01-x86_64.iso
APPEND iso

LABEL clonezilla-iso
LINUX memdisk
INITRD /images/clonezilla-live-2.7.2-39-amd64.iso
APPEND iso

archiso_tail.cfg #

LABEL existing
TEXT HELP
Boot an existing operating system.
Press TAB to edit the disk and partition number to boot.
ENDTEXT
MENU LABEL Boot existing OS
COM32 chain.c32
APPEND hd0 0

# http://www.memtest.org/
LABEL memtest
MENU LABEL Run Memtest86+ (RAM test)
LINUX /arch/boot/memtest

# http://hdt-project.org/
LABEL hdt
MENU LABEL Hardware Information (HDT)
COM32 hdt.c32
APPEND modules_alias=hdt/modalias.gz pciids=hdt/pciids.gz

LABEL reboot
TEXT HELP
Reboot computer.
The computer's firmware must support APM.
ENDTEXT
MENU LABEL Reboot
COM32 reboot.c32

LABEL poweroff
TEXT HELP
Power off computer.
The computer's firmware must support APM.
ENDTEXT
MENU LABEL Power Off
COM32 poweroff.c32
Calendar December 26, 2021