Enhance network boot setup script and documentation: automate fetching of Raspberry Pi 4 boot files from GitHub, update TFTP root handling, and improve user instructions for setup. Remove manual steps for file retrieval and clarify echo messages in the setup script.

This commit is contained in:
nearxos
2026-02-20 12:28:54 +02:00
parent 499c14580e
commit b99cc2520a
3 changed files with 77 additions and 15 deletions

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Populate /srv/tftpboot with Raspberry Pi 4 / CM4 boot files from the official firmware repo.
# Run inside the LXC (as root), or from your machine: ./populate-tftpboot-from-git.sh root@10.130.60.141
# Requires: curl or wget, tar; the LXC must have internet (eth0).
set -e
TARGET="${1:-}"
FIRMWARE_URL="https://github.com/raspberrypi/firmware/archive/refs/heads/master.tar.gz"
TFTP_ROOT="${TFTP_ROOT:-/srv/tftpboot}"
do_populate() {
echo "Populating $TFTP_ROOT from Raspberry Pi firmware (GitHub) ..."
mkdir -p "$TFTP_ROOT"
if [[ -f "$TFTP_ROOT/start4cd.elf" ]]; then
echo "start4cd.elf already present; skipping download (remove it to re-fetch)."
return 0
fi
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
echo "Installing curl ..."
apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq curl
fi
local tmpdir
tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT
if command -v curl >/dev/null 2>&1; then
curl -sL "$FIRMWARE_URL" -o "$tmpdir/firmware.tar.gz"
else
wget -q -O "$tmpdir/firmware.tar.gz" "$FIRMWARE_URL"
fi
tar xzf "$tmpdir/firmware.tar.gz" -C "$tmpdir"
if [[ ! -d "$tmpdir/firmware-master/boot" ]]; then
echo "Error: boot folder not found in archive"
exit 1
fi
cp -a "$tmpdir/firmware-master/boot/." "$TFTP_ROOT/"
echo "Copied boot files to $TFTP_ROOT ($(ls "$TFTP_ROOT" | wc -l) items)."
ls -la "$TFTP_ROOT"/start4*.elf "$TFTP_ROOT"/fixup4*.dat "$TFTP_ROOT"/config.txt 2>/dev/null || true
}
if [[ -n "$TARGET" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
scp "$SCRIPT_DIR/populate-tftpboot-from-git.sh" "$TARGET:/tmp/populate-tftpboot.sh"
ssh "$TARGET" "bash /tmp/populate-tftpboot.sh"
exit 0
fi
do_populate

View File

@@ -14,7 +14,7 @@ if [[ -n "$TARGET" ]]; then
rsync -a "$REPO_DIR/lxc/" "$TARGET:/tmp/cm4-network-boot-lxc/" --exclude='.git'
scp "$SCRIPT_DIR/setup-network-boot-on-lxc.sh" "$TARGET:/tmp/cm4-network-boot-lxc/setup.sh"
ssh "$TARGET" "bash /tmp/cm4-network-boot-lxc/setup.sh"
echo "Done. Next: ensure /srv/tftpboot has RPi boot files (see docs/NETWORK-BOOT-LXC.md)."
echo "Done."
exit 0
fi
@@ -42,12 +42,26 @@ log-queries
port=0
DNSMASQ
# 3) TFTP root and minimal placeholder so TFTP serves something
# 3) TFTP root: fetch Raspberry Pi 4 boot files from GitHub if missing
mkdir -p /srv/tftpboot
if [[ ! -f /srv/tftpboot/start4cd.elf ]]; then
echo "TFTP root /srv/tftpboot is empty. You need Raspberry Pi 4 boot files (start4cd.elf, fixup4cd.dat, config.txt, cmdline.txt, kernel8.img)."
echo "Download from: https://github.com/raspberrypi/firmware/ (branch master, boot/ folder) and copy into /srv/tftpboot"
echo "Or from a Pi: scp -r pi@<pi>:/boot/firmware/* root@<lxc>:/srv/tftpboot/"
echo "Fetching Raspberry Pi firmware boot files from GitHub ..."
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq curl
fi
tmpdir=$(mktemp -d)
trap "rm -rf $tmpdir" EXIT
if command -v curl >/dev/null 2>&1; then
curl -sL "https://github.com/raspberrypi/firmware/archive/refs/heads/master.tar.gz" -o "$tmpdir/firmware.tar.gz"
else
wget -q -O "$tmpdir/firmware.tar.gz" "https://github.com/raspberrypi/firmware/archive/refs/heads/master.tar.gz"
fi
tar xzf "$tmpdir/firmware.tar.gz" -C "$tmpdir"
cp -a "$tmpdir/firmware-master/boot/." /srv/tftpboot/
rm -rf "$tmpdir"
echo "Copied RPi boot files to /srv/tftpboot"
else
echo "TFTP root already has boot files (start4cd.elf present), skipping fetch."
fi
# 4) IP forwarding (LAN clients use WAN)
@@ -87,4 +101,4 @@ systemctl restart dnsmasq
echo "Network boot setup done."
echo " - DHCP + TFTP on eth1 (10.20.50.1), range 10.20.50.100-200"
echo " - NAT: 10.20.50.0/24 -> eth0 (internet)"
echo " - Put RPi 4 boot files in /srv/tftpboot (see above or docs/NETWORK-BOOT-LXC.md)"
echo " - TFTP root: /srv/tftpboot (RPi boot files from GitHub)"