The recursive search returned vioserial/2k12 first (alphabetical), and pnputil rejects it on Server 2022 with -536870325. The agent MSI installed fine (exit 0) but never had a channel. Pick the folder from the OS build and fall back through the other amd64 builds until one succeeds.
147 lines
7.1 KiB
PowerShell
147 lines
7.1 KiB
PowerShell
# Norbourg lab — first-boot bootstrap, runs once from the seed ISO.
|
|
# The unattend file creates the account and triggers this; everything that
|
|
# touches the network happens here because unattend TCPIP settings fail
|
|
# silently when the adapter name does not match.
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$base = 'C:\norbourg'
|
|
New-Item -ItemType Directory -Force -Path $base | Out-Null
|
|
Start-Transcript -Path "$base\bootstrap.log" -Append | Out-Null
|
|
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
. (Join-Path $here 'config.ps1')
|
|
|
|
Write-Host "bootstrap: host=$($Config.Hostname) role=$($Config.Role) ip=$($Config.IP)"
|
|
|
|
# ------------------------------------------------------------------ network
|
|
$nic = Get-NetAdapter |
|
|
Where-Object { $_.Status -eq 'Up' -and $_.InterfaceDescription -notmatch 'Loopback' } |
|
|
Select-Object -First 1
|
|
|
|
if (-not $nic) {
|
|
Write-Host 'bootstrap: no up adapter, network step skipped'
|
|
} else {
|
|
Remove-NetIPAddress -InterfaceIndex $nic.ifIndex -Confirm:$false -ErrorAction SilentlyContinue
|
|
Remove-NetRoute -InterfaceIndex $nic.ifIndex -Confirm:$false -ErrorAction SilentlyContinue
|
|
|
|
New-NetIPAddress -InterfaceIndex $nic.ifIndex `
|
|
-IPAddress $Config.IP -PrefixLength $Config.Prefix `
|
|
-DefaultGateway $Config.Gateway | Out-Null
|
|
|
|
Set-DnsClientServerAddress -InterfaceIndex $nic.ifIndex -ServerAddresses $Config.DNS
|
|
Set-NetConnectionProfile -InterfaceIndex $nic.ifIndex -NetworkCategory Private -ErrorAction SilentlyContinue
|
|
|
|
# Cosmetic: silence the "make this PC discoverable" flyout that the IP
|
|
# change re-triggers. New-Item -Force throws on this protected key, and a
|
|
# Stop preference would abort the whole bootstrap — so it must not throw.
|
|
try {
|
|
New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Network' `
|
|
-Name NewNetworkWindowOff -Value 1 -PropertyType DWord -Force -ErrorAction Stop | Out-Null
|
|
} catch {
|
|
Write-Host "bootstrap: flyout tweak skipped ($($_.Exception.Message))"
|
|
}
|
|
|
|
Write-Host "bootstrap: $($nic.Name) -> $($Config.IP)/$($Config.Prefix)"
|
|
}
|
|
|
|
# ------------------------------------------------------------------ WinRM
|
|
# The host provisions over WinRM; no guest agent needed for that.
|
|
Enable-PSRemoting -SkipNetworkProfileCheck -Force | Out-Null
|
|
Set-NetFirewallRule -DisplayGroup 'Windows Remote Management' -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
|
|
|
# SMB: the eval image leaves File and Printer Sharing disabled, which makes the
|
|
# workstation invisible to a normal SMB scan.
|
|
Enable-NetFirewallRule -DisplayGroup 'File and Printer Sharing' -ErrorAction SilentlyContinue
|
|
|
|
# ICMP echo: Windows drops it by default, and "ping the DC" is the first thing
|
|
# anyone does. A lab where ping fails looks broken even when it is not.
|
|
if (-not (Get-NetFirewallRule -DisplayName 'Norbourg ICMPv4' -ErrorAction SilentlyContinue)) {
|
|
New-NetFirewallRule -DisplayName 'Norbourg ICMPv4' -Protocol ICMPv4 -IcmpType 8 `
|
|
-Direction Inbound -Action Allow -Profile Any | Out-Null
|
|
}
|
|
|
|
# QEMU guest agent. Proxmox provisions over `qm guest exec`, which needs it.
|
|
# virtio-win is attached as a CD on that platform; on qemu it is absent and
|
|
# this block does nothing.
|
|
try {
|
|
# Find the virtio CD by its content, not by volume label: the label is
|
|
# not reliable across images and an empty one silently skipped the whole
|
|
# block (no driver, no agent, no provisioning).
|
|
$virtioRoot = $null
|
|
foreach ($drv in (Get-PSDrive -PSProvider FileSystem -ErrorAction SilentlyContinue)) {
|
|
if (Test-Path "$($drv.Root)guest-agent\qemu-ga-x86_64.msi") {
|
|
$virtioRoot = $drv.Root
|
|
break
|
|
}
|
|
}
|
|
if ($virtioRoot) {
|
|
# The agent MSI does not install the VirtIO serial driver. Without it
|
|
# the service starts but never connects to the channel, and Proxmox
|
|
# shows "guest agent is not running", which blocks provisioning.
|
|
# Pick the driver for this Windows build first (2k12 first in the
|
|
# directory made pnputil reject it on Server 2022), then fall back to
|
|
# the other amd64 builds until one reports success.
|
|
$build = [Environment]::OSVersion.Version.Build
|
|
$pref = '2k12'
|
|
if ($build -ge 26100) { $pref = '2k25' } elseif ($build -ge 20348) { $pref = '2k22' } elseif ($build -ge 17763) { $pref = '2k19' } elseif ($build -ge 14393) { $pref = '2k16' }
|
|
$candidates = @($pref, '2k25', '2k22', 'w11', '2k19', '2k16', '2k12') |
|
|
Select-Object -Unique
|
|
$driverOk = $false
|
|
foreach ($v in $candidates) {
|
|
$inf = Join-Path $virtioRoot "vioserial\$v\amd64\vioser.inf"
|
|
if (-not (Test-Path $inf)) { continue }
|
|
$null = pnputil.exe /add-driver $inf /install
|
|
Write-Host "bootstrap: vioser $v exit=$LASTEXITCODE"
|
|
if ($LASTEXITCODE -eq 0) { $driverOk = $true; break }
|
|
}
|
|
if (-not $driverOk) {
|
|
Write-Host 'bootstrap: no vioser driver could be installed'
|
|
}
|
|
|
|
$msi = "$($virtioRoot)guest-agent\qemu-ga-x86_64.msi"
|
|
if (Test-Path $msi) {
|
|
$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'
|
|
} else {
|
|
Write-Host 'bootstrap: virtio-win mounted but qemu-ga msi not found'
|
|
}
|
|
}
|
|
} catch {
|
|
Write-Host "bootstrap: guest agent step skipped ($($_.Exception.Message))"
|
|
}
|
|
|
|
# RDP: useful for the instructor when a step misbehaves. This only opens the
|
|
# listener; who may log on is still governed by Remote Desktop Users.
|
|
try {
|
|
Set-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Terminal Server' `
|
|
-Name fDenyTSConnections -Value 0 -ErrorAction Stop
|
|
Set-Service -Name TermService -StartupType Automatic -ErrorAction SilentlyContinue
|
|
Start-Service -Name TermService -ErrorAction SilentlyContinue
|
|
Enable-NetFirewallRule -DisplayGroup 'Remote Desktop' -ErrorAction SilentlyContinue
|
|
Write-Host 'bootstrap: RDP enabled'
|
|
} catch {
|
|
Write-Host "bootstrap: RDP setup failed ($($_.Exception.Message))"
|
|
}
|
|
|
|
# ------------------------------------------------------------------ marker
|
|
"$env:COMPUTERNAME|$($Config.Role)|$($Config.IP)|$((Get-Date).ToString('s'))" |
|
|
Set-Content -Path "$base\stamp.txt" -Encoding ascii
|
|
|
|
# ------------------------------------------------------------------ role
|
|
# The role stages are driven by the host (`./lab.sh provision`), which orders
|
|
# them: the DC must be promoted before a member tries to join. Running them
|
|
# here as well made every guest race the harness — fs01 joined before the
|
|
# domain existed, and dc01 ran two promotions at once.
|
|
$role = Join-Path $here "roles\$($Config.Role).ps1"
|
|
if (Test-Path $role) {
|
|
Write-Host "bootstrap: role $($Config.Role) staged, waiting for ./lab.sh provision"
|
|
} else {
|
|
Write-Host "bootstrap: no role script for '$($Config.Role)' yet (phase 5)"
|
|
}
|
|
|
|
Write-Host 'bootstrap: done'
|
|
Stop-Transcript | Out-Null
|