Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed hardware/raspberrypi/bootmodes/bootcode.bin
Binary file not shown.
30 changes: 22 additions & 8 deletions hardware/raspberrypi/bootmodes/msd.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
This tutorial explains how to boot your Raspberry Pi 3 from a USB mass storage device such as a flash drive or USB hard disk. Be warned that this feature is experimental and may not work with all USB mass storage devices.

## Program USB Boot Mode
Before a Pi will network boot, it needs to be booted with a config option to enable USB boot mode. Enabling this config option requires a special `start.elf` and `bootcode.bin` file.
Before a Pi will network boot, it needs to be booted with a config option to enable USB boot mode. Enabling this config option requires a special `start.elf` and `bootcode.bin` file. These can be installed by using the "next" branch on rpi-update.

Go to the [Downloads page](https://www.raspberrypi.org/downloads/raspbian/) and install Raspbian onto an SD card using `Win32DiskImager` if you are on Windows, or `dd` if you are on Linux/Mac. Boot the Pi.

First, prepare the `/boot` directory with new `start.elf` and `bootcode.bin` files:
First, prepare the `/boot` directory with experimental boot files:
```
cd /boot
sudo rm start.elf bootcode.bin start_* fixup*
sudo wget https://github.com/raspberrypi/documentation/raw/master/hardware/raspberrypi/bootmodes/start.elf
sudo wget https://github.com/raspberrypi/documentation/raw/master/hardware/raspberrypi/bootmodes/bootcode.bin
sudo sync
# If on raspbian lite you need to install rpi-update before you can use it:
$ sudo apt-get update; sudo apt-get install rpi-update
$ sudo BRANCH=next rpi-update
```

Then enable USB boot mode with:
Expand All @@ -37,7 +35,6 @@ Now that your Pi 3 is USB boot-enabled, we can prepare a USB storage device to b
We will start by using parted to create a 100MB fat32 partition, followed by a Linux ext4 partition that will take up the rest of the disk.

```
sudo umount /dev/sda
sudo parted /dev/sda

(parted) mktable msdos
Expand Down Expand Up @@ -70,9 +67,25 @@ sudo mkdir /mnt/target
sudo mount /dev/sda2 /mnt/target/
sudo mkdir /mnt/target/boot
sudo mount /dev/sda1 /mnt/target/boot/
sudo apt-get update; sudo apt-get install rsync
sudo rsync -ax --progress / /boot /mnt/target
```

Regenerate ssh host keys:
```
cd /mnt/target
sudo mount --bind /dev dev
sudo mount --bind /sys sys
sudo mount --bind /proc proc
sudo chroot /mnt/target
rm /etc/ssh/ssh_host*
dpkg-reconfigure openssh-server
exit
sudo umount dev
sudo umount sys
sudo umount proc
```

Edit `/boot/cmdline.txt` so that it uses the USB storage device as the root filesystem instead of the SD card.

```
Expand All @@ -86,6 +99,7 @@ sudo sed -i "s,/dev/mmcblk0p,/dev/sda," /mnt/target/etc/fstab

Finally, unmount the target filesystems, and power off the Pi.
```
cd ~
sudo umount /mnt/target/boot
sudo umount /mnt/target
sudo poweroff
Expand Down
21 changes: 13 additions & 8 deletions hardware/raspberrypi/bootmodes/net_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
This tutorial is written to explain how to set up a simple DHCP / TFTP server which will allow you to boot a Raspberry Pi 3 from the network. The tutorial assumes you have an existing home network, and want to use a Raspberry Pi for the **server**. You will need a second Pi 3 as a **client** to be booted. Only one SD card is needed because the **client** will be booted from the **server** after the initial client configuration.

## Client configuration
Before a Pi will network boot, it needs to be booted with a config option to enable USB boot mode. Enabling this config option requires a special `start.elf` and `bootcode.bin` file.
Before a Pi will network boot, it needs to be booted with a config option to enable USB boot mode. Enabling this config option requires a special `start.elf` and `bootcode.bin` file. These can be installed by using the "next" branch on rpi-update.

Install Raspbian lite (or heavy if you want) from the [Downloads page](https://www.raspberrypi.org/downloads/raspbian/) onto an SD card using `Win32DiskImager` if you are on Windows, or `dd` if you are on Linux/Mac. Boot the **client** Pi.

### Program USB Boot Mode
First, prepare the `/boot` directory with new `start.elf` and `bootcode.bin` files:
First, prepare the `/boot` directory with experimental boot files:
```
cd /boot
sudo rm start.elf bootcode.bin start_* fixup*
sudo wget https://github.com/raspberrypi/documentation/raw/master/hardware/raspberrypi/bootmodes/start.elf
sudo wget https://github.com/raspberrypi/documentation/raw/master/hardware/raspberrypi/bootmodes/bootcode.bin
sudo sync
# If on raspbian lite you need to install rpi-update before you can use it:
$ sudo apt-get update; sudo apt-get install rpi-update
$ sudo BRANCH=next rpi-update
```

Then enable USB boot mode with:
Expand Down Expand Up @@ -45,10 +43,17 @@ sudo rsync -xa --progress --exclude /nfs / /nfs/client1

Regenerate ssh host keys on client filesystem by chrooting into it:
```
sudo chroot /nfs/client1
cd /nfs/client1
sudo mount --bind /dev dev
sudo mount --bind /sys sys
sudo mount --bind /proc proc
sudo chroot .
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
exit
sudo umount dev
sudo umount sys
sudo umount proc
```

You need to find the settings of your local network. You need to find the address of your router (or gateway), which you can find with:
Expand Down
14 changes: 14 additions & 0 deletions hardware/raspberrypi/bootmodes/netboot_server_easy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## pxetools
We have created a Python script that is used internally to quickly set up Pi's that will network boot. It takes a serial number, which you can find in `cat /proc/cpuinfo`, an owner name and the name of the Pi. It then creates a root filesystem for that Pi from a raspbian image. There is also a --list option which will print out the IP address of the Pi, and remove an option. The follwing instructions describe how to set up the environment required by the script starting from a fresh Raspbian lite image. It might be a good idea to mount a hard disk or flash drive on /nfs so that your SD card isn't providing filesystems to multiple Pi's. This is left as an exercise for the reader.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raspbian should probably have a capital R.
Was "and remove an option" supposed to be "and a --remove option" ?
"Pi's" shouldn't have an apostrophe.


```
sudo raspi-config
# Pick expand filesystem option
# Finish
# Reboot

sudo wget https://raw.githubusercontent.com/raspberrypi/documentation/master/hardware/raspberrypi/bootmodes/pxetools/prepare_pxetools
bash prepare_pxetools

prepare_pxetools should prepare everything you need to use pxetools
```
107 changes: 107 additions & 0 deletions hardware/raspberrypi/bootmodes/pxetools/prepare_pxetools
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/bin/bash

set -e

sudo apt-get update; sudo apt-get -y upgrade
sudo apt-get install -y rpi-update
sudo BRANCH=next rpi-update

sudo apt-get install python3 python3-pip ipcalc
sudo pip3 install tabulate

# Get network info
NAMESERVER=$(cat /etc/resolv.conf | grep nameserver | head -n 1 | cut -d " " -f2)
GATEWAY=$(ip -4 route | grep default | cut -d " " -f3)
IP=$(ifconfig eth0 | grep "inet addr" | cut -d " " -f 12 | cut -d ":" -f 2)
BRD=$(ifconfig eth0 | grep "inet addr" | cut -d " " -f 14 | cut -d ":" -f 2)
NETMASK=$(ifconfig eth0 | grep "inet addr" | cut -d " " -f 16 | cut -d ":" -f 2)
NETWORK=$(ip -4 addr show dev eth0 | grep inet | cut -d " " -f6 | xargs ipcalc | grep Network | cut -d " " -f4)

echo "IP: $IP"
echo "Netmask: $NETMASK"
echo "Broadcast: $BRD"
echo "Nameserver: $NAMESERVER"
echo "Gateway: $GATEWAY"

echo "Setting static IP using above information"

cat << EOF | sudo tee /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address $IP
netmask $NETMASK
gateway $GATEWAY
EOF

sudo systemctl restart networking

# In case it is already set
sudo chattr -i /etc/resolv.conf

echo "Setting nameserver"
cat << EOF | sudo tee /etc/resolv.conf
nameserver $NAMESERVER
EOF

# Prevent DNSMasq from changing
sudo chattr +i /etc/resolv.conf

sudo apt-get install -y nfs-kernel-server dnsmasq iptables-persistent unzip nmap kpartx

sudo mkdir -p /nfs
sudo mkdir -p /tftpboot
sudo cp -r /boot /tftpboot/base
sudo chmod -R 777 /tftpboot

echo "Writing dnsmasq.conf"
cat << EOF | sudo tee /etc/dnsmasq.conf
port=0
dhcp-range=$BRD,proxy
bind-interfaces
log-dhcp
enable-tftp
log-facility=/var/log/dnsmasq
tftp-root=/tftpboot
pxe-service=0,"Raspberry Pi Boot"
EOF

# Flush any rules that might exist
sudo iptables -t raw --flush

# Create the DHCP_clients chain in the 'raw' table
sudo iptables -t raw -N DHCP_clients || true

# Incoming DHCP, pass to chain processing DHCP
sudo iptables -t raw -A PREROUTING -p udp --dport 67 -j DHCP_clients

# Deny clients not in chain not listed above
sudo iptables -t raw -A DHCP_clients -j DROP

sudo iptables-save | sudo tee /etc/iptables/rules.v4

# Start services
sudo systemctl enable dnsmasq
sudo systemctl restart dnsmasq
sudo systemctl enable nfs-kernel-server
sudo systemctl restart nfs-kernel-server
sudo systemctl enable rpcbind
sudo systemctl restart rpcbind

echo "Getting latest Raspbian lite image to use as NFS root"
# Get latest Raspbian lite image
sudo mkdir -p /nfs/bases
cd /nfs/bases
sudo wget -O raspbian_latest.zip https://downloads.raspberrypi.org/raspbian_lite_latest
sudo unzip raspbian_latest.zip
sudo rm raspbian_latest.zip

sudo wget -O /usr/local/sbin/pxetools https://raw.githubusercontent.com/raspberrypi/documentation/master/hardware/raspberrypi/bootmodes/pxetools/pxetools
sudo chmod +x /usr/local/sbin/pxetools

sudo sed -i "s,LAN = \"10.3.14.0/24\",LAN = \"$NETWORK\"," /usr/local/sbin/pxetools
sudo sed -i "s,NFS_IP = \"10.3.14.18\",NFS_IP = \"$IP\"," /usr/local/sbin/pxetools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these values get hard-coded? Wouldn't it be better for the pxetools script to determine them dynamically, the same way this script does?


echo "Now run sudo pxetools --add \$serial"
Loading