Intro

I really like Vagrant for developement and testing. The Vagrant team maintains a Hyper-V provider for use with Windows but it has some limitations . A very big one being limited networking support. For example: You cannot create additional networks so are stuck using the "Default Network" :/

I discovered that in newer versions of Hyper-V you can run nested virtualization with Linux VMs. This presents some interesting opportunities to run KVM/QEMU on a Linux VM nested on Hyper-V. This in theory would allow you to run Vagrant or even EVE-NG under Hyper-V albeit in a nested Linux VM. This post outlines how to enable nested virtualization on an Ubuntu 1804 VM on Hyper-V.

Note

This post focuses on Ubuntu 1804 but should work on most Linux distros on the Suported Distros list.

Software Used in this Post

  • Windows 10 Pro - 19041.388
  • Ubuntu - 1804

Pre-Flight

This post assumes that you already have Hyper-V enabled and an Ubuntu 1804 VM installed. Follow along with this post to install an Ubuntu 1804 VM. This is a pretty decent post on enabling Hyper-V.

The VM/Host must also adhere to the following paramaters.

  • A VM configuration version 8.0 or greater
  • The VM must be of the type Generation 2
  • The VM cannot use Dynamic Memory
  • Disable Secure Boot on the VM
  • The host must have an Intel processor with VT-x and EPT technology
Note

To enable nested virtualization the VM must first be powered off.

Note

Open a Powershell window as administrator to execute the following commands.

With all that out of the way. Lets get to it.

Windows Hyper-V Host

Get a list of the Hyper-V VMs. The VM I will be altering is called vagrant

cmd
Get-VM

# output

Name    State CPUUsage(%) MemoryAssigned(M) Uptime   Status             Version
----    ----- ----------- ----------------- ------   ------             -------
vagrant Off   0           0                 00:00:00 Operating normally 9.0

Enable nested virtualization on the required VM.

cmd
Set-VMProcessor -VMName vagrant -ExposeVirtualizationExtensions $true

Confirm nested virtualization is enabled on the VM.

cmd
(Get-VMProcessor -VMName vagrant).ExposeVirtualizationExtensions

# output

True

Ubuntu 1804 VM

Power on the VM and install the cpu-checker utility.

cmd
sudo apt install -y cpu-checker

Confirm that KVM acceleration can be used with the kvm-ok command.

cmd
kvm-ok

# output

INFO: /dev/kvm exists
KVM acceleration can be used

And .... that's it!!!!

Outro

In this post we enabled nested virtualization on a Linux VM hosted on Microsoft Hyper-V. My intention is to use this VM to run Vagrant labs with the libvirt provider. Whatever your intention is, may the swartz be with you.