Network Boot Raspberry Pi

This is a post is meant for myself.

Prepare tftp boot folder

$ sudo mkdir /mnt/<tftpboot>
$ sudo mount -t nfs <ip_of_NAS>:/volume1/<tftpboot> /mnt/<tftpboot>
$ sudo cp /boot/firmware/bootcode.bin /mnt/<tftpboot>
# Get Raspberry Pi Serial Number 
$ grep Serial /proc/cpuinfo
$ sudo mkdir /mnt/<tftpboot>/<rpi_serial>
$ sudo rsync -avhP /boot/firmware/ /mnt/<tftpboot>/<rpi_serial>

Prepare pxe share folder

$ sudo mkdir /mnt/<pxeshare>
$ sudo mount -t nfs <ip_of_NAS>:/volume1/<pxeshare> /mnt/<pxeshare>
$ sudo mkdir /mnt/<pxeshare>/<rpi_folder>
$ sudo rsync -avhP --exclude /boot --exclude /dev --exclude /mnt --exclude /proc --exclude /sys --exclude /tmp --exclude /var/tmp / /mnt/<pxeshare>/<rpi_folder>/
$ sudo mkdir /mnt/<pxeshare>/<rpi_folder>/{boot,dev,mnt,proc,sys,tmp,var/tmp}

Edit /boot/firmware/cmdline.txt

$ mv /mnt/<tftpboot>/<rpi_serial>/cmdline.txt /mnt/<tftpboot>/<rpi_serial>/cmdline.bak.txt 
$ sudo nano /mnt/<tftpboot>/<rpi_serial>/cmdline.txt

# Insert the following line
console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=<ip_of_NAS>:/volume1/<pxeshare>/<rpi_folder> rw ip=dhcp elevator=deadline rootwait cfg80211.ieee80211_regdom=SG

# Save and exit 

Edit /etc/fstab

$ sudo sed -i 's/PARTUUID/#PARTUUID/g' /mnt/<pxeshare>/<rpifolder>/etc/fstab
$ sudo sed -i "2i <ip_of_NAS>:/volume1/tftpboot/<rpi_serial> /boot/firmware nfs _netdev 0 0" /mnt/pxeshare/<rpi_folder>/etc/fstab
$ sudo sed -i "3i <ip_of_NAS>:/volume1/<pxeshare>/<rpifolder> / nfs _netdev 0 0" /mnt/<pxeshare>/<rpi_folder>/etc/fstab

Enable zram and disable swap

$ sudo dphys-swapfile swapoff 
$ sudo dphys-swapfile uninstall 
$ sudo systemctl stop dphys-swapfile.service 
$ sudo systemctl disable dphys-swapfile.service 
$ sudo systemctl mask dphys-swapfile.service 
$ sudo apt-get install zram-tools

Special Instructions for Ugreen NAS (No longer required. Can be set from within web interface)

# Make changes to the exports file here, change to no_root_squash
$ sudo nano /overlay/upper/etc/exports

# Make the file immutable
$ sudo chattr +i /overlay/upper/etc/exports

# Restart nfs service from the ugreen control panel

References

https://warmestrobot.com/blog/2024/06/27/raspberry-pi-network-boot-guide-2/
https://rob-ferguson.me/how-to-pxe-boot-your-rpi/
https://www.reddit.com/r/UgreenNASync/comments/1hh0ld9/export_nfs_share_with_no_root_squash/

You may also like...

Leave a Reply