PXE boot over Ethernet

You can also boot your Raspberry Pi from you NAS drive I use Synology DS420+ and PfSense to manage my DHCP server options. You can not manage DHCP from your standard router.

This is only working with ethernet cabel connected not over wifi.

And here how to do this.

Synology NAS configuration. Create 2 shared folders in Synology control panel shared folders. “rpi-pxe” and “rpi-tftpboot”.

rpi-pxe” for the root image of the sd card.
rpi-tftpboot” for the boot image of the sd card.

Share this 2 folder with NFS so you can mount them on Raspberry Pi. IP * all devices are allowed to mount the share for read and write. Do this for both folders.

Now set the TFTP server in services. Importend here is TFTP must be rpi-tftpboot the folder for the boot image of the sd card. That’s all what you have to do on Synology. DHCP will I manage on PfSense. You can also use Synology as DHCP server if you like to do this.

On PfSense must we define the DHCP option 66 (TFTP server) so the Raspberry Pi can find the TFTP server on boot. Go to services – DHCP server in PfSense and in my case 192.168.0.11 is my TFTP server on Synology. Restart the DHCP server on PfSense. That is all to do on PfSense.

Now to the Raspberry Pi here you need an sd card but only to get started. Image the OS to the SD card use the headless description and log in to your Raspberry Pi with ssh.

Find the serial number of your Raspberry Pi with this command.
vcgencmd otp_dump | grep 28: | sed s/.*://g

My serial number is “f36b81a4”.

Install NFS common tools.
sudo apt install nfs-common

Change the boot order in raspi-config.
sudo raspi-config

We have to change the boot order on so we can start Raspberry Pi without sd card over network. The Raspberry Pi will reboot to make this change.

Create a folder in “rpi-pxe” with the hostname. My Raspberry Pi has the name RPI2GB. And a folder in “rpi-tftpboot” with the serialnumber name.

Now we have to mount the NAS drive to the Raspberry Pi to copy the boot image and the root image over to the NAS.

sudo mkdir /nfs
sudo chmod 777 /nfs
sudo mkdir /nfs/boot /nfs/root
sudo chmod 777 /nfs/boot /nfs/root

sudo mount -t nfs -o proto=tcp,port=2049 192.168.0.11:/volume1/rpi-tftpboot/f36b81a4 /nfs/boot
sudo mount -t nfs -o proto=tcp,port=2049 192.168.0.11:/volume1/rpi-pxe/RPI2GB /nfs/root
sudo chmod 777 /nfs/boot /nfs/root

This will create the folder /nfs/root and /nfs/boot and mount your NAS. “rpi-tftpboot” to /nfs/boot and “rpi-pxe” to /nfs/root.

You can use write a file to /nfs/root and /nfs/boot to see if the mount is ok before you continue. I use the “touch /nfs/root/x” and “touch /nfs/boot/x” to make an this test file.

Now we have to copy /boot to /nfs/boot and / to /nfs/root on the NAS. The boot is fast root take some minutes here I have excluded our mount folders.

sudo rsync -av /boot/* /nfs/boot
sudo rsync -av --exclude '/nfs' / /nfs/root

Some files/attrs were not transferred but this is ok.

sudo nano /nfs/boot/cmdline.txt

And here change the first line to this one – this is one line you have to change the ip to your nfsroot server (TFTP server) and the hostname.

console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=192.168.0.11:/volume1/rpi-pxe/RPI2GB rw ip=dhcp elevator=deadline rootwait

Now we have to change fstab so our Raspberry Pi can find the right boot folder on the NAS.

sudo nano /nfs/root/etc/fstab

This must be added and the PARTUUID must be changed to #PARTUUID to disable them. Also here change the ip to your TFTP server, the serialnumber and the hostname.

192.168.0.11:/volume1/rpi-tftpboot/f36b81a4 /boot nfs defaults 0 2
192.168.0.11:/volume1/rpi-pxe/RPI2GB / nfs defaults,noatime 0 1

sudo shutdown now

Stop your Raspberry Pi with shutdown and take the sd card out. Check you NAS that you have files in “rpi-exe/RPI2GB” and in “rpi-tftpboot/f36b81a4”.

Take out your sd card and start the Raspberry Pi again – now it will boot over network from your NAS.

On the NAS can you make snapshots and take backup of your Raspberry Pi you can also access the files from Windows and edit them if you need this.