Raspberry Pi PXE Boot – Network booting a Pi 4 without an SD card

Install Raspbian on an SD card and install needed tools

Let’s start configuring your client system for netboot. This is the Raspberry Pi that will eventually boot without a micro SD card installed.

  • Download PiOS Lite. For this tutorial I used the Bullseye release.
  • Copy the Bullseye image onto an SD card. I suggest using the PiOS Imager. Warning! This will overwrite data on the device specified. Triple check you are writing to the SD card and not your laptop drive!
  • Put the SD card in your client Raspberry Pi 4 and boot it. Using the lite version of raspbian give you a text console only. If you want a graphical console you can use the full version and it should work. I have not tested this workflow with the full version.
  • Log in via the console using the login you created with the Imager.
  • Connect your Raspberry Pi to the internet via an ethernet cable.
  • Update PiOS via apt-get and install the rpi-config program:

sudo apt-get update
sudo apt-get full-upgrade
sudo apt-get install rpi-eeprom

Configure the Rasperry Pi 4 bootloader to PXE boot

Next lets examine your boot loader configuration using this command:

vcgencmd bootloader_config

Here is the output on my fresh out of the box Raspberry Pi 4:

pi@raspberrypi:~ $ vcgencmd bootloader_config
 BOOT_UART=0
 WAKE_ON_GPIO=1
 POWER_OFF_ON_HALT=0
 FREEZE_VERSION=0

We need to modify the boot loader config to boot off the network using the BOOT_ORDER parameter. To do that we must extract it from the EEPROM image. Once extracted, make our modifications to enable PXE boot. Finally install it back into the boot loader.

We do that with these steps:

  • Go to the directory where the bootloader images are stored:
cd /lib/firmware/raspberrypi/bootloader/stable
  • Make a copy of the latest firmware image file. In my case it was pieeprom-2023-05-11.bin:
cp pieeprom-2023-05-11.bin new-pieeprom.bin
  • Extract the config from the eeprom image
rpi-eeprom-config new-pieeprom.bin > bootconf.txt
  • In bootconf.txt, change the BOOT_ORDER variable to BOOT_ORDER=0xf241. In my case it had defaulted to BOOT_ORDER=0x1. 0X1 means only boot from SD card. 0xf241 means attempt SD card boot first, followed by USB Mass Storage Device, followed by network boot, and then repeat. See this Raspberry Pi Bootloader page for more details on the values and what they control.
  • Now save the new bootconf.txt file to the firmware image we copied earlier:
rpi-eeprom-config --out netboot-pieeprom.bin --config bootconf.txt new-pieeprom.bin
  • Now install the new boot loader:
sudo rpi-eeprom-update -d -f ./netboot-pieeprom.bin
  • If you get an error with the above command, double check that your apt-get full-upgrade completed successfully.
Then use cat /proc/cpuinfo to get the serial number of the Pi.

Reference
https://linuxhit.com/raspberry-pi-pxe-boot-netbooting-a-pi-4-without-an-sd-card