virt-builder is a tool for rapidly creating customized Linux images. Recently I’ve added support for Windows although for rather obvious licensing reasons we cannot distribute the Windows templates which would be needed to provide Windows support for everyone. However you can build your own Windows templates as described here and then:
$ virt-builder -l | grep windows windows-10.0-server x86_64 Windows Server 2016 (x86_64) windows-6.2-server x86_64 Windows Server 2012 (x86_64) windows-6.3-server x86_64 Windows Server 2012 R2 (x86_64) $ virt-builder windows-6.3-server [ 0.6] Downloading: http://xx/builder/windows-6.3-server.xz [ 5.1] Planning how to build this image [ 5.1] Uncompressing [ 60.1] Opening the new disk [ 77.6] Setting a random seed virt-builder: warning: random seed could not be set for this type of guest virt-builder: warning: passwords could not be set for this type of guest [ 77.6] Finishing off Output file: windows-6.3-server.img Output size: 10.0G Output format: raw Total usable space: 9.7G Free space: 3.5G (36%)
To build a Windows template repository you will need the latest libguestfs sources checked out from https://github.com/libguestfs/libguestfs and you will also need a suitable Windows Volume License, KMS or MSDN developer subscription. Also the final Windows templates are at least ten times larger than Linux templates, so virt-builder operations take correspondingly longer and use lots more disk space.
First download install ISOs for the Windows guests you want to use.
After cloning the latest libguestfs sources, go into the builder/templates
subdirectory. Edit the top of the make-template.ml
script to set the path which contains the Windows ISOs. You will also possibly need to edit the names of the ISOs later in the script.
Build a template, eg:
$ ../../run ./make-template.ml windows 2k12 x86_64
You’ll need to read the script to understand what the arguments do. The script will ask you for the product key, where you should enter the volume license key or your MSDN key.
Each time you run the script successfully you’ll end up with two files called something like:
windows-6.2-server.xz windows-6.2-server.index-fragment
The version numbers are Windows internal version numbers.
After you’ve created templates for all the Windows guest types you need, copy them to any (private) web server, and concatenate all the index fragments into the final index file:
$ cat *.index-fragment > index
Finally create a virt-builder repo file pointing to this index file:
# cat /etc/virt-builder/repos.d/windows.conf [windows] uri=http://xx/builder/index
You can now create Windows guests in virt-builder. However note they are not sysprepped. We can’t do this because it requires some Windows tooling. So while these guests are good for small tests and similar, they’re not suitable for creating actual Windows long-lived VMs. To do that you will need to add a sysprep.exe step somewhere in the template creation process.