Raspberry PI: network boot explained

Da raspibo.
Jump to navigation Jump to search

The network booting process has three phases:

  • get an IP address via DHCP
  • load kernel and configuration files using TFTP
  • mount root partition by NFS

Any Raspberry PI can be net-booted

...but it needs an SD card. Only Raspberry PI 3 supports network booting without any card (although I have not tested it yet).

The SD card need to contain one FAT partition and inside it one file: bootcode.bin. The latest version of bootcode.bin can be dowloaded from here. It is a 50K file so any size of SD Card is okay. Even a partially damaged SD card or a fake SD card can be used for this purpose. This file will be read at boot time and never modified so the card should not be further damaged.

Further information on the boot modes can be retrieved from the boot modes page on the raspberry pi foundation documentation site.

Phase 1: DHCP

The goal of DHCP is to provide our Raspberry PI with an IP address and inform it that the server is available for the next steps of the network boot

The Raspberry PI MAC address is required to provide it with its specific IP address.

I suggest to use wireshark (clearly on the server) to get this information: a view on the network packets flowing on the net can teach a lot about how the boot process really works.

Start wireshark, put the SD Card in the Raspberry PI, connect the Raspberry PI to the network, and power it on.

Bootrpidhcp.jpg

The screenshot shows the DHCP request. The MAC address of my Raspberry PI is: be:27:eb:15:e4:ef

The next step is to configure a DHCP server to provide the Raspberry PI with its own IP address.

In this test I'll use DNSmasq.

This is the configuration to assign the IP address 192.168.1.100 to the MAC be:27:eb:15:e4:ef on the interface eth0.

interface=enx0050b6175c07
bind-interfaces
dhcp-range=192.168.1.100,192.168.1.100,255.255.255.0,1h
dhcp-host=be:27:eb:15:e4:ef,192.168.1.100,1h
pxe-service=0,"Raspberry Pi Boot"
log-dhcp

The option pxe-service notifies the Raspberry pi that this server supports the net boot.

Restart dnsmaq:

sudo systemctl restart dnsmasq.service

restart wireshark and powercycle the Raspberry PI.

If everything is working properly now the Raspberry PI receives a DHCP offer and tries to continue with the following step (and it fails as we have not configured TFTP, yet).

Here is the screenshot:

Bootrpidhcpreply.jpg