Skip to content

Instantly share code, notes, and snippets.

@corusm
Created March 30, 2022 19:35
Show Gist options
  • Save corusm/afa62e6268b4f35906d99849d748a37c to your computer and use it in GitHub Desktop.
Save corusm/afa62e6268b4f35906d99849d748a37c to your computer and use it in GitHub Desktop.
Raspberry Pi Network Boot Approach

How I tried it:

Build Docker Images

sudo docker build -f Dockerfile.dnsmasq -t local/dnsmasq .

sudo docker build -f Dockerfile.nfs -t local/nfs-server .

Edited the setup.sh from here

  1. Updated the URL to: url="http://downloads.raspberrypi.org/raspios_lite_armhf/archive/2022-01-28-13:51/"
port=0
dhcp-range=10.50.0.1,10.50.3.254
log-dhcp
enable-tftp
tftp-root=/tftpboot
pxe-service=0,"Raspberry Pi Boot"
version: "2"
services:
netboot_boot:
image: local/dnsmasq
privileged: true
container_name: dnsmasq
network_mode: "host"
volumes:
- ./os/boot:/tftpboot
- ./dnsmasq.conf:/etc/dnsmasq.conf
netboot_root:
image: local/nfs-server
container_name: nfs-server
privileged: true
network_mode: "host"
volumes:
# - ./exports:/etc/exports
- ./os:/nfsshare
FROM alpine
RUN apk add --no-cache dnsmasq
EXPOSE 53/tcp \
53/udp \
67/udp
ENTRYPOINT ["dnsmasq", "--no-daemon", "--user=dnsmasq", "--group=dnsmasq"]
FROM alpine
RUN apk --update --no-cache add bash nfs-utils \
&& echo "/nfs/client1 *(rw,sync,no_subtree_check,no_root_squash)" | tee -a /etc/exports
COPY run_nfs /usr/bin/
COPY exports /etc/exports
#VOLUME /nfs/client1
ENTRYPOINT ["run_nfs"]
/nfsshare *(rw,sync,no_subtree_check,no_root_squash)
#!/bin/bash
set -xe
trap "stop; exit 0;" SIGTERM SIGINT
stop()
{
# We're here because we've seen SIGTERM, likely via a Docker stop command or similar
# Let's shutdown cleanly
echo "SIGTERM caught, terminating NFS process(es)..."
/usr/sbin/exportfs -ua
pid1=$(pidof rpc.nfsd)
pid2=$(pidof rpc.mountd)
kill -TERM $pid1 $pid2 > /dev/null 2>&1
echo "Terminated."
exit
}
mkdir -p /nfsshare
# Fixed nlockmgr port
#echo 'fs.nfs.nlm_tcpport=32768' >> /etc/sysctl.conf
#echo 'fs.nfs.nlm_udpport=32768' >> /etc/sysctl.conf
#sysctl -p > /dev/null
mount -t nfsd nfds /proc/fs/nfsd
rpcbind -w
rpc.nfsd -N 2 -V 3 -N 4 -N 4.1 8
exportfs -arfv
rpc.statd
rpc.mountd -N 2 -V 3 -N 4 -N 4.1 -F
#!/bin/sh
set -xe
die() {
printf '\033[1;31mERROR:\033[0m %s\n' "$@" >&2 # bold red
exit 1
}
which xz > /dev/null || die 'please install xz'
which docker > /dev/null || die 'please install docker'
which docker-compose > /dev/null || die 'please install docker-compose with: sudo pip3 install docker-compose'
cd "$(dirname "$0")"
DEST=$(pwd)
url="http://downloads.raspberrypi.org/raspios_lite_armhf/archive/2022-01-28-13:51/"
server_ip=$(ip route get 1 | awk '{print $NF;exit}')
mkdir -p os/boot os/root
wget $url/boot.tar.xz -O- | tar -C os/boot -xJf -
wget $url/root.tar.xz -O- | sudo tar -C os/root -xJf -
echo "dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/nfs \
nfsroot=$server_ip:/nfsshare/root,vers=3 rw ip=dhcp rootwait elevator=deadline" | \
sudo tee os/boot/cmdline.txt
echo "proc /proc proc defaults 0 0
"$server_ip":/nfsshare/boot /boot nfs defaults 0 0" | sudo tee os/root/etc/fstab
sudo rm -f os/root/etc/init.d/resize2fs_once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment