From 2f8eaf4f18bef8258465155d27f41a56c6238c5f Mon Sep 17 00:00:00 2001
From: CodingWonders <101426328+CodingWonders@users.noreply.github.com>
Date: Fri, 6 Dec 2024 08:55:02 +0100
Subject: [PATCH] Add VirtIO functionality and more enhancements
- Added the ability to grab VirtIO Guest Tools
- Modified the description of the Copy ISO files function because it basically had nonsense
---
functions/microwin/Invoke-Microwin.ps1 | 7 ++++
functions/microwin/Invoke-MicrowinGetIso.ps1 | 4 +-
functions/microwin/Microwin-CopyVirtIO.ps1 | 40 ++++++++++++++++++++
functions/private/Copy-Files.ps1 | 18 ++++++---
xaml/inputXML.xaml | 1 +
5 files changed, 62 insertions(+), 8 deletions(-)
create mode 100644 functions/microwin/Microwin-CopyVirtIO.ps1
diff --git a/functions/microwin/Invoke-Microwin.ps1 b/functions/microwin/Invoke-Microwin.ps1
index 077f4711..1d012613 100644
--- a/functions/microwin/Invoke-Microwin.ps1
+++ b/functions/microwin/Invoke-Microwin.ps1
@@ -55,6 +55,8 @@ public class PowerManagement {
$injectDrivers = $sync.MicrowinInjectDrivers.IsChecked
$importDrivers = $sync.MicrowinImportDrivers.IsChecked
+ $importVirtIO = $sync.MicrowinCopyVirtIO.IsChecked
+
$mountDir = $sync.MicrowinMountDir.Text
$scratchDir = $sync.MicrowinScratchDir.Text
@@ -155,6 +157,11 @@ public class PowerManagement {
}
}
+ if ($importVirtIO) {
+ Write-Host "Copying VirtIO drivers..."
+ Microwin-CopyVirtIO
+ }
+
Write-Host "Remove Features from the image"
Microwin-RemoveFeatures
Write-Host "Removing features complete!"
diff --git a/functions/microwin/Invoke-MicrowinGetIso.ps1 b/functions/microwin/Invoke-MicrowinGetIso.ps1
index 43f4caed..aa4e9c7c 100644
--- a/functions/microwin/Invoke-MicrowinGetIso.ps1
+++ b/functions/microwin/Invoke-MicrowinGetIso.ps1
@@ -242,8 +242,8 @@ function Invoke-MicrowinGetIso {
# xcopy we can verify files and also not copy files that already exist, but hard to measure
# xcopy.exe /E /I /H /R /Y /J $DriveLetter":" $mountDir >$null
- $totalTime = Measure-Command { Copy-Files "$($driveLetter):" $mountDir -Recurse -Force }
- Write-Host "Copy complete! Total Time: $($totalTime.Minutes)m$($totalTime.Seconds)s"
+ $totalTime = Measure-Command { Copy-Files "$($driveLetter):" "$mountDir" -Recurse -Force }
+ Write-Host "Copy complete! Total Time: $($totalTime.Minutes) minutes, $($totalTime.Seconds) seconds"
$wimFile = "$mountDir\sources\install.wim"
Write-Host "Getting image information $wimFile"
diff --git a/functions/microwin/Microwin-CopyVirtIO.ps1 b/functions/microwin/Microwin-CopyVirtIO.ps1
new file mode 100644
index 00000000..d050d6dc
--- /dev/null
+++ b/functions/microwin/Microwin-CopyVirtIO.ps1
@@ -0,0 +1,40 @@
+function Microwin-CopyVirtIO {
+ <#
+ .SYNOPSIS
+ Downloads and copies the VirtIO Guest Tools drivers to the target MicroWin ISO
+ .NOTES
+ A network connection must be available and the servers of Fedora People must be up. Automatic driver installation will not be added yet - I want this implementation to be reliable.
+ #>
+
+ try {
+ Write-Host "Checking existing files..."
+ if (Test-Path -Path "$($env:TEMP)\virtio.iso" -PathType Leaf) {
+ Write-Host "VirtIO ISO has been detected. Deleting..."
+ Remove-Item -Path "$($env:TEMP)\virtio.iso" -Force
+ }
+ Write-Host "Getting latest VirtIO drivers. Please wait. This can take some time, depending on your network connection speed and the speed of the servers..."
+ Start-BitsTransfer -Source "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" -Destination "$($env:TEMP)\virtio.iso" -DisplayName "Downloading VirtIO drivers..."
+ # Do everything else if the VirtIO ISO exists
+ if (Test-Path -Path "$($env:TEMP)\virtio.iso" -PathType Leaf) {
+ Write-Host "Mounting ISO. Please wait."
+ $virtIO_ISO = Mount-DiskImage -PassThru "$($env:TEMP)\virtio.iso"
+ $driveLetter = (Get-Volume -DiskImage $virtIO_ISO).DriveLetter
+ # Create new directory for VirtIO on ISO
+ New-Item -Path "$mountDir\VirtIO" -ItemType Directory | Out-Null
+ $totalTime = Measure-Command { Copy-Files "$($driveLetter):" "$mountDir\VirtIO" -Recurse -Force }
+ Write-Host "VirtIO contents have been successfully copied. Time taken: $($totalTime.Minutes) minutes, $($totalTime.Seconds) seconds`n"
+ Get-Volume $driveLetter | Get-DiskImage | Dismount-DiskImage
+ Remove-Item -Path "$($env:TEMP)\virtio.iso" -Force -ErrorAction SilentlyContinue
+ Write-Host "To proceed with installation of the MicroWin image in QEMU/Proxmox VE:"
+ Write-Host "1. Proceed with Setup until you reach the disk selection screen, in which you won't see any drives"
+ Write-Host "2. Click `"Load Driver`" and click Browse"
+ Write-Host "3. In the folder selection dialog, point to this path:`n`n `"D:\VirtIO\vioscsi\w11\amd64`" (replace amd64 with ARM64 if you are using Windows on ARM, and `"D:`" with the drive letter of the ISO)`n"
+ Write-Host "4. Select all drivers that will appear in the list box and click OK"
+ } else {
+ throw "Could not download VirtIO drivers"
+ }
+ } catch {
+ Write-Host "We could not download and/or prepare the VirtIO drivers. Error information: $_`n"
+ Write-Host "You will need to download these drivers manually. Location: https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso"
+ }
+}
diff --git a/functions/private/Copy-Files.ps1 b/functions/private/Copy-Files.ps1
index fafb4b51..cec7869a 100644
--- a/functions/private/Copy-Files.ps1
+++ b/functions/private/Copy-Files.ps1
@@ -2,11 +2,17 @@ function Copy-Files {
<#
.DESCRIPTION
- This function will make all modifications to the registry
-
+ Copies the contents of a given ISO file to a given destination
+ .PARAMETER Path
+ The source of the files to copy
+ .PARAMETER Destination
+ The destination to copy the files to
+ .PARAMETER Recurse
+ Determines whether or not to copy all files of the ISO file, including those in subdirectories
+ .PARAMETER Force
+ Determines whether or not to overwrite existing files
.EXAMPLE
-
- Set-WinUtilRegistry -Name "PublishUserActivities" -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System" -Type "DWord" -Value "0"
+ Copy-Files "D:" "C:\ISOFile" -Recurse -Force
#>
param (
@@ -23,7 +29,7 @@ function Copy-Files {
foreach ($file in $files) {
$status = "Copying file {0} of {1}: {2}" -f $counter, $files.Count, $file.Name
- Write-Progress -Activity "Copy Windows files" -Status $status -PercentComplete ($counter++/$files.count*100)
+ Write-Progress -Activity "Copy disc image files" -Status $status -PercentComplete ($counter++/$files.count*100)
$restpath = $file.FullName -Replace $path, ''
if ($file.PSIsContainer -eq $true) {
@@ -35,7 +41,7 @@ function Copy-Files {
Set-ItemProperty -Path ($destination+$restpath) -Name IsReadOnly -Value $false
}
}
- Write-Progress -Activity "Copy Windows files" -Status "Ready" -Completed
+ Write-Progress -Activity "Copy disc image files" -Status "Ready" -Completed
} catch {
Write-Host "Unable to Copy all the files due to an unhandled exception" -ForegroundColor Yellow
Write-Host "Error information: $($_.Exception.Message)`n" -ForegroundColor Yellow
diff --git a/xaml/inputXML.xaml b/xaml/inputXML.xaml
index c8eb4100..5f36750f 100644
--- a/xaml/inputXML.xaml
+++ b/xaml/inputXML.xaml
@@ -1175,6 +1175,7 @@
ToolTip="Path to unpacked drivers all sys and inf files for devices that need drivers"
/>
+