From 06a9034214284029d73955e84cf35ec7e3aeee9c Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Mon, 26 Oct 2026 17:23:05 -0400 Subject: [PATCH] proxmox: reboot once after the install so the guest agent can connect The agent MSI was installed at first logon, before the virtio-serial port existed. The service started without a channel and Proxmox kept reporting "guest agent is not running", which blocked provisioning at backend_ready. - backend_finalize now waits for the first-logon bootstrap to finish (stamp.txt over SMB, which does not need the agent), detaches the installer ISO, reboots the VM once and waits for the agent to answer. - bootstrap logs the pnputil and msiexec exit codes, so bootstrap.log says exactly what happened if it still fails. - check requires smbclient (site sync + finalize) and python3. - instructor guide: snapshot doubles disk usage, plan ~60 GB. --- session1/content/seed/payload/bootstrap.ps1 | 5 ++- session1/docs/instructeur.md | 2 + .../platforms/proxmox/backends/proxmox.sh | 38 ++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/session1/content/seed/payload/bootstrap.ps1 b/session1/content/seed/payload/bootstrap.ps1 index 5956df1..e0ae8a9 100644 --- a/session1/content/seed/payload/bootstrap.ps1 +++ b/session1/content/seed/payload/bootstrap.ps1 @@ -83,14 +83,15 @@ try { Where-Object { $_.FullName -match 'amd64' } | Select-Object -First 1 if ($vioser) { $null = pnputil.exe /add-driver $vioser.FullName /install - Write-Host "bootstrap: vioser driver installed from $($vioser.FullName)" + Write-Host "bootstrap: vioser add-driver exit=$LASTEXITCODE ($($vioser.FullName))" } else { Write-Host 'bootstrap: vioser.inf not found on the virtio CD' } $msi = "$($virtioRoot)guest-agent\qemu-ga-x86_64.msi" if (Test-Path $msi) { - Start-Process msiexec.exe -ArgumentList "/i `"$msi`" /qn /norestart" -Wait + $proc = Start-Process msiexec.exe -ArgumentList "/i `"$msi`" /qn /norestart" -Wait -PassThru + Write-Host "bootstrap: qemu-ga msi exit=$($proc.ExitCode)" Set-Service -Name QEMU-GA -StartupType Automatic -ErrorAction SilentlyContinue Start-Service -Name QEMU-GA -ErrorAction SilentlyContinue Write-Host 'bootstrap: qemu guest agent installed' diff --git a/session1/docs/instructeur.md b/session1/docs/instructeur.md index 5495369..50a8c21 100644 --- a/session1/docs/instructeur.md +++ b/session1/docs/instructeur.md @@ -171,6 +171,8 @@ de continuer si elle ne correspond pas à la machine. `reset` détruit la VM et la reclone depuis le gabarit : une copie de disque (quelques dizaines de secondes), pas de réinstallation. +Espace disque : le gabarit et la VM de travail sont deux copies complètes. Prévoyez le double de l'espace utilisé par les trois disques, soit environ 60 Go pour le laboratoire seul. + `reset` ne touche pas aux Kali : `./lab.sh kali reset` les recrée séparément. ### Sans accès au serveur git diff --git a/session1/platforms/proxmox/backends/proxmox.sh b/session1/platforms/proxmox/backends/proxmox.sh index d77ecc4..921b036 100644 --- a/session1/platforms/proxmox/backends/proxmox.sh +++ b/session1/platforms/proxmox/backends/proxmox.sh @@ -90,6 +90,9 @@ backend_check() { _c_fail "genisoimage or xorriso required to build seed ISOs" fi + have_cmd smbclient || _c_fail "smbclient required (apt install smbclient): site sync and install finalize" + have_cmd python3 || _c_fail "python3 required to read the guest agent output" + # participant Kali clones local kali_count=${KALI_COUNT:-0} if (( kali_count > 0 )); then @@ -436,10 +439,43 @@ CONF # After a successful install, stop booting from the installer CD: otherwise # every boot waits five seconds and a stray keypress re-enters Setup. backend_finalize() { - local name=$1 vmid + local name=$1 vmid ip deadline vmid=$(pve_vmid "$name") + ip=$(pve_ip "$name") + qm set "$vmid" --boot 'order=sata0' --delete ide2 >/dev/null 2>&1 || true ok "$(printf '%-6s boots from disk (installer ISO detached)' "$name")" + + # WinRM answers while the first-logon bootstrap is still running (it + # enables remoting early). Rebooting before stamp.txt exists would abort + # the agent install, so wait for the end marker first. SMB is already up + # and, unlike the agent, does not depend on vioser. + if have_cmd smbclient; then + deadline=$(( SECONDS + 300 )) + while (( SECONDS < deadline )); do + smbclient "//$ip/C\$" -W "$NETBIOS" -U "$LAB_USER%$LAB_ADMIN_PASSWORD" \ + -c 'ls norbourg\stamp.txt' >/dev/null 2>&1 && break + sleep 5 + done + else + warn "smbclient missing: cannot wait for the bootstrap marker, pausing 60 s" + sleep 60 + fi + + # The virtio-serial port appears on the next boot: the agent installed at + # first logon started before its device existed and never connected, so + # Proxmox reports "guest agent is not running". Reboot once and wait. + qm reboot "$vmid" >/dev/null 2>&1 || qm start "$vmid" >/dev/null 2>&1 || true + deadline=$(( SECONDS + 300 )) + while (( SECONDS < deadline )); do + if _qga "$name" cmd.exe /c exit >/dev/null 2>&1; then + ok "$(printf '%-6s guest agent answering' "$name")" + return 0 + fi + sleep 5 + done + warn "$name: guest agent still silent after the post-install reboot" + return 1 } # ------------------------------------------------------------------ kali