Define nested virtualization

Completed

Nested virtualization is a Hyper-V feature that you can use to install and run Hyper-V inside a guest VM. It's a virtualized environment running inside a virtualized environment. Nested virtualization enables a guest VM to be a Hyper-V host, which can then host other guest VMs. Nested virtualization can be extremely useful for implementing virtual test and development environments that would otherwise require physical hardware to run. The Contoso Hyper-V administrator is investigating test environments and implementing a private cloud. Both could use nested virtualization.

The following diagram depicts Hyper-V in a non-nested scenario. The Hyper-V hypervisor takes full control of the hardware virtualization capabilities and doesn't expose them to the guest OS. Also, in this non-nested scenario, the VM does not directly interact with the host hardware.

A non-nested virtualization architecture diagram in which the Windows operating system and Hyper-V Guest operating system have to access the hardware on the host via a Hyper-V hypervisor layer.

In contrast, the following diagram depicts Hyper-V with nested virtualization enabled. With nested virtualization enabled, a guest VM can install its own hypervisor and run its own guest VM. VM access to the host hardware must go through the second hypervisor and then through the first hypervisor.

A nested virtualization architecture diagram in which there is an additional hypervisor present, which sits above the initial hypervisor, creating two hypervisor layers. Any VMs created above this additional hypervisor access host hardware through the two hypervisors in succession.

Prerequisites for nested virtualization

For Windows Server hosts, the prerequisites depend on the physical processor:

Physical processor Hyper-V host operating system Minimum VM configuration version
Intel with VT-x and Extended Page Tables (EPT) Windows Server 2016 or later 8.0
AMD EPYC or Ryzen, or later Windows Server 2022 or later 9.3

These host requirements aren't a requirement that the host and guest run the same Windows Server version. Choose a supported Windows guest operating system that supports installing Hyper-V for the VM that acts as the nested host. Allocate enough memory and other resources to that VM for its own operating system and the nested VMs it runs.

Supported Windows client hosts are also covered in Run Hyper-V in a virtual machine with nested virtualization. Check the processor-specific requirements for the host platform you use.

Enable nested virtualization

To enable nested virtualization by using Windows PowerShell, run the following command from the physical Hyper-V host while the VM is in the off state. Replace NestedHostVM with the name of the VM that acts as the nested Hyper-V host:

Set-VMProcessor -VMName 'NestedHostVM' -ExposeVirtualizationExtensions $true

After you have enabled nested virtualization, you can install Hyper-V on the guest VM in the same way that you would for a Hyper-V host.

Networking with nested virtualization

There are two options for networking with nested VMs:

  • MAC address spoofing
  • NAT

MAC address spoofing

The first option uses MAC address spoofing, which enables network packets to be routed through two vSwitches. MAC address spoofing must be enabled on the physical Hyper-V host.

To enable MAC address spoofing by using Windows PowerShell, run the following command from the physical Hyper-V host. Replace NestedHostVM with the name of the VM that acts as the nested Hyper-V host. The command gets that VM's network adapters and enables MAC address spoofing on them:

Get-VMNetworkAdapter -VMName 'NestedHostVM' | Set-VMNetworkAdapter -MacAddressSpoofing On

NAT

The second option uses NAT. This approach is best suited for cases where MAC address spoofing isn't possible, such as in a public cloud environment.

To use NAT, create a virtual NAT switch in the host VM. Assign an IP address to the network adapter and ensure that each nested VM has an IP address and gateway assigned to it.

Note

There's more configuration required with the NAT option than the MAC address spoofing option.

Memory considerations

When Hyper-V runs inside a VM, that VM's memory allocation doesn't fluctuate even if Dynamic Memory is enabled. Turn off the VM before adjusting its memory allocation. Runtime memory resizing also fails for a VM without Dynamic Memory while Hyper-V runs inside it.

Simply exposing virtualization extensions doesn't disable Dynamic Memory. The restriction applies while Hyper-V runs inside the VM. See Nested virtualization memory considerations.