Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added build time custom driver injection support. #239

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions windows/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ else
EDIT ?= SERVERSTANDARD
endif

ifeq ($(wildcard /usr/share/OVMF/OVMF_CODE.fd),)
OVMF_SFX ?= _4M
else
OVMF_SFX ?=
endif

.PHONY: all clean

all: windows

$(eval $(call check_packages_deps,cloud-image-utils ovmf,cloud-image-utils ovmf))

OVMF_VARS.fd: /usr/share/OVMF/OVMF_VARS*.fd
cp -v $< $@

http/Autounattend.xml: http/Autounattend.xml.${BOOT}.template
sed s#@VERSION@#"${TYPE} ${VERSION} ${EDIT}"#g $< > $@
ifneq ($(strip $(PKEY)),)
ifneq ($(strip $(PKEY1)),)
sed -i s#@PKEY@#${PKEY}#g $@
sed -i 's/<!--<ProductKey>/<ProductKey>/;s/<\/ProductKey>-->/<\/ProductKey>/' $@
endif
Expand All @@ -40,10 +49,17 @@ else ifeq ($(strip $(VERSION)),11)
sed -i 's/<!--<LocalAccounts>/<LocalAccounts>/;s/<\/LocalAccounts>-->/<\/LocalAccounts>/' $@
endif

.INTERMEDIATE: http/Autounattend.xml
extra_drivers:
mkisofs -o drivers.iso -V 'Extra Drivers' -input-charset utf-8 drivers

.INTERMEDIATE: extra_drivers http/Autounattend.xml

windows: check-deps clean http/Autounattend.xml
${PACKER} init . && ${PACKER} build -var iso_path=${ISO} -var headless=${HEADLESS} windows.pkr.hcl
windows: check-deps clean extra_drivers http/Autounattend.xml OVMF_VARS.fd
${PACKER} init . && ${PACKER} build -var iso_path=${ISO} \
-var headless=${HEADLESS} \
-var ovmf_suffix=${OVMF_SFX} \
windows.pkr.hcl

clean:
${RM} -rf output-* windows.dd.gz http/Autounattend.xml
${RM} -rf output-* windows.tar.gz http/Autounattend.xml \
drivers.iso OVMF_VARS.fd
14 changes: 14 additions & 0 deletions windows/drivers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#### Extra Windows drivers
Place all extra Windows drivers under infs directory.

Please note that these drivers will be installed using
dpinst.exe which does not support scanning sub directories.

This requires all drivers to be present directly under the
infs directory.

These can include custom Windows drivers needed by certain
hardware components to function, either becuase the drivers
are not natively availble in Windows or would require extra
optimization.

Empty file added windows/drivers/infs/.gitignore
Empty file.
Empty file added windows/drivers/infs/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions windows/http/logon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ try
# Download the WDK installer.
$Host.UI.RawUI.WindowTitle = "Downloading Windows Driver Kit..."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest "http://download.microsoft.com/download/0/8/C/08C7497F-8551-4054-97DE-60C0E510D97A/wdk/wdksetup.exe" -Outfile "c:\wdksetup.exe"
Invoke-WebRequest "https://download.microsoft.com/download/8/6/9/86925F0F-D57A-4BA4-8278-861B6876D78E/wdk/wdksetup.exe" -Outfile "c:\wdksetup.exe"

# Run the installer.
$Host.UI.RawUI.WindowTitle = "Installing Windows Driver Kit..."
Expand All @@ -75,7 +75,7 @@ try

# Run dpinst.exe with the path to the drivers.
$Host.UI.RawUI.WindowTitle = "Injecting Windows drivers..."
$dpinst = "$programFilesDir\Windows Kits\8.1\redist\DIFx\dpinst\EngMui\$archDir\dpinst.exe"
$dpinst = "$ENV:ProgramFiles (x86)\Windows Kits\8.1\redist\DIFx\dpinst\EngMui\x64\dpinst.exe"
Start-Process -Wait -FilePath "$dpinst" -ArgumentList "/S /C /F /SA /Path E:\infs"

# Uninstall the WDK
Expand Down
31 changes: 24 additions & 7 deletions windows/windows.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
variable "iso_path" {
type = string
default = ""
}

packer {
required_version = ">= 1.7.0"
required_plugins {
Expand All @@ -19,6 +14,22 @@ variable "headless" {
description = "Whether VNC viewer should not be launched."
}

variable "iso_path" {
type = string
default = ""
}

variable "ovmf_suffix" {
type = string
default = "_4M"
}

variable "filename" {
type = string
default = "windows.dd.gz"
description = "The filename of the tarball to produce"
}

source "qemu" "windows_builder" {
accelerator = "kvm"
boot_command = ["<enter>"]
Expand All @@ -38,7 +49,13 @@ source "qemu" "windows_builder" {
cpus = "2"
net_device = "e1000"
qemuargs = [
["-serial", "stdio"], ["-bios", "/usr/share/OVMF/OVMF_CODE.fd"]
["-serial", "stdio"],
["-drive", "if=pflash,format=raw,id=ovmf_code,readonly=on,file=/usr/share/OVMF/OVMF_CODE${var.ovmf_suffix}.fd"],
["-drive", "if=pflash,format=raw,id=ovmf_vars,file=OVMF_VARS.fd"],
["-drive", "file=output-windows_builder/packer-windows_builder,format=raw"],
["-cdrom", "${var.iso_path}"],
["-drive", "file=drivers.iso,media=cdrom,index=3"],
["-boot", "d"]
]
shutdown_timeout = "45m"
vnc_bind_address = "0.0.0.0"
Expand Down Expand Up @@ -66,6 +83,6 @@ build {
inline_shebang = "/bin/bash -e"
}
post-processor "compress" {
output = "windows.dd.gz"
output = "${var.filename}"
}
}
Loading