Create suitable Microsoft Windows images for CI.
This work was sponsored by NetworkRADIUS.
- currently only tested with
- Windows 11
- Windows 10
- should work with locales other than en-us, but untested
- ...still yet to describe how to use this image (ie. through WinRM and/or OpenSSH) for CI purposes.
- we assume if running on Linux, SPICE is available
- find a way to disable Windows Defender from the CLI without a reboot
-
this does not work as the 'Tamper Protection' needs to be disabled from meat space:
powershell.exe -Command "Set-MpPreference -DisableRealTimeMonitoring $true"
-
You will need the following installed:
- QEMU (tested with 7.0.0)
- output of
qemu-system-x86_64 -accel help
must list- Linux:
kvm
- macOS (Intel):
hvf
- Linux:
- if you wish to use non-accelerated (
tcg
) mode, Windows will install and run really slowly, but you will also need to uncommentwinrm_timeout
insetup.pkr.hcl
and set it to a multi-hour value
- output of
- either:
- VNC client
- SPICE client
- though SPICE provides a nicer user experience, it is a lot of work to get SPICE working under macOS so it is recommended you stick with VNC
curl
- GNU
make
- macOS users will need to run
gmake
wheremake
is described instead
- macOS users will need to run
m4
unzip
Before starting to build the image, you need to download either a Windows 11 Insider Preview ISO (tested with Dev Channel, tested with build 25227, filename Windows11_InsiderPreview_Client_x64_en-us_25227.iso
) or Windows 10 ISO (tested with 22H2, filename Win10_22H2_English_x64.iso
) into the top of project directory.
Make sure you have at least 30 GiB of disk space to work with.
Create the image using:
make CORES=2 RAM=4096
Where:
IMAGE
(default: first glob matchWindows11_*_x64*.iso
,Win11_*_x64*.iso
andWin10_*.iso
in sorted descending order): ISO image to use- examples are
Win11_22H2_EnglishInternational_x64v2.iso
,Windows11_InsiderPreview_Client_x64_en-us_25227.iso
andWin10_22H2_English_x64.iso
- examples are
CORES
(default:2
, must be more than 1): number of CPUs to provide to the VMRAM
(default:4096
): amount of RAM to provide to the VM in MiBACCEL
(default: suitable for your OS): QEMU accelerator to use- Linux:
kvm
- macOS:
hvf
- Linux:
SPICE
(default: on Linux5930
, otherwise0
): port to connect on- zero (
0
) forcible disables SPICE
- zero (
N.B. to see detailed debugging, set the environment variable PACKER_LOG=1
If you wish to use VNC (for example if you are a macOS user) then you should look in the packer
console output for:
...
qemu.main: The VM will be run headless, without a GUI. If you want to
qemu.main: view the screen of the VM, connect via VNC without a password to
qemu.main: vnc://127.0.0.1:5909
...
Then point your VNC client at the proto://host:port
it lists; the example here shows vnc://127.0.0.1:5909
so you could connect with:
vncviewer 127.0.0.1:5909
Or:
vncviewer :5909
Or:
vncviewer :9
For a better and faster experience, you should use SPICE which you can connect with:
make spice SPICE=5930
Where:
SPICE
(default:5930
): port to connect on
Once the image has built (typical build time is 30 minutes), the single output artefact is a qcow2 image located at output-main/packer-main
.
To start a VM using this image, run:
make vm CORES=2 RAM=4096 VNC=5900 SSH=2222 SPICE=5930 WINRM=5985 RDP=3389
Points of interest:
-
you will be presented with the QEMU monitor
-
you can access the VM either using
- Graphically
- your VNC viewer (defaults to
:0
aka port5900
, or if that is in use increments to the next free port) make spice
as before- use an RDP (Remote Desktop) client pointing at
3389/tcp
- your VNC viewer (defaults to
- Terminal connect over
localhost
(bound to127.0.0.1
) usingAdministrator
/password
as your credentials- WinRM to
5930/tcp
- SSH to
2222/tcp
- if SCP does not work for you, try including the
-O
parameter to use the legacy SCP protocol which seems to work
- if SCP does not work for you, try including the
- WinRM to
- Graphically
-
we use the image in 'snapshot' mode with means nothing is persisted back to the image
-
if you wish to persist your changes you should halt (not shutdown) your VM and run from the monitor console
commit all quit
-
image has an snapshot called 'initial' which provides you with a point to restore to using
qemu-img snapshot -a initial output-main/packer-main