How to run Hyper-V/Docker on Windows 10 in qemu/libvirt/kvm

Hyper-V on Windows requires nested virtualization, since it runs linux in a virtual machine. You need Hyper-V to run docker. Windows 10 does not allow virtualization when it is run in kvm. If you open the task manager, it does not even show “Virtualization: Not available”.

The trick is to make Windows 10 think it is running on real hardware, with virtualization enabled. So you need hypervisor off but vmx on; on the qemu command line this would be –cpu -hypervisor,+vmx.

First, download a time-limited Windows 10 VM from Microsoft. The VirtualBox and vmware downloads contain a .vmdk file, which can be converted to qcow2 using qemu-img. In this example the file downloaded was WinDev2009Eval.VMware.zip, this might be different for you.

1
2
3
4
5
$ unzip WinDev2009Eval.VMware.zip WinDev2009Eval-disk1.vmdk
Archive: WinDev2009Eval.VMware.zip
inflating: WinDev2009Eval-disk1.vmdk
$ qemu-img convert -f vmdk WinDev2009Eval-disk1.vmdk -O qcow2 WinDev2009Eval-disk1.qcow2
$

Second, in Virtual Manager, create a new virtual machine. You have to select Windows 10 and the WinDev2009Eval-disk1.qcow2 as a disk image (not as an installer iso).

To make Hyper-V work, you have to edit the xml which describes the cpu in Virtual Manager. First you have to enable xml editting in Edit -> Preferences -> Enabled XML editting. Then your machine details, find the CPUs, go to xml and find the cpu element. This should read:

1
2
3
4
5
<cpu mode="custom" match="exact" check="partial">
<model fallback="allow">IvyBridge</model>
<feature policy="disable" name="hypervisor"/>
<feature policy="require" name="vmx"/>
</cpu>

Press apply to make it work and start your machine. Now you can install Docker in Windows 10.

docker in Windows 10 in KVM

The hypervisor hack was inspired by a similar hack for vmware.