Hyper-V Nested Virtualization
Before covering containers, let’s look at a long-requested feature that is finally
available in Windows Server 2016 and Windows 10 Hyper-V: nested virtualization.
This capability enables you to run a hypervisor inside a virtual machine.
Hyper-V requires certain capabilities from the processor to enable virtualization,
primarily hardware-assisted virtualization (Intel VT and AMD-V). While the Hyper-V
hypervisor exposes most capabilities of the underlying physical processor to virtual
machines, it has not until Windows Server 2016 been able to expose the hardware-
assisted virtualization capability that makes Hyper-V virtualization possible. Prior to
Windows Server 2016, this meant that within a Hyper-V VM, it was not possible to
install the Hyper-V role and run a VM within the VM (although the role could be
installed, a VM would not be able to start). Historically, there has not been a serious
need to run VMs in VMs (outside of test environments on a developer’s laptop). This
changed, however, with Windows Server 2016 containers, as you will see later in this
chapter, and there is now a very real requirement to be able to create Hyper-V VMs
inside other Hyper-V VMs.
Enabling a VM to support nested virtualization requires the following:
The VM must be turned off.
Any saved state must be deleted.
Dynamic Memory must be disabled, and the VM must have at least 4GB of
memory. It might need significantly more, depending on the memory
requirements of the VMs that will run nested inside. Nested VMs running inside
the VM can use Dynamic Memory.
MAC address spoofing must be enabled on the VM’s NIC if the VMs running inside
the VM need network connectivity.
Set-VMNetworkAdapter -VMName <VM Name> ‐MacAddressSpoofing On
Virtualization extensions must be exposed to the virtual CPU inside the VM. To do
this, the following PowerShell is executed:
Set-VMProcessor -VMName <VM Name> ‐ExposeVirtualizationExtensions $true
Microsoft has a script available at
https://raw.githubusercontent.com/Microsoft/Virtualization-
Documentation/master/hyperv-tools/Nested/Enable-NestedVm.ps1 that performs all
of the configurations previously mentioned. It can be downloaded to a local file by
using the following PowerShell and then executed on a VM:
Invoke-WebRequest https://raw.githubusercontent.com/Microsoft/Virtualization-
Documentation/master/hyperv-tools/Nested/Enable-NestedVm.ps1 `
-OutFile ~/Enable-NestedVm.ps1