Skip to content

Commit

Permalink
Merge pull request StefanScherer#216 from qmfrederik/features/qemu
Browse files Browse the repository at this point in the history
Add QEMU/KVM support for Windows 10, Windows 2019
  • Loading branch information
StefanScherer authored Nov 16, 2019
2 parents ce348ba + 7d587b0 commit bae4d5b
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ hyperv-iso output will be in this color.
* Secondary Dvd image does not exist: CreateFile ./iso/windows_server_insider_unattend.iso: The system cannot find the file specified.
```

### KVM/qemu support

If you are using Linux and have KVM/qemu configured, you can use these packerfiles to build a KVM virtual machine.
To build a KVM/qemu box, first make sure:

* You are a member of the kvm group on your machine. You can list the groups you are member of by running `groups`. It should
include the `kvm` group. If you're not a member, run `sudo usermod -aG kvm $(whoami)` to add yourself.
* You have downloaded [the iso image with the Windows drivers for paravirtualized KVM/qemu hardware](wget -nv -nc https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso).
You can do this from the command line: `wget -nv -nc https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso -O virtio-win.iso`.

You can use the following sample command to build a KVM/qemu box:

```
packer build --only=qemu --var virtio_win_iso=./virtio-win.iso ./windows_2019_docker.json
```

### Using .box Files With Vagrant

The generated box files include a Vagrantfile template that is suitable for use
Expand Down
54 changes: 54 additions & 0 deletions answer_files/10/Autounattend.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,60 @@
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<servicing/>
<settings pass="windowsPE">
<component name="Microsoft-Windows-PnpCustomizationsWinPE"
publicKeyToken="31bf3856ad364e35" language="neutral"
versionScope="nonSxS" processorArchitecture="amd64"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">

<!--
This makes the VirtIO drivers available to Windows, assuming that
the VirtIO driver disk at https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
(see https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html#virtio-win-direct-downloads)
is available as drive E:
-->
<DriverPaths>
<PathAndCredentials wcm:action="add" wcm:keyValue="2">
<Path>E:\viostor\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="3">
<Path>E:\NetKVM\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="4">
<Path>E:\Balloon\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="5">
<Path>E:\pvpanic\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="6">
<Path>E:\qemupciserial\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="7">
<Path>E:\qxldod\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="8">
<Path>E:\vioinput\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="9">
<Path>E:\viorng\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="10">
<Path>E:\vioscsi\w10\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="11">
<Path>E:\vioserial\w10\amd64</Path>
</PathAndCredentials>
</DriverPaths>
</component>

<component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<DiskConfiguration>
<Disk wcm:action="add">
Expand Down
54 changes: 54 additions & 0 deletions answer_files/2019/Autounattend.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-PnpCustomizationsWinPE"
publicKeyToken="31bf3856ad364e35" language="neutral"
versionScope="nonSxS" processorArchitecture="amd64"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">

<!--
This makes the VirtIO drivers available to Windows, assuming that
the VirtIO driver disk at https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
(see https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html#virtio-win-direct-downloads)
is available as drive E:
-->
<DriverPaths>
<PathAndCredentials wcm:action="add" wcm:keyValue="2">
<Path>E:\viostor\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="3">
<Path>E:\NetKVM\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="4">
<Path>E:\Balloon\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="5">
<Path>E:\pvpanic\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="6">
<Path>E:\qemupciserial\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="7">
<Path>E:\qxldod\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="8">
<Path>E:\vioinput\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="9">
<Path>E:\viorng\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="10">
<Path>E:\vioscsi\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="11">
<Path>E:\vioserial\2k19\amd64</Path>
</PathAndCredentials>
</DriverPaths>
</component>

<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
Expand Down
54 changes: 54 additions & 0 deletions answer_files/2019_core/Autounattend.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-PnpCustomizationsWinPE"
publicKeyToken="31bf3856ad364e35" language="neutral"
versionScope="nonSxS" processorArchitecture="amd64"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State">

<!--
This makes the VirtIO drivers available to Windows, assuming that
the VirtIO driver disk at https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
(see https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html#virtio-win-direct-downloads)
is available as drive E:
-->
<DriverPaths>
<PathAndCredentials wcm:action="add" wcm:keyValue="2">
<Path>E:\viostor\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="3">
<Path>E:\NetKVM\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="4">
<Path>E:\Balloon\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="5">
<Path>E:\pvpanic\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="6">
<Path>E:\qemupciserial\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="7">
<Path>E:\qxldod\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="8">
<Path>E:\vioinput\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="9">
<Path>E:\viorng\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="10">
<Path>E:\vioscsi\2k19\amd64</Path>
</PathAndCredentials>

<PathAndCredentials wcm:action="add" wcm:keyValue="11">
<Path>E:\vioserial\2k19\amd64</Path>
</PathAndCredentials>
</DriverPaths>
</component>

<component xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
Expand Down
7 changes: 7 additions & 0 deletions scripts/vm-guest-tools.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ msiexec /qb /i C:\Windows\Temp\7z1900-x64.msi
if "%PACKER_BUILDER_TYPE%" equ "vmware-iso" goto :vmware
if "%PACKER_BUILDER_TYPE%" equ "virtualbox-iso" goto :virtualbox
if "%PACKER_BUILDER_TYPE%" equ "parallels-iso" goto :parallels
if "%PACKER_BUILDER_TYPE%" equ "qemu" goto :qemu
goto :done

:vmware
Expand Down Expand Up @@ -55,6 +56,12 @@ if exist "C:\Users\vagrant\prl-tools-win.iso" (
cmd /C C:\Windows\Temp\parallels\PTAgent.exe /install_silent
rd /S /Q "C:\Windows\Temp\parallels"
)
goto :done

:qemu
if exist "E:\guest-agent\" (
msiexec /qb /x E:\guest-agent\qemu-ga-x86_64.msi
)

:done
msiexec /qb /x C:\Windows\Temp\7z1900-x64.msi
22 changes: 22 additions & 0 deletions vagrantfile-windows_10.template
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,26 @@ Vagrant.configure("2") do |config|
v.maxmemory = 2048
v.linked_clone = true
end

config.vm.provider :libvirt do |libvirt, override|
libvirt.memory = 2048
libvirt.cpus = 2

# Use WinRM for the default synced folder; or disable it if
# WinRM is not available. Linux hosts don't support SMB,
# and Windows guests don't support NFS/9P/rsync
# See https://github.com/Cimpress-MCP/vagrant-winrm-syncedfolders
if Vagrant.has_plugin?("vagrant-winrm-syncedfolders")
override.vm.synced_folder ".", "/vagrant", type: "winrm"
else
override.vm.synced_folder ".", "/vagrant", disabled: true
end

# Enable Hyper-V enlightments, see
# https://blog.wikichoon.com/2014/07/enabling-hyper-v-enlightenments-with-kvm.html
libvirt.hyperv_feature :name => 'stimer', :state => 'on'
libvirt.hyperv_feature :name => 'relaxed', :state => 'on'
libvirt.hyperv_feature :name => 'vapic', :state => 'on'
libvirt.hyperv_feature :name => 'synic', :state => 'on'
end
end
22 changes: 22 additions & 0 deletions vagrantfile-windows_2016.template
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,26 @@ Vagrant.configure("2") do |config|
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end

config.vm.provider :libvirt do |libvirt, override|
libvirt.memory = 2048
libvirt.cpus = 2

# Use WinRM for the default synced folder; or disable it if
# WinRM is not available. Linux hosts don't support SMB,
# and Windows guests don't support NFS/9P/rsync
# See https://github.com/Cimpress-MCP/vagrant-winrm-syncedfolders
if Vagrant.has_plugin?("vagrant-winrm-syncedfolders")
override.vm.synced_folder ".", "/vagrant", type: "winrm"
else
override.vm.synced_folder ".", "/vagrant", disabled: true
end

# Enable Hyper-V enlightments, see
# https://blog.wikichoon.com/2014/07/enabling-hyper-v-enlightenments-with-kvm.html
libvirt.hyperv_feature :name => 'stimer', :state => 'on'
libvirt.hyperv_feature :name => 'relaxed', :state => 'on'
libvirt.hyperv_feature :name => 'vapic', :state => 'on'
libvirt.hyperv_feature :name => 'synic', :state => 'on'
end
end
5 changes: 5 additions & 0 deletions vagrantfile-windows_2019_core.template
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ Vagrant.configure("2") do |config|
v.maxmemory = 2048
v.linked_clone = true
end

config.vm.provider :libvirt do |libvirt|
libvirt.memory = 2048
libvirt.cpus = 2
end
end
22 changes: 22 additions & 0 deletions vagrantfile-windows_7.template
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,26 @@ Vagrant.configure("2") do |config|
v.whitelist_verified = true
v.vmx["hgfs.linkRootShare"] = "FALSE"
end

config.vm.provider :libvirt do |libvirt, override|
libvirt.memory = 2048
libvirt.cpus = 2

# Use WinRM for the default synced folder; or disable it if
# WinRM is not available. Linux hosts don't support SMB,
# and Windows guests don't support NFS/9P/rsync
# See https://github.com/Cimpress-MCP/vagrant-winrm-syncedfolders
if Vagrant.has_plugin?("vagrant-winrm-syncedfolders")
override.vm.synced_folder ".", "/vagrant", type: "winrm"
else
override.vm.synced_folder ".", "/vagrant", disabled: true
end

# Enable Hyper-V enlightments, see
# https://blog.wikichoon.com/2014/07/enabling-hyper-v-enlightenments-with-kvm.html
libvirt.hyperv_feature :name => 'stimer', :state => 'on'
libvirt.hyperv_feature :name => 'relaxed', :state => 'on'
libvirt.hyperv_feature :name => 'vapic', :state => 'on'
libvirt.hyperv_feature :name => 'synic', :state => 'on'
end
end
37 changes: 36 additions & 1 deletion windows_10.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
{
"builders": [
{
"boot_wait": "6m",
"communicator": "winrm",
"cpus": "2",
"disk_size": "{{user `disk_size`}}",
"floppy_files": [
"{{user `autounattend`}}",
"./floppy/WindowsPowershell.lnk",
"./floppy/PinTo10.exe",
"./scripts/fixnetwork.ps1",
"./scripts/disable-screensaver.ps1",
"./scripts/disable-winrm.ps1",
"./scripts/enable-winrm.ps1",
"./scripts/microsoft-updates.bat",
"./scripts/win-updates.ps1"
],
"headless": true,
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `iso_url`}}",
"memory": "2048",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"type": "qemu",
"accelerator": "kvm",
"output_directory": "windows_10-qemu",
"qemuargs": [
[ "-drive", "file=windows_10-qemu/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1" ],
[ "-drive", "file={{ user `virtio_win_iso` }},media=cdrom,index=3" ]
],
"vm_name": "windows_10",
"winrm_password": "vagrant",
"winrm_timeout": "{{user `winrm_timeout`}}",
"winrm_username": "vagrant"
},
{
"boot_wait": "6m",
"communicator": "winrm",
Expand Down Expand Up @@ -161,7 +195,8 @@
"iso_url": "https://software-download.microsoft.com/download/pr/18362.30.190401-1528.19h1_release_svc_refresh_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso",
"restart_timeout": "5m",
"vhv_enable": "false",
"winrm_timeout": "6h"
"winrm_timeout": "6h",
"virtio_win_iso": "~/virtio-win.iso"
}
}

Loading

0 comments on commit bae4d5b

Please sign in to comment.