Pxe Network Booting The Raspberry Pi
While developing using Yocto and using a Raspberry Pi 3B+ I was finding it very inefficient to flash an sd card over again. I knew I could leverage the bootloader to network boot but I gladly found out that by using PXE you can network boot without an sd card. For this you will need:
- A device running Linux that supports dnsmasq and nfs
- A compatible Raspberry Pi (see following table)
- An ethernet connection between the server and the Pi
You can boot multiple Raspberries albeit with some limitations. For the server I will be using my laptop powered by Arch Linux .
Raspberry Pi (client) Setup
The following table summarises the support of your device depending on its model.
Raspberry Pi Model | PXE Support/Configuration |
---|---|
Raspberry Pi 1 | here |
Raspberry Pi 2 | here |
Raspberry Pi 3B | here |
Raspberry Pi 3B+ | Working out of the box |
Raspberry Pi 4 | here |
Server configuration
Install and configure dnsmasq (for DHCP and TFTP) and nfs:
Create the TFTP and NFS root directories and copy over your previously built rootfs and boot files.
Edit cmdline.txt
and replace the rootfs parameters with:
Configure nfs-server
Example /etc/exports
configuration
Edit /etc/nfs.conf
and enable udp, nfsv2 (if needed) and nfsv3 as exemplified:
Configure dnsmasq
PXE, TFTP and DHCP are handed by dnsmasq. Be sure you have control over the network and aren't colliding with existing services. In my case I am using a usb to ethernet converter hooked up to a switch to which I connect the raspberries.
Example /etc/dnsmasq.conf
configuration:
Network configuration
Set up your NIC with a static address. If you are using NetworkManager you have a number of front-ends including the cli tools nmcli
and nmtui
, as an example my network configuration file /etc/NetworkManager/system-connections/usb0.nmconnection
looks like:
Final Steps
Restart the services, check their status to make sure there was no configuration error and if it doesn't work you can always fire up wireshark and debug it. If that doesn't help feel free to leave a comment below.
Limitations
This scheme isn't safe to use with multiple devices without built-in measures to the rootfs. I am curious if this can be dealt with server side, let me know in the comments if you have any idea.