How to Network Boot a Raspberry Pi Without an SD Card

Ben
Ben
@benjislab

Network booting allows your Raspberry Pi to boot up and run without the need for an SD card, using a network server instead. This can be useful for centralized management of multiple Raspberry Pi devices, or for quickly deploying systems. This guide will walk you through the steps to set up and configure network booting on your Raspberry Pi.

Prerequisites

Before starting, ensure you have the following:

  • Raspberry Pi 3 Model B, 3 Model B+, Raspberry Pi 4, or later
  • A computer to set up the server
  • A network switch or router
  • Ethernet cables
  • Access to the command line (via monitor and keyboard or SSH)
  • Raspberry Pi OS image

Step 1: Enable Network Boot on Raspberry Pi

For Raspberry Pi 3 Model B and Model B+, you need to enable network boot mode. This step is not required for Raspberry Pi 4 and later models.

  1. Insert an SD Card with Raspberry Pi OS:

Boot your Raspberry Pi with a standard SD card containing Raspberry Pi OS.

  1. Enable Network Boot:

Open a terminal and run the following command to enable network boot:

echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
  1. Reboot the Raspberry Pi:
sudo reboot
  1. Check if Network Boot is Enabled:

After rebooting, check if the OTP (One-Time Programmable) memory has been programmed with:

vcgencmd otp_dump | grep 17:

You should see 17:3020000a in the output. If you do, network boot is enabled.

Step 2: Set Up a Network Boot Server

The network boot server will host the boot files and operating system for your Raspberry Pi. We'll use a computer running a Linux-based OS (such as Ubuntu) as the server.

  1. Install Necessary Packages:

On your server, install the required packages for a DHCP and TFTP server:

sudo apt update
sudo apt install dnsmasq nfs-kernel-server -y
  1. Configure dnsmasq:

Edit the dnsmasq configuration file:

sudo nano /etc/dnsmasq.conf

Add the following lines to configure the DHCP and TFTP services:

interface=eth0
dhcp-range=192.168.1.50,192.168.1.150,12h
enable-tftp
tftp-root=/tftpboot
dhcp-boot=pxelinux.0
  1. Create TFTP Boot Directory:

Create the TFTP boot directory and download the necessary boot files:

sudo mkdir /tftpboot
cd /tftpboot
sudo wget https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin
  1. Configure NFS:

Create a directory for the root filesystem and configure NFS exports:

sudo mkdir -p /nfsroot
sudo nano /etc/exports

Add the following line to the exports file:

/nfsroot *(rw,sync,no_subtree_check,no_root_squash)

Export the NFS share:

sudo exportfs -a
sudo systemctl restart nfs-kernel-server
  1. Copy Raspberry Pi OS Files:

Download and extract the Raspberry Pi OS image, then copy its contents to the NFS root directory:

sudo mount -o loop,offset=512 <path_to_raspberry_pi_os_image> /mnt
sudo cp -r /mnt/* /nfsroot
sudo umount /mnt

Step 3: Boot the Raspberry Pi

  1. Connect the Raspberry Pi to the Network:

Connect your Raspberry Pi to the network via an Ethernet cable.

  1. Power On the Raspberry Pi:

Power on your Raspberry Pi. It should now attempt to boot from the network. If everything is configured correctly, it will retrieve the boot files from the TFTP server and the root filesystem from the NFS server.

  1. Monitor the Boot Process:

You can monitor the boot process by checking the logs on the server:

sudo tail -f /var/log/syslog

Conclusion

By setting up network booting for your Raspberry Pi, you can streamline the management and deployment of multiple devices without the need for individual SD cards. This setup is particularly useful for educational environments, labs, or any scenario where you need to manage several Raspberry Pi devices efficiently. Follow these steps to get your Raspberry Pi network booting and enjoy the convenience and flexibility it offers.