Network Booting a Raspberry Pi 2

Network Booting a Raspberry Pi 2

Introduction

While going forward it would be ideal to only use Rasberry Pi 3s for Network Booting (or generally) I have a number of Pi 2s left. Being able to re-use these in the same way means less waste.

I found it much easier to test this approach after having a working Network Boot Environment tested on a Pi 3.

Turns out this is very simple once the Server is working as expected!

This article is initially based on the following guides, but looks to includes a bit more detail and troubleshooting steps:

Essentially it just requires a boot partition with only the latest bootcode.bin from the next branch of rpi-firmware - https://raw.githubusercontent.com/Hexxeh/rpi-firmware/next/bootcode.bin.

Edit (2018-09-25): Warning, the next branch appears to be out of date now, downloading from master (the default) works best for all devices - https://raw.githubusercontent.com/Hexxeh/rpi-firmware/master/bootcode.bin.

The Long Version

This version starts from a fully working Rasbpian Install and strips it back to just include the required file.

It means an SD card large enough for the full OS image is required whereas bootcode.bin is some ~50Kb which by iteself would clearly fit on a much smaller card.

Step 1: Raspbian (Lite) SD Card

Download the Raspbian Lite from here.

Flash to a Micro SD card, the easiest way is to use Etcher (it will even take a zip and use that, and verify the content after).

Etcher

Step 2: Clean Up (optional)

After the SD card is ready find the disk:

paul@box [10:35:08] [~] 
-> % lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 894.3G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 861.9G  0 part /
└─sda3   8:3    0  31.9G  0 part [SWAP]
sdb      8:16   0 232.9G  0 disk 
└─sdb1   8:17   0 232.9G  0 part /media/paul/xx3
sdc      8:32   0 931.5G  0 disk 
└─sdc1   8:33   0 931.5G  0 part /data/xx2
sdd      8:48   0 931.5G  0 disk 
└─sdd1   8:49   0 931.5G  0 part /data/xx1
sde      8:64   1   7.4G  0 disk 
├─sde1   8:65   1  41.5M  0 part 
└─sde2   8:66   1   1.7G  0 part 

In my case it is sde.

Run sudo fdisk /dev/sde, delete partition 2 and write the changes:

paul@box [10:35:10] [~] 
-> % sudo fdisk /dev/sde
Welcome to fdisk (util-linux 2.30.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sde: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x37665771

Device     Boot Start     End Sectors  Size Id Type
/dev/sde1        8192   93236   85045 41.5M  c W95 FAT32 (LBA)
/dev/sde2       94208 3629055 3534848  1.7G 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 

Partition 2 has been deleted.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Synching disks.
Step 3: Configure boot

Mount /dev/sde1 either using mount or the file manager.

Clear the partition and then download bootcode.bin:

paul@box [10:49:14] [~] 
-> % cd /media/paul/boot 
paul@box [10:49:17] [/media/paul/boot] 
-> % rm -Rf *
zsh: sure you want to delete all the files in /media/paul/boot [yn]? y
paul@box [10:49:20] [/media/paul/boot] 
-> % wget https://github.com/Hexxeh/rpi-firmware/raw/next/bootcode.bin
--2018-03-05 10:49:21--  https://github.com/Hexxeh/rpi-firmware/raw/next/bootcode.bin
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/Hexxeh/rpi-firmware/next/bootcode.bin [following]
--2018-03-05 10:49:22--  https://raw.githubusercontent.com/Hexxeh/rpi-firmware/next/bootcode.bin
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.192.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 51996 (51K) [application/octet-stream]
Saving to: ‘bootcode.bin’

bootcode.bin                  100%[===============================================>]  50.78K  --.-KB/s    in 0.1s    

2018-03-05 10:49:22 (460 KB/s) - ‘bootcode.bin’ saved [51996/51996]

Eject and boot the Pi 2 off it and it should all work - tailing syslog for dhcp and tftp can confirm the early stages.

The Short Version

This version starts a blank SD card and sets it up for just what is needed.

It means a very small (and cheap) card can be used as bootcode.bin is some ~50Kb.

Step 1: Find your device

Mine is sde:

paul@box [10:44:43] [~] 
-> % lsblk              
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 894.3G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0 861.9G  0 part /
└─sda3   8:3    0  31.9G  0 part [SWAP]
sdb      8:16   0 232.9G  0 disk 
└─sdb1   8:17   0 232.9G  0 part /media/paul/xx3
sdc      8:32   0 931.5G  0 disk 
└─sdc1   8:33   0 931.5G  0 part /data/xx2
sdd      8:48   0 931.5G  0 disk 
└─sdd1   8:49   0 931.5G  0 part /data/xx1
sde      8:64   1   1.9G  0 disk 
└─sde1   8:65   1   1.9G  0 part 
paul@box [10:44:44] [~] 
-> % sudo fdisk /dev/sde
Step 2: Set up the partition
  • See what is there already with p.
  • Delete any existing partitions with d.
  • Create a new partition with n, it is primary, starting from the beginning and can be anywhere from around 10Mb (any less didn't work) to the size of the drive, in the example below I made it 50Mb.
  • If prompted to remove the vfat signature select Y.
  • Use t to set its type to b (W95 FAT32).
  • Finally write the changes with w.
Welcome to fdisk (util-linux 2.30.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sde: 1.9 GiB, 2002780160 bytes, 3911680 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start     End Sectors  Size Id Type
/dev/sde1        2048 3911679 3909632  1.9G  b W95 FAT32

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-3911679, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-3911679, default 3911679): +50M

Created a new partition 1 of type 'Linux' and of size 50 MiB.
Partition #1 contains a vfat signature.

Do you want to remove the signature? [Y]es/[N]o: Y

The signature will be removed by a write command.

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): b 
Changed type of partition 'Linux' to 'W95 FAT32'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Synching disks.
Step 3: Format the new partition

The partition is FAT formatted.

Note: The label 'boot' is not required.

paul@box [10:44:59] [~] 
-> % sudo mkfs.fat -n boot /dev/sde1                                  
mkfs.fat 4.1 (2017-01-24)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
Step 4: Add bootcode.bin

Mount /dev/sde1 either using mount or the file manager.

Download bootcode.bin:

paul@box [10:49:14] [~] 
-> % cd /media/paul/boot 
paul@box [10:49:17] [/media/paul/boot] 
-> % wget https://github.com/Hexxeh/rpi-firmware/raw/next/bootcode.bin
--2018-03-05 10:49:21--  https://github.com/Hexxeh/rpi-firmware/raw/next/bootcode.bin
Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113
Connecting to github.com (github.com)|192.30.253.112|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/Hexxeh/rpi-firmware/next/bootcode.bin [following]
--2018-03-05 10:49:22--  https://raw.githubusercontent.com/Hexxeh/rpi-firmware/next/bootcode.bin
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.192.133, 151.101.128.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 51996 (51K) [application/octet-stream]
Saving to: ‘bootcode.bin’

bootcode.bin                  100%[===============================================>]  50.78K  --.-KB/s    in 0.1s    

2018-03-05 10:49:22 (460 KB/s) - ‘bootcode.bin’ saved [51996/51996]

Eject and boot the Pi 2 off it and it should all work - tailing syslog for dhcp and tftp can confirm the early stages.