feat: add RPi4 NFS netboot staging
This commit is contained in:
parent
de6443ef73
commit
8e6bf49e06
2
jeannie
2
jeannie
|
|
@ -64,7 +64,7 @@ Build And Bootstrap
|
||||||
deploy-hermes Deploy the Hermes agent (git-install + venv + gateway service).
|
deploy-hermes Deploy the Hermes agent (git-install + venv + gateway service).
|
||||||
bootstrap-gitea-repo Ensure the Gitea repo and SSH key wiring exist.
|
bootstrap-gitea-repo Ensure the Gitea repo and SSH key wiring exist.
|
||||||
rpi-services Deploy Pi-hole, Unbound, and Uptime Kuma on RPi4.
|
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.
|
Provision/check the physical RPi4, then bootstrap host services.
|
||||||
ollama-setup Install/configure Ollama on the Debian host.
|
ollama-setup Install/configure Ollama on the Debian host.
|
||||||
artifact-cache {status|up|down|instructions}
|
artifact-cache {status|up|down|instructions}
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,11 @@ host_bootstrap_manage() {
|
||||||
local rpi_host rpi_user rpi_key rpi_os_image rpi_os_url rpi_install_device
|
local rpi_host rpi_user rpi_key rpi_os_image rpi_os_url rpi_install_device
|
||||||
|
|
||||||
if [[ "${host_target}" != "rpi4" ]]; then
|
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
|
return 2
|
||||||
fi
|
fi
|
||||||
if [[ "${action}" == "--help" || "${action}" == "help" ]]; then
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
rpi_host="${LAB_RPI_HOST:-${LAB_RASPBERRY_HOST:-192.168.100.89}}"
|
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_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_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_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
|
case "${action}" in
|
||||||
|
nfs-stage)
|
||||||
|
"${REPO_ROOT}/scripts/rpi4-nfs-stage" "${3:-plan}" "${4:-}"
|
||||||
|
;;
|
||||||
status)
|
status)
|
||||||
echo "== RPi4 host bootstrap status =="
|
echo "== RPi4 host bootstrap status =="
|
||||||
echo "target=${rpi_user}@${rpi_host} key=${rpi_key}"
|
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
|
echo "LAB_RPI4_OS_PROVISIONER_COMMAND is required for RPi4 OS installation; refusing to guess a disk or boot target." >&2
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
if [[ "${LAB_RPI4_INSTALL_DEVICE:-}" != "/dev/mmcblk0" ]]; then
|
if [[ "${LAB_RPI4_INSTALL_DEVICE:-/dev/mmcblk0}" != "/dev/mmcblk0" ]]; then
|
||||||
echo "Set LAB_RPI4_INSTALL_DEVICE=/dev/mmcblk0 explicitly before applying the RPi4 image." >&2
|
echo "RPi4 installs are fixed to /dev/mmcblk0; refusing a different target." >&2
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
if ssh -i "${rpi_key}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \
|
if ssh -i "${rpi_key}" -o BatchMode=yes -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new \
|
||||||
|
|
|
||||||
|
|
@ -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 <<EOF
|
||||||
|
RPi4 NFS staging plan
|
||||||
|
=====================
|
||||||
|
source: ${rpi_user}@${rpi_host}
|
||||||
|
server: ${server_ip}
|
||||||
|
TFTP root: ${tftp_root}
|
||||||
|
NFS root: ${nfs_root}
|
||||||
|
|
||||||
|
This copies the current RPi4 boot and root filesystems into a per-device
|
||||||
|
network-root tree. It does not erase the SD card or reboot the Pi.
|
||||||
|
EOF
|
||||||
|
;;
|
||||||
|
apply)
|
||||||
|
[[ "${2:-}" == "--yes" ]] || { echo "Use: scripts/rpi4-nfs-stage apply --yes" >&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
|
||||||
Loading…
Reference in New Issue