published: 17th of August 2020
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.
This post focuses on Ubuntu 1804 but should work on most Linux distros on the Suported Distros list.
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.
To enable nested virtualization the VM must first be powered off.
Open a Powershell window as administrator to execute the following commands.
With all that out of the way. Lets get to it.
Get a list of the Hyper-V VMs. The VM I will be altering is called vagrant
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.
Set-VMProcessor -VMName vagrant -ExposeVirtualizationExtensions $true
Confirm nested virtualization is enabled on the VM.
(Get-VMProcessor -VMName vagrant).ExposeVirtualizationExtensions
# output
True
Power on the VM and install the cpu-checker utility.
sudo apt install -y cpu-checker
Confirm that KVM acceleration can be used with the kvm-ok command.
kvm-ok
# output
INFO: /dev/kvm exists
KVM acceleration can be used
And .... that's it!!!!
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.
https://timothygruber.com/hyper-v-2/run-a-nested-vm-on-kvm-qemu-vm-in-hyper-v/
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/nested-virtualization
https://devblogs.microsoft.com/scripting/get-a-list-of-virtual-machines-by-using-powershell/