Booting Raspberry Pi via PXE: A Guide to Network Booting

image_print

Title: Booting Raspberry Pi via PXE: A Guide to Network Booting

Introduction

Raspberry Pi, with its versatility and affordability, has become a favorite among tech enthusiasts for various projects. One of the most intriguing applications is using PXE (Preboot Execution Environment) to boot Raspberry Pi devices over the network, eliminating the need for local storage. This method can simplify management and deployment in various scenarios. In this guide, we’ll walk you through the steps to set up PXE boot for your Raspberry Pi.

Prerequisites

Before diving into the PXE boot setup, ensure you have the following:

  • Raspberry Pi board(s)
  • Network access
  • A NAS (Network-Attached Storage) or server for storing boot and root images
  • Basic knowledge of Linux commands

Setting Up PXE Boot for Raspberry Pi

  1. Find Serial Number for PXE Boot Begin by finding the serial number of your Raspberry Pi. Open a terminal and enter the following command:
   vcgencmd otp_dump | grep 28: | sed s/.*://g
  1. Install Necessary Software Install the nfs-common package on your Raspberry Pi by running:
   sudo apt install nfs-common
  1. Configure Network Booting Use raspi-config to enable network booting:
   sudo raspi-config

In the advanced boot options, enable network booting and set the boot order to boot from the network if the SD card boot fails.

  1. Create Directories On your Raspberry Pi, create a directory in /rpi-tftpboot using the serial number obtained earlier. On your PXE server, create a directory with the hostname of your Raspberry Pi.
   mkdir /nfs/boot /nfs/root
  1. Mount NAS Mount your NAS or server to the created directories:
   sudo mount -t nfs -o proto=tcp,port=2049 192.168.0.11:/volume1/rpi-tftpboot/8eb2f324 /nfs/boot
   sudo mount -t nfs -o proto=tcp,port=2049 192.168.0.11:/volume1/rpi-pxe/RPI4GB /nfs/root
  1. Copy Boot and Root Images Copy the boot image to the /nfs/boot directory and the root image to the /nfs/root directory:
   sudo rsync -av /boot/* /nfs/boot
   sudo rsync -av --exclude '/nfs' / /nfs/root
  1. Modify Command Line Edit the cmdline.txt file in the /nfs/boot directory to adjust the mount point and other parameters:
   sudo nano /nfs/boot/cmdline.txt

Modify the console, root, and nfsroot parameters to match your setup:

   console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=192.168.0.11:/volume1/rpi-pxe/RPI4GB rw ip=dhcp elevator=deadline rootwait
  1. Update /etc/fstab Edit the /etc/fstab file on the Raspberry Pi to update the mount points for the boot and root directories:
   sudo nano /nfs/root/etc/fstab

Update the entries with the appropriate paths:

   192.168.0.11:/volume1/rpi-tftpboot/8eb2f324  /boot           nfs    defaults          0       2
   192.168.0.11:/volume1/rpi-pxe/RPI4GB  /               nfs    defaults,noatime  0       1

Conclusion

By following these steps, you’ve successfully set up PXE boot for your Raspberry Pi devices. Network booting offers flexibility, scalability, and centralized management for your projects. This method can be particularly valuable for large-scale deployments or when you want to minimize the reliance on physical storage. Enjoy the benefits of network booting and explore new possibilities for your Raspberry Pi projects!

You may also like...