Differenze tra le versioni di "Raspberry PI: network boot explained"

Da raspibo.
Jump to navigation Jump to search
Riga 61: Riga 61:
  
 
== Phase 2: TFTP ==
 
== Phase 2: TFTP ==
 +
 +
TFTP means trivial file transfer protocol. Nothing really complex can be used at boot time, the code to manage TFTP at boot time needs to fit in the BIOS ROM or, in our case, in the 50K bootcode.bin file.
 +
 +
DNSmasq is able to provide TFTP too.
 +
 +
Let us enable TFTP: it is possible just by add two lines in /etc/dnsmasq.conf:
 +
<pre>
 +
enable-tftp
 +
tftp-root=/tftpboot
 +
</pre>
 +
 +
The tftp-root parameter defines the root directory for tftp: any file inside this directory (and in its subdirectories) will be available for downloading via TFTP.
 +
Feel free to put it where it is more suitable in your file system.
 +
 +
The files needed to boot a Raspberry PI can be stored in the TFTP root directory or in directories named upon the Raspberry PI serial number/MAC address. In the former case the files will be shared between all the raspberry pi using the net-boot service on the same server, the latter choice permits to define specific boot files for each client.

Versione delle 11:45, 10 gen 2018

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

Packet #39 is the DHCP repy whish assigns the address to the Raspberry PI, then packet #42 tries to load the file "6c15e4ef/start.elf" via TFTP...

We are ready for the second phase.

Phase 2: TFTP

TFTP means trivial file transfer protocol. Nothing really complex can be used at boot time, the code to manage TFTP at boot time needs to fit in the BIOS ROM or, in our case, in the 50K bootcode.bin file.

DNSmasq is able to provide TFTP too.

Let us enable TFTP: it is possible just by add two lines in /etc/dnsmasq.conf:

enable-tftp
tftp-root=/tftpboot

The tftp-root parameter defines the root directory for tftp: any file inside this directory (and in its subdirectories) will be available for downloading via TFTP. Feel free to put it where it is more suitable in your file system.

The files needed to boot a Raspberry PI can be stored in the TFTP root directory or in directories named upon the Raspberry PI serial number/MAC address. In the former case the files will be shared between all the raspberry pi using the net-boot service on the same server, the latter choice permits to define specific boot files for each client.