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.
This commit is contained in:
2026-10-26 17:23:05 -04:00
parent bcc370d70f
commit 06a9034214
3 changed files with 42 additions and 3 deletions
+3 -2
View File
@@ -83,14 +83,15 @@ try {
Where-Object { $_.FullName -match 'amd64' } | Select-Object -First 1 Where-Object { $_.FullName -match 'amd64' } | Select-Object -First 1
if ($vioser) { if ($vioser) {
$null = pnputil.exe /add-driver $vioser.FullName /install $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 { } else {
Write-Host 'bootstrap: vioser.inf not found on the virtio CD' Write-Host 'bootstrap: vioser.inf not found on the virtio CD'
} }
$msi = "$($virtioRoot)guest-agent\qemu-ga-x86_64.msi" $msi = "$($virtioRoot)guest-agent\qemu-ga-x86_64.msi"
if (Test-Path $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 Set-Service -Name QEMU-GA -StartupType Automatic -ErrorAction SilentlyContinue
Start-Service -Name QEMU-GA -ErrorAction SilentlyContinue Start-Service -Name QEMU-GA -ErrorAction SilentlyContinue
Write-Host 'bootstrap: qemu guest agent installed' Write-Host 'bootstrap: qemu guest agent installed'
+2
View File
@@ -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. `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. `reset` ne touche pas aux Kali : `./lab.sh kali reset` les recrée séparément.
### Sans accès au serveur git ### Sans accès au serveur git
+37 -1
View File
@@ -90,6 +90,9 @@ backend_check() {
_c_fail "genisoimage or xorriso required to build seed ISOs" _c_fail "genisoimage or xorriso required to build seed ISOs"
fi 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 # participant Kali clones
local kali_count=${KALI_COUNT:-0} local kali_count=${KALI_COUNT:-0}
if (( kali_count > 0 )); then if (( kali_count > 0 )); then
@@ -436,10 +439,43 @@ CONF
# After a successful install, stop booting from the installer CD: otherwise # After a successful install, stop booting from the installer CD: otherwise
# every boot waits five seconds and a stray keypress re-enters Setup. # every boot waits five seconds and a stray keypress re-enters Setup.
backend_finalize() { backend_finalize() {
local name=$1 vmid local name=$1 vmid ip deadline
vmid=$(pve_vmid "$name") vmid=$(pve_vmid "$name")
ip=$(pve_ip "$name")
qm set "$vmid" --boot 'order=sata0' --delete ide2 >/dev/null 2>&1 || true qm set "$vmid" --boot 'order=sata0' --delete ide2 >/dev/null 2>&1 || true
ok "$(printf '%-6s boots from disk (installer ISO detached)' "$name")" 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 # ------------------------------------------------------------------ kali