From 6dfcf10446a924f3f08b83251d938c9c72598c57 Mon Sep 17 00:00:00 2001 From: marco Date: Wed, 12 Nov 2025 14:34:12 +0100 Subject: [PATCH] Add Prep-VirtIODrivers.ps1 --- Prep-VirtIODrivers.ps1 | 129 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 Prep-VirtIODrivers.ps1 diff --git a/Prep-VirtIODrivers.ps1 b/Prep-VirtIODrivers.ps1 new file mode 100644 index 0000000..dc05dc3 --- /dev/null +++ b/Prep-VirtIODrivers.ps1 @@ -0,0 +1,129 @@ +<# +.SYNOPSIS +Pre-stage VirtIO drivers on a VMware Windows Server 2025 VM prior to migration to Proxmox. + +.DESCRIPTION +- Downloads (or uses provided) virtio-win.iso +- Mounts ISO and installs storage (vioscsi, viostor), network (NetKVM), balloon drivers +- Verifies driver install +- Unmounts ISO + +.PARAMETER IsoPath +Optional. Local path to virtio-win.iso if you already downloaded it. + +.PARAMETER Download +Switch. Force download latest virtio-win.iso from Fedora mirrors. + +.EXAMPLE +.\Prep-VirtIODrivers.ps1 -Download + +.EXAMPLE +.\Prep-VirtIODrivers.ps1 -IsoPath "C:\Temp\virtio-win.iso" +#> + +param( + [string]$IsoPath, + [switch]$Download +) + +# --- Require admin --- +if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent() + ).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Write-Error "Run this script in an elevated PowerShell (Run as Administrator)." + exit 1 +} + +$ErrorActionPreference = 'Stop' + +# --- Prepare working paths --- +$WorkDir = Join-Path $env:TEMP "virtio-prep" +New-Item -ItemType Directory -Force -Path $WorkDir | Out-Null + +if (-not $IsoPath -and -not $Download) { + # default to download + $Download = $true +} + +if ($Download) { + $IsoPath = Join-Path $WorkDir "virtio-win.iso" + Write-Host "Downloading latest virtio-win.iso..." -ForegroundColor Cyan + + # Primary URL (Fedora people direct-downloads) + $url = "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso" + try { + Invoke-WebRequest -Uri $url -OutFile $IsoPath -UseBasicParsing + } + catch { + Write-Host "Primary download failed, trying mirror..." -ForegroundColor Yellow + # Fallback mirror (if needed, simple same path assumption) + $url2 = "https://dl.fedoraproject.org/pub/alt/virtio-win/latest-virtio/virtio-win.iso" + Invoke-WebRequest -Uri $url2 -OutFile $IsoPath -UseBasicParsing + } + Write-Host "Downloaded to $IsoPath" -ForegroundColor Green +} +elseif (-not (Test-Path $IsoPath)) { + Write-Error "IsoPath not found: $IsoPath" + exit 1 +} + +# --- Mount ISO --- +Write-Host "Mounting ISO..." -ForegroundColor Cyan +$mount = Mount-DiskImage -ImagePath $IsoPath -PassThru +$vol = ($mount | Get-Volume) +$cd = $vol.DriveLetter + ":" +Write-Host "Mounted at $cd" -ForegroundColor Green + +# Driver roots (Windows Server 2025 uses the 'w11' folder) +$Paths = @( + Join-Path $cd "vioscsi\w11\amd64", # VirtIO SCSI storage + Join-Path $cd "viostor\w11\amd64", # VirtIO block storage + Join-Path $cd "NetKVM\w11\amd64", # VirtIO network + Join-Path $cd "Balloon\w11\amd64" # Memory balloon +) + +# --- Install drivers with pnputil (online) --- +Write-Host "Installing VirtIO drivers..." -ForegroundColor Cyan +foreach ($p in $Paths) { + if (Test-Path $p) { + Write-Host " -> $p" -ForegroundColor DarkCyan + # add + install all INF in this dir (no recurse needed; w11\amd64 holds INF) + pnputil /add-driver "$p\*.inf" /install | Out-Null + } else { + Write-Warning "Path not found: $p" + } +} + +# --- Optional extras (uncomment if you want them now) --- +# QXL display driver (not required for server core/headless): +# pnputil /add-driver "$cd\qxldod\w11\amd64\*.inf" /install | Out-Null +# VioSerial / pvpanic (not strictly required for boot): +# pnputil /add-driver "$cd\vioserial\w11\amd64\*.inf" /install | Out-Null +# pnputil /add-driver "$cd\pvpanic\w11\amd64\*.inf" /install | Out-Null + +# --- Verify key drivers staged --- +Write-Host "`nVerifying driver presence..." -ForegroundColor Cyan +$need = @('vioscsi','viostor','NetKVM','Balloon') +$drivers = (pnputil /enum-drivers) -join "`n" +foreach ($n in $need) { + if ($drivers -match $n) { + Write-Host (" [+] {0} present" -f $n) -ForegroundColor Green + } else { + Write-Warning (" [!] {0} NOT found in driver store" -f $n) + } +} + +# --- Unmount ISO --- +Write-Host "`nUnmounting ISO..." -ForegroundColor Cyan +Dismount-DiskImage -ImagePath $IsoPath + +Write-Host "`nAll done." -ForegroundColor Green +Write-Host "Next steps:" -ForegroundColor Yellow +Write-Host @" +1) Maak nu je Veeam backup (of export) van deze VM. +2) Herstel in Proxmox: + - Disk op **VirtIO SCSI** (controller: virtio-scsi-pci; boot: scsi0) + - NIC op **VirtIO (paravirtualized)** + - Voeg CD-ROM met virtio-win.iso toe voor het geval je nog wilt bij-installeren +3) Start de VM. Na eerste boot kun je (optioneel) 'virtio-win-guest-tools.exe' draaien + vanaf de ISO voor QEMU agent en aanvullende drivers. +"@