2. 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
.
3. 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 Follow instructions https://3mdeb.com/app-dev/pxe-server-with-raspberry-pi-1
Raspberry Pi 2 Follow instructions https://blockdev.io/network-booting-a-raspberry-pi-2
Raspberry Pi 3B Follow instructions https://blockdev.io/network-booting-a-raspberry-pi-3/
Raspberry Pi 3B+ Working out of the box
Raspberry Pi 4 TBD, visit https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md
4. Server configuration
Install and configure dnsmasq (for DHCP and TFTP) and nfs:
sudo pacman -S nfs-utils dnsmasq
Create the TFTP and NFS root directories and copy over your
previously built rootfs and boot files.
sudo mkdir -p /srv/nfs
sudo mkdir /srv/tftp
# copy the rootfs
sudo cp -a ${rootfs-directory} /srv/nfs/rootfs
# copy the bootfiles, these are normally the files
you encounter
# in the sdcard boot partition
sudo cp -a ${boofiles-directory} /srv/tftp
Edit cmdline.txt and replace the rootfs parameters with:
root=/dev/nfs
nfsroot=192.168.77.1:/srv/nfs/rootfs,nfsvers=3 rootwait
1
1
2
3
4
5
6
7
1
5. Configure nfs-server
Example /etc/exports configuration
/srv/nfs
192.168.77.0/24(rw,sync,no_subtree_check,no_root_squash)
Edit /etc/nfs.conf and enable udp, nfsv2 (if needed) and nfsv3
as exemplified:
[nfsd]
udp=y
vers2=y
vers3=y
1
1
2
3
4
6. 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:
port=0
interface=usb0
dhcp-
range=192.168.77.2,192.168.77.100,255.255.255.0
pxe-service=0,"Raspberry Pi Boot"
log-dhcp
enable-tftp
tftp-root=/srv/tftp
1
2
3
4
5
6
7
7. 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:
[connection]
id=usb0
uuid=eaa72b36-beef-3367-a17c-43d4597b5123
type=ethernet
autoconnect-priority=-100
permissions=
[ethernet]
duplex=half
mac-address=00:B5:6D:0D:B1:47
mac-address-blacklist=
speed=100
[ipv4]
address1=192.168.77.1/24
dns-search=
ignore-auto-routes=true
method=manual
never-default=true
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=link-local
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
8. 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.
sudo systemctl restart dnsmasq nfs-server
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.
1