Skip to content

Instantly share code, notes, and snippets.

@crwolff
Last active July 18, 2024 18:16
Show Gist options
  • Save crwolff/d120d7b673618befdf2cd11b828e73b5 to your computer and use it in GitHub Desktop.
Save crwolff/d120d7b673618befdf2cd11b828e73b5 to your computer and use it in GitHub Desktop.
Netboot Raspberry Pi 3B+

Router

Setup router to redirect TFTP to main server

$ cat /jffs/configs/dnsmasq.conf.add 
dhcp-boot=pxelinux,[IP Address],[IP Address]

This should be the following, but it doesn't work right with the Pi

$ cat /jffs/configs/dnsmasq.conf.add 
dhcp-boot=pxelinux,[Hostname],[IP Address]

Setup tftpd-hpa

$ cat tftpd-hpa 
# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"

Setup NFS server

$ cat /etc/exports 
# /etc/exports: the access control list for filesystems which may be exported
#		to NFS clients.  See exports(5).
#
/srv/nfs/raspi3 *(rw,sync,no_subtree_check,no_root_squash)

Unpack Raspios image into /srv/nfs

Download from http://downloads.raspberrypi.org/

unxz 2024-07-04-raspios-bookworm-armhf.img.xz
sudo kpartx -a -v 2024-07-04-raspios-bookworm-armhf.img
mkdir rootmnt
mkdir bootmnt
sudo mount /dev/mapper/loop0p2 rootmnt/
sudo mount /dev/mapper/loop0p1 bootmnt/
sudo mkdir -p /srv/nfs/raspi3
sudo cp -a rootmnt/* /srv/nfs/raspi3/
sudo cp -a bootmnt/* /srv/nfs/raspi3/boot/firmware/
sudo umount bootmnt rootmnt
sudo kpartx -d `pwd`/2024-07-04-raspios-bookworm-armhf.img

Fixup Pi filesystem for network operation

sudo sed -i /UUID/d /srv/nfs/raspi3/etc/fstab
echo "console=serial0,115200 console=tty root=/dev/nfs nfsroot=[IP Address]:/srv/nfs/raspi3,vers=3 rw ip=dhcp rootwait elevator=deadline modprobe.blacklist=bcm2835_v4l2" | sudo tee /srv/nfs/raspi3/boot/firmware/cmdline.txt

Find serial number for Pi and create directory for it

Used to be last 4 bytes of MAC (45:67:89:ab:cd:ef -> 89abcdef), may have to boot from SD card and extract with vcgencmd
sudo mkdir -p /srv/tftp/89abcdef

Copy files for network boot

Also required after update that installs new kernel. Maybe 'rsync -av --delete'?

sudo cp /srv/nfs/raspi3/boot/firmware/bootcode.bin /srv/tftp/
sudo cp /srv/nfs/raspi3/boot/firmware/* /srv/tftp/89abcdef/

It takes approximately 30 seconds before the bootp protocol begins and an additional 15 seconds for the splash screen to appear.

First boot requires keyboard and monitor to perform initial configuration

Credit

Based on https://ian.bebbs.co.uk/posts/NetworkBootingManyRaspberryPis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment