Skip to content

Build Microsoft Windows images for QEMU to run for the purposes of continuous integration (CI) including the VirtIO drivers and remote access enabled (WinRM, SSH and RDP)

License

Notifications You must be signed in to change notification settings

jimdigriz/winci

Repository files navigation

Build Microsoft Windows images for QEMU to run for the purposes of continuous integration (CI) including the VirtIO drivers and remote access enabled (WinRM, SSH and RDP).

This work was sponsored by InkBridge Networks.

Issues

  • ...still yet to describe how to use this image (ie. through WinRM and/or OpenSSH) for CI purposes
  • find a way to disable Windows Defender from the CLI without a reboot

Preflight

You will need the following installed:

You will also require the following assets:

Make sure you have at least 30 GiB of disk space to work with.

Building

Create the image using:

rm -rf output
env IMAGE=... CORES=2 RAM=4096 sh build.sh

Where:

  • IMAGE (required): ISO image to use
    • examples are Win11_24H2_EnglishInternational_x64.iso, Windows11_InsiderPreview_Client_x64_en-gb_26100.1150.iso
  • VIRTIO (default virtio-win.iso): VirtIO driver ISO image to use
  • CORES (default: 2, must be more than 1): number of CPUs to provide to the VM
  • RAM (default: 4096): amount of RAM to provide to the VM in MiB
  • ACCEL (default: suitable for your OS): QEMU accelerator to use
    • Linux: kvm:tcg
    • macOS: hvf:tcg
  • PASSWORD (default: password): password for Administrator account
  • SPICE (default: disabled): enable spice on UNIX socket name such as spice.sock

N.B. to see detailed debugging, set the environment variable PACKER_LOG=1

Monitoring the Build

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

SPICE

For a better and faster experience, you should use SPICE which you can connect with:

remote-viewer spice+unix://spice.sock

N.B. less CPU usage if you disable compression (--spice-preferred-compression=off)

Or alternatively (though not recommended):

spicy --uri spice+unix://spice.sock

Troubleshooting

If the build fails for some reasons, you should open a command prompt (Shift-F10) and use Notepad to read some .log or .xml files.

Usage

Once the image has built (typical build time is 30 minutes), the single output artefact is a qcow2 image located at output/packer-main.

To start a VM using this image, run:

env IMAGE=... CORES=2 RAM=4096 sh vm.sh

Where:

  • IMAGE (default output/packer-main): point to the QCOW2 image to use as the main disk
  • CORES/RAM/ACCEL/SPICE: as above for build.sh
  • VNC (default: 5900): port to listen for VNC connections
  • WINRM (default: 5985`): port to listen for WinRM connections
  • RDP (default: 3389): port to listen for RDP (remote desktop) connections
  • SSH (default: 2222): port to listen for SSH connections (connect using something like: ssh -o PasswordAuthentication=yes -p 2222 Administrator@localhost)
    • to use public key authentication, copy your public key(s) using something like:

      scp -o PasswordAuthentication=yes -P 2222 ~/.ssh/authorized_keys Administrator@localhost:"/ProgramData/ssh/administrators_authorized_keys"
      

Points of interest:

  • you will be presented with the QEMU monitor

  • if SCP does not work for you, try including the -O parameter to use the legacy SCP protocol which seems to work

  • image is used in 'snapshot' mode which 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/packer-main
    

Examples

About

Build Microsoft Windows images for QEMU to run for the purposes of continuous integration (CI) including the VirtIO drivers and remote access enabled (WinRM, SSH and RDP)

Topics

Resources

License

Stars

Watchers

Forks