From 8e6bf49e06f02c7ddff45ec04a69f1cfc8f7c1f6 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Sat, 24 Oct 2026 09:00:22 -0600 Subject: [PATCH] feat: add RPi4 NFS netboot staging --- jeannie | 2 +- lib/jeannie/commands.sh | 13 +++++++---- scripts/rpi4-nfs-stage | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100755 scripts/rpi4-nfs-stage diff --git a/jeannie b/jeannie index 4cc5809..3ef61c8 100755 --- a/jeannie +++ b/jeannie @@ -64,7 +64,7 @@ Build And Bootstrap deploy-hermes Deploy the Hermes agent (git-install + venv + gateway service). bootstrap-gitea-repo Ensure the Gitea repo and SSH key wiring exist. rpi-services Deploy Pi-hole, Unbound, and Uptime Kuma on RPi4. - host-bootstrap rpi4 [status|plan|apply --yes] + host-bootstrap rpi4 [status|plan|nfs-stage|apply --yes] Provision/check the physical RPi4, then bootstrap host services. ollama-setup Install/configure Ollama on the Debian host. artifact-cache {status|up|down|instructions} diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index f6bbafe..8b52239 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -39,11 +39,11 @@ host_bootstrap_manage() { local rpi_host rpi_user rpi_key rpi_os_image rpi_os_url rpi_install_device if [[ "${host_target}" != "rpi4" ]]; then - echo "Usage: ./jeannie host-bootstrap rpi4 [status|plan|apply --yes]" >&2 + echo "Usage: ./jeannie host-bootstrap rpi4 [status|plan|nfs-stage|apply --yes]" >&2 return 2 fi if [[ "${action}" == "--help" || "${action}" == "help" ]]; then - echo "Usage: ./jeannie host-bootstrap rpi4 [status|plan|apply --yes]" + echo "Usage: ./jeannie host-bootstrap rpi4 [status|plan|nfs-stage|apply --yes]" return 0 fi rpi_host="${LAB_RPI_HOST:-${LAB_RASPBERRY_HOST:-192.168.100.89}}" @@ -51,9 +51,12 @@ host_bootstrap_manage() { rpi_key="${LAB_RPI_SSH_KEY_PATH:-${LAB_RASPBERRY_SSH_KEY_PATH:-${HOME}/.ssh/id_ed25519}}" rpi_os_image="${LAB_RPI4_OS_IMAGE_NAME:-Raspberry Pi OS Lite (64-bit)}" rpi_os_url="${LAB_RPI4_OS_IMAGE_URL:-https://downloads.raspberrypi.com/raspios_lite_arm64_latest}" - rpi_install_device="${LAB_RPI4_INSTALL_DEVICE:-unset}" + rpi_install_device="${LAB_RPI4_INSTALL_DEVICE:-/dev/mmcblk0}" case "${action}" in + nfs-stage) + "${REPO_ROOT}/scripts/rpi4-nfs-stage" "${3:-plan}" "${4:-}" + ;; status) echo "== RPi4 host bootstrap status ==" echo "target=${rpi_user}@${rpi_host} key=${rpi_key}" @@ -95,8 +98,8 @@ EOF echo "LAB_RPI4_OS_PROVISIONER_COMMAND is required for RPi4 OS installation; refusing to guess a disk or boot target." >&2 return 2 fi - if [[ "${LAB_RPI4_INSTALL_DEVICE:-}" != "/dev/mmcblk0" ]]; then - echo "Set LAB_RPI4_INSTALL_DEVICE=/dev/mmcblk0 explicitly before applying the RPi4 image." >&2 + if [[ "${LAB_RPI4_INSTALL_DEVICE:-/dev/mmcblk0}" != "/dev/mmcblk0" ]]; then + echo "RPi4 installs are fixed to /dev/mmcblk0; refusing a different target." >&2 return 2 fi if ssh -i "${rpi_key}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \ diff --git a/scripts/rpi4-nfs-stage b/scripts/rpi4-nfs-stage new file mode 100755 index 0000000..a883ea5 --- /dev/null +++ b/scripts/rpi4-nfs-stage @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +action="${1:-plan}" +rpi_host="${LAB_RPI_HOST:-${LAB_RASPBERRY_HOST:-192.168.100.89}}" +rpi_user="${LAB_RPI_USER:-${LAB_RASPBERRY_USER:-jv}}" +rpi_key="${LAB_RPI_SSH_KEY_PATH:-${LAB_RASPBERRY_SSH_KEY_PATH:-${HOME}/.ssh/id_ed25519}}" +server_ip="${LAB_RPI4_NETBOOT_SERVER_IP:-${LAB_DEBIAN_LAN_IP:-192.168.100.73}}" +tftp_root="${LAB_RPI4_TFTP_ROOT:-/opt/homelab-provisioning/tftp}" +nfs_root="${LAB_RPI4_NFS_ROOT:-/srv/nfs/rpi4}" + +case "${action}" in + plan) + cat <&2; exit 2; } + command -v ssh >/dev/null || { echo "ssh is required" >&2; exit 1; } + ssh -i "${rpi_key}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new "${rpi_user}@${rpi_host}" true + serial="$(ssh -i "${rpi_key}" -o BatchMode=yes "${rpi_user}@${rpi_host}" "awk '/^Serial/{print \$3}' /proc/cpuinfo | tail -1 | cut -c9-16")" + [[ "${serial}" =~ ^[0-9a-fA-F]{8}$ ]] || { echo "Unable to determine RPi4 serial prefix" >&2; exit 1; } + boot_dir="${tftp_root}/${serial}" + sudo apt-get update + sudo apt-get install -y nfs-kernel-server rsync + sudo mkdir -p "${boot_dir}" "${nfs_root}/${serial}" + ssh -i "${rpi_key}" -o BatchMode=yes "${rpi_user}@${rpi_host}" 'sudo tar -C /boot/firmware -cf - .' | sudo tar -C "${boot_dir}" -xf - + ssh -i "${rpi_key}" -o BatchMode=yes "${rpi_user}@${rpi_host}" 'sudo tar -C / --exclude=./proc --exclude=./sys --exclude=./dev --exclude=./run --exclude=./tmp --exclude=./mnt --exclude=./media --exclude=./boot --exclude=./var/lib/docker --exclude=./nvme-storage --exclude=./lost+found -cf - .' | sudo tar -C "${nfs_root}/${serial}" -xf - + sudo sed -i -E "s#root=[^ ]+#root=/dev/nfs nfsroot=${server_ip}:${nfs_root}/${serial},vers=4.1,proto=tcp,rw#" "${boot_dir}/cmdline.txt" + grep -q "${nfs_root}/${serial}" "${boot_dir}/cmdline.txt" || { echo "Failed to set NFS root cmdline" >&2; exit 1; } + export_line="${nfs_root}/${serial} ${rpi_host}(rw,sync,no_subtree_check,no_root_squash)" + sudo grep -Fqx "${export_line}" /etc/exports 2>/dev/null || echo "${export_line}" | sudo tee -a /etc/exports >/dev/null + sudo exportfs -ra + sudo systemctl enable --now nfs-server 2>/dev/null || sudo systemctl enable --now nfs-kernel-server + echo "NFS staging prepared for RPi4 serial ${serial}." + echo "The Pi still boots from SD until its EEPROM boot order is changed to network-first." + ;; + *) + echo "Usage: scripts/rpi4-nfs-stage {plan|apply --yes}" >&2 + exit 2 + ;; +esac