What Is Nested Virtualization? Running VMs Inside VMs, Requirements, and Limits
Nested virtualization lets you install a hypervisor inside a virtual machine (VM) and run another VM from there. It is useful for testing hypervisors and operating-system combinations without adding physical servers, but the outer platform must expose CPU virtualization features to the inner VM. Performance, networking, and provider support also need to be checked.
Nested virtualization lets you install a hypervisor inside a virtual machine (VM) and run another VM from there. It is useful for testing hypervisors and operating-system combinations without adding physical servers, but the outer platform must expose CPU virtualization features to the inner VM. Performance, networking, and provider support also need to be checked.
What do L0, L1, and L2 mean?
The labels describe each layer's role. L0 is the hypervisor on the physical host that manages the real CPU and memory. L1 is a VM on L0 that acts as a hypervisor host. L2 is a VM created by the L1 hypervisor. For example, if a physical server runs Hyper-V, a Windows VM on it also runs Hyper-V, and that inner Hyper-V creates a Linux test VM, those systems are L0, L1, and L2 respectively.
In an ordinary VM, L0 manages CPU virtualization extensions such as Intel VT-x or AMD-V, so the L1 operating system usually cannot use them directly. When nesting is enabled, L0 exposes the features to L1 in a supported way, and the L1 hypervisor manages L2. Memory translation also passes through both hypervisor layers. The inner VM therefore does not get direct access to the host's physical memory or devices; the CPU and hypervisors cooperate to translate addresses and enforce access checks.
When is it useful, and how does it differ from an ordinary VM or a container?
Common uses include testing a hypervisor, validating combinations of operating systems, training labs, and developer tools that depend on hardware virtualization. AWS documents running KVM or Hyper-V inside an EC2 VM and cites tools such as Docker Desktop, WSL 2, Android emulators, and QEMU. Google Cloud gives disaster recovery for existing VM workloads and software validation across OS images as examples. These are examples of configurations supported by each service; they do not mean that nesting works on every cloud VM.
An ordinary VM runs an operating system or application on virtual hardware created by L0. With nested virtualization, L1 must provide virtual hardware and hypervisor functions again, adding another layer. Containers generally share the host kernel for isolation, so they have different requirements from nested virtualization, which supplies another kernel and hypervisor inside a VM. If you only need containers, first check whether the runtime works in an ordinary VM; consider nesting when a hypervisor inside the guest is actually required.
What changes when CPU extensions are exposed, and what does it cost?
A basic VM configuration often does not let L1 see hardware virtualization instructions. L1's Hyper-V or KVM can start L2 only when the platform supports nesting and the administrator exposes the CPU extensions to that VM. The physical host still controls the actual limits of CPU, memory, storage, and networking. Assigning more virtual CPUs or memory to L1 does not create more physical capacity.
Running VMs through multiple layers and handling virtual disks and networks adds work. CPU throughput, disk I/O, or network latency can suffer, so nesting may be a poor fit for latency-sensitive or performance-critical services. Google warns that, in its supported configurations, CPU-bound or I/O-bound workloads might see performance reductions of 10% or more. This is not a universal guarantee or prediction: results depend on the hypervisors, processor, storage, network, and workload, so measure with representative traffic.
What is needed to enable nesting in Hyper-V?
The following prerequisites come from Microsoft's current Hyper-V documentation. With an Intel processor using VT-x and EPT, the host must be Windows Server 2016 or later or Windows 10 or later, and the VM configuration version must be 8.0 or later. With AMD EPYC/Ryzen or later, the host must be Windows Server 2022 or later or Windows 11 or later, and the VM configuration version must be 9.3 or later. For an Azure VM, Microsoft also says to use the Standard security type. Other hypervisors and clouds have their own compatibility requirements.
Confirm that hardware virtualization is enabled on the host and that the guest OS and VM configuration version meet the applicable requirements.
Fully shut down the L1 VM. You cannot change this setting while the VM is running.
Open an elevated PowerShell session on the physical Hyper-V host and run the following command, replacing `<VMName>` with the VM's actual name.
Set-VMProcessor -VMName "<VMName>" -ExposeVirtualizationExtensions $trueStart the L1 VM, then install the Hyper-V role inside it or configure another supported hypervisor. Allocate enough resources for the L2 VM's CPU, memory, and disk needs as well.
If the nested VM needs network access, enable MAC address spoofing on the L1 virtual switch or configure NAT. NAT can suit environments such as public clouds where spoofing is unavailable, but routing, ports, and firewall rules still need to be configured.
How can you verify it and diagnose problems?
A successful configuration command does not prove that an L2 VM can run. Check that the virtualization extension is visible inside L1, that the hypervisor installs, and that a test L2 VM starts. On a Linux L1 VM, this command checks for Intel's vmx or AMD's svm flag:
grep -E -m1 '(^| )(vmx|svm)( |$)' /proc/cpuinfoIf the flag is absent, check whether L0 supports nesting, whether the VM is powered off when configured, whether extension exposure is enabled, and whether CPU or management policies allow it. If the flag appears but L2 will not start, check the L1 hypervisor version and permissions, available vCPU and memory, guest OS support, and logs. If only L2 has network problems, inspect virtual switches, NAT, MAC spoofing, routing, and firewall rules instead of repeating the CPU configuration.
Even with Dynamic Memory enabled, an L1 VM's memory cannot be adjusted while nested Hyper-V is running. Shut down L1 before changing its memory. When nesting is no longer needed, shut down the VM and disable exposure with Set-VMProcessor -VMName "<VMName>" -ExposeVirtualizationExtensions $false. If organizational security policy or cloud-provider settings must change, follow the approved operating procedure and check the provider's support documentation first.
How should you choose a cloud or production setup?
Support depends on the hypervisor, processor family, VM generation or size, operating system, and security policy. AWS EC2 specifies supported instance types and KVM/Hyper-V conditions. Google Cloud's documentation supports only Linux KVM as the L1 hypervisor and restricts certain VM families and processors. Do not assume that a cloud VM supports nesting: check the current support matrix for the selected region, instance type, and guest OS. Provider lists can change, so verify them before deployment.
Nesting is useful in development, training, and validation labs that can tolerate configuration changes and restarts. For latency-sensitive production services, unsupported hypervisor combinations, or work requiring strong availability guarantees, consider a physical host or a dedicated VM explicitly supported by the provider. First decide whether the extra layer is necessary; if it is, validate a small L1/L2 setup, then test representative load and recovery procedures.
References
[Microsoft: Hyper-V nested virtualization overview](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/nested-virtualization)
[Microsoft: Run Hyper-V in a VM with nested virtualization](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/enable-nested-virtualization)
[Microsoft: Hyper-V architecture](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/architecture)
[AWS: Use nested virtualization in Amazon EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/amazon-ec2-nested-virtualization.html)
[Google Cloud: Nested virtualization overview](https://docs.cloud.google.com/compute/docs/instances/nested-virtualization/overview)
[Google Cloud: Troubleshoot nested VMs](https://docs.cloud.google.com/compute/docs/troubleshooting/troubleshooting-nested-vms)