Improve network boot troubleshooting documentation and initramfs scripts

Update NETWORK-BOOT-TROUBLESHOOTING.md to clarify the boot process and emphasize the need to disable PXE before rebooting to ensure EEPROM updates are applied. Enhance initramfs scripts to improve DHCP lease acquisition and capture the device's IP address more reliably. Add a revision tracking feature to the initramfs build process for better version control. Modify provisioning-client.sh to ensure proper reboot handling after deployment and backup actions.
This commit is contained in:
nearxos
2026-02-21 12:57:26 +02:00
parent a6e27219f4
commit ea6f846021
6 changed files with 106 additions and 18 deletions

View File

@@ -7,6 +7,8 @@ export PATH=/bin:/usr/bin
export LD_LIBRARY_PATH=/lib
echo "=== CM4 provisioning initramfs ==="
# Revision is set at build time; cat /revision.txt to confirm you have the latest initrd on TFTP
[ -f /revision.txt ] && echo "Revision: $(cat /revision.txt)" || echo "Revision: (none)"
# Minimal filesystem
mount -t proc none /proc
@@ -15,13 +17,28 @@ mount -t devtmpfs none /dev
mkdir -p /dev/pts
mount -t devpts none /dev/pts
# Kernel might have brought up eth0 via ip=dhcp; ensure we have an IP (run in background with timeout so we don't block rescue shell)
if ! ip addr show | grep -q 'inet .* scope global'; then
# Bring up eth0 (bootloader used it for TFTP but kernel starts with it down)
echo "Bringing up eth0..."
ip link set lo up 2>/dev/null || true
ip link set eth0 up 2>/dev/null || true
# Wait for link (PHY negotiation takes a few seconds after ip link set up)
echo "Waiting for link..."
for _ in 1 2 3 4 5 6 7 8 9 10; do
ip link show eth0 2>/dev/null | grep -q 'LOWER_UP' && break
sleep 1
done
# Get DHCP lease (foreground with retries; -q exits after obtaining lease)
if ! ip addr show eth0 2>/dev/null | grep -q 'inet [0-9]'; then
echo "Getting DHCP lease..."
( udhcpc -f -q -i eth0 -n -T 5 2>/dev/null || true ) &
sleep 6
udhcpc -i eth0 -q -T 5 -t 5 -n -s /usr/share/udhcpc/default.script 2>&1 || echo "udhcpc failed (will retry)"
fi
# /tmp for client_ip (so client can read IP without running ip/awk)
mkdir -p /tmp
mount -t tmpfs none /tmp 2>/dev/null || true
# Allow kernel cmdline to override: provisioning_server=... and rescue mode
RESCUE=0
for arg in $(cat /proc/cmdline); do
@@ -42,5 +59,13 @@ if [ "$RESCUE" -eq 1 ]; then
fi
echo "Provisioning server: $PROVISIONING_SERVER"
# Capture eth0 IP; retry in case DHCP is still completing
for _ in 1 2 3 4 5; do
ip addr show dev eth0 2>/dev/null | awk '/inet [0-9]/ { print $2; exit }' | cut -d/ -f1 > /tmp/client_ip 2>/dev/null || true
[ -s /tmp/client_ip ] && break
echo "Waiting for IP on eth0..."
sleep 2
done
echo "Client IP: $(cat /tmp/client_ip 2>/dev/null || echo '(none)')"
echo "Running provisioning client..."
exec /bin/sh /provisioning-client.sh