Nested virtualization is a feature that allows you to run Hyper-V inside of a Hyper-V virtual machine. In other words, with nested virtualization, a Hyper-V host itself can be virtualized. Some use cases for nested virtualization would be to run a Hyper-V Container in a virtualized container host, set-up a Hyper-V lab in a virtualized environment or to test multi-machine scenarios without the need for individual hardware. This document will detail software and hardware prerequisites, configuration steps, and limitations.
Nested virtualization allows you to run in Hyper-V virtual machine hyper-V features. In other words, using nested virtualization, the hyper-v host itself can be virtualized. Some use cases for nested virtualization are to run hyper-v containers on virtual container hosts, set up hyper-v labs in virtualized environments, or test multi-machine scenarios without the need for separate hardware. This document describes in detail the prerequisites, configuration steps, and limitations of software and hardware.
A Hyper-V host running Windows Server 2016 or Windows 10 Anniversary Update.
A Hyper-V VM running Windows Server 2016 or Windows 10 Anniversary Update.
A Hyper-V VM with configuration version 8.0 or greater.
An Intel processor with VT-x and EPT technology.
A hyper-v host running Windows Server 2016 or Windows 10th Anniversary Update.
A hyper-v VM runs Windows Server the 10th anniversary of 2016 or Windows.
Configure the hyper-v VM version 8.0 or later.
An Intel processor with vt-x and EPT technologies.
Configure Nested Virtualization (configuration nested virtualization)
Create a virtual machine. See the prerequisites above for the required OS and VM versions. Create a virtual machine. See the preceding prerequisites for the required OS and VM versions.
While the virtual machine is in the OFF state, run the following command on the physical Hyper-V host. This enables nested virtualization for the virtual machine. When the virtual machine is in the OFF state, run the following command on the physical hyper-v host. This provides nested virtualization for virtual machines.
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true
Start the virtual machine. The VM is powered on.
Install Hyper-V within the virtual machine, just like you would for a physical server. For more information on installing Hyper-V see, Install Hyper-V. Install hyper-v in a virtual machine, just like a physical server. For more information about installing hyper-v, install hyper-v.
Disable Nested Virtualization Disable nested Virtualization
You can disable nested virtualization for a stopped virtual machine using the following PowerShell command: you can run the following PowerShell command to disable nested virtual machines. Run the following PowerShell command:
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $false
Dynamic Memory and Runtime Memory Resize dynamic memory and runtime memory size
When Hyper-V is running inside a virtual machine, the virtual machine must be turned off to adjust its memory. This means that even if dynamic memory is enabled, the amount of memory will not fluctuate. For virtual machines without dynamic memory enabled, any attempt to adjust the amount of memory while it's on will fail.
Note that simply enabling nested virtualization will have no effect on dynamic memory or runtime memory resize. The incompatibility only occurs while Hyper-V is running in the VM.
When hyper-v is running in a virtual machine, you must shut down the virtual machine to adjust its memory. This means that even if dynamic memory is enabled, the memory capacity does not fluctuate. For virtual machines with dynamic memory enabled, any attempt to adjust the amount of memory during their runtime will fail.
Note that only enabling nested virtualization does not affect the size of dynamic memory or runtime memory. When hyper-v is running in a VM, it cannot be compatible.
Networking Options network Options
There are two options for networking with nested virtual machines: MAC address spoofing and NAT mode. There are two options: MAC address spoofing and NAT mode.
In order for network packets to be routed through two virtual switches, MAC address spoofing must be enabled on the first level of virtual switch. This is completed with the following PowerShell command. To route network packets through two vswitches, MAC address spoofing must be enabled at the first level of the vSwitch. This is done by using the following PowerShell command.
Get-VMNetworkAdapter -VMName <VMName> | Set-VMNetworkAdapter -MacAddressSpoofing On
Network Address Translation network address translation
The second option relies on network address translation (NAT). This approach is best suited for cases where MAC address spoofing is not possible, like in a public cloud environment.
the second option depends on network address translation (NAT). This method is most suitable for scenarios where MAC address cheating is impossible, such as in public cloud environments.
First, the virtual NAT switch must be created in the host virtual machine (intermediate VM). Note that the IP address is only an example and will change in different environments:
New-VMSwitch -Name VmNAT -SwitchType Internal New-NetNat –Name LocalNAT –InternalIPInterfaceAddressPrefix “192.168.100.0/24”
Next, assign an IP address to the net adapter: next, assign an IP address to the NIC:
Get-NetAdapter "vEthernet (VmNat)" | New-NetIPAddress -IPAddress 192.168.100.1 -AddressFamily IPv4 -PrefixLength 24
Each nested virtual machine must have an IP address and gateway assigned to it. Note that the gateway IP must point to the NAT adapter from the previous step. You may also want to assign a DNS server: each nested virtual machine must have an IP address and a gateway assigned to it. Note that the gateway IP address must point to the NAT adapter from the previous step. You may also need to assign a DNS server:
Get-NetAdapter "Ethernet" | New-NetIPAddress -IPAddress 192.168.100.2 -DefaultGateway 192.168.100.1 -AddressFamily IPv4 -PrefixLength 24 Netsh interface ip add dnsserver “Ethernet” address=<my DNS server>
3rd Party Virtualization AppsThird-party virtualization applications
Virtualization applications other than Hyper-V are not supported in Hyper-V virtual machines, and are likely to fail. This includes any software that requires hardware virtualization extensions.
In hyper-v virtual machines, virtualization applications other than hyper-v are not supported and may fail. This includes any software that requires hardware virtualization extension.
This article is forwarded from Chenghang 51CTO blog, original link: http://blog.51cto.com/hangtc/1965782,如需转载请自行联系原作者