Tuesday, 16 November 2021

How to configure PXE network boot on Raspberry Pi or a general computer?

PXE network boot is becoming a very powerful tool nowadays. It can be used for setting up a large cluster of identical-purpose computers (e.g., computer access room for students); it can also be used to boot into a selected image for small Internet-based devices, e.g., Raspberry Pi running Raspbian, Ubuntu, RetroPie, Batocera, Lakka, Recalbox, Manjaro, Gentoo, or etc. You don't have to buy many big microSD cards, one for each image, neither do you need to flash the image onto the microSD card every time.

The setup process involves two sides, server side (for hosting the image) and client side (for PXE booting into the hosted image via network).


Server side:

1. Configure the DHCP server to tell the boot server's IP address. Add the following line into /etc/dnsmasq.conf and restart dnsmasq service

dhcp-boot=kernel8.img,192.168.50.2

 where kernel8.img is the Stage-1 boot image file (such as grubnetx64.efi.signed, grubx64.efi, bootmgr.efi); 192.168.50.2 is the TFTP server IP address (see below).

2. Host PXE boot folder using TFTP. Install and start tftpd-hpa, its configuration file is in /etc/default/tftpd-hpa . You can set the TFTP root folder location which contains the boot directory including the boot image file.

 Most of the time, the machine that hosts DHCP server can also host TFTP (since TFTP is a built-in feature of dnsmasq), so Step 1 and 2 can be combined, you can specify tftp-root in /etc/dnsmasq.conf, and the IP address field in dhcp-boot can be left out. Take note that all routers host a DHCP server by themselves, so if there are more than one DHCP servers in the same network, it might cause IP conflict.

3. Host operating system's root folder (e.g. /nfs/rootfs) and boot folder (e.g., /nfs/boot) using NFS

4. Modify /nfs/boot/cmdline.txt , append the string root=/dev/nfs nfsroot=192.168.50.2:/nfs/boot,vers=3 rw ip=dhcp onto the same line, this is to ask the kernel to load root filesystem from NFS instead of from local storage

5. Modify /etc/fstab in the hosted root filesystem to mount NFS as root instead of /dev/sd* or /dev/nvm*, etc.

 

Client side:

1. Set boot order. You must configure the boot order in BIOS (for PC) or eeprom (for Raspberry Pi) to boot from PXE if previous boot options all fail.

 1a. On Raspberry Pi, extract boot config info by running:

  cd /lib/firmware/raspberrypi/bootloader/stable/
rpi-eeprom-config
pieeprom-2021-07-06.bin > bootconf.txt 

 1b. Edit bootconf.txt, change BOOT_ORDER to at least 0x21, preferably 0x0365421

 1c. Generate updated EEPROM image by running:

  rpi-eeprom-config --out netboot-pieeprom-2021-07-06.bin --config bootconf.txt pieeprom-2021-07-06.bin

 1d. Flash the updated EEPROM image to EEPROM:

  rpi-eeprom-update -d -f netboot-pieeprom-2021-07-06.bin


2. You must make sure PXE network boot is currently the first available boot option (by plugging out hard-disks or microSD cards if their boot order is prior to PXE netboot)

No comments:

Post a Comment