What is it?

We talk about nested virtualization when for some reason we need to work with a virtual machine (L2) inside another virtual machine (L1).

Nested Virtualization

The possibilities for nested virtualization depend mainly on the hardware and operating system of the host, but also on the combination of virtualization solutions used (at the first and second levels).

The next few sections provide a brief overview of the steps required to enable nested virtualization under various virtualization solutions.

Hyper-V

Let’s look at enabling nested virtualization for a virtual machine named MyVM.

In a PowerShell session on the host (physical machine), several commands need to be executed.

To pass the virtualization instructions to the virtual machine:

Set-VMProcessor -VMName MyVM -ExposeVirtualizationExtensions $true

To turn off dynamic memory:

Set-VMMemory -VMName MyVM -DynamicMemoryEnabled $false

To enable MAC address change:

Set-VMNetworkAdapter -VMName MyVM -MACAddressSpoofing On

The last two steps can also be performed through the Hyper-V graphical interface. In the virtual machine settings, in the Memory section, disable Enable Dynamic Memory and in the Network Adapter > Advanced Features section, enable Enable MAC address spoofing.

VMware Workstation Pro

To enable nested virtualization, simply go to the processor settings of the selected virtual machine and enable the Virtualize Intel VT-x/EPT or AMD-V/RVI.

VMware ESXi

Nested virtualization becomes available after performing the following two actions:

  • In the virtual machine’s processor settings, the Expose hardware assisted virtualization to the guest OS option must be enabled

  • In addition, the Promiscuous mode of the virtual switch to which the virtual machine is connected must be changed to Accept

KVM

With KVM, nested virtualization is enabled at the host level, i.e. it becomes available to all virtual machines.

For Intel processors, you need to add options kvm_intel nested=1 to the file /etc/modprobe.d/kvm.conf.

For AMD processors, you need to add options kvm_amd nested=1 to the file /etc/modprobe.d/kvm.conf.

VirtualBox

Enabling nested virtualization in VirtualBox can be done both from the user interface and from the command line.

In the processor settings (System > Processor) of the virtual machine, the Nested VT-x/AMD-V option must be enabled. In some older versions, the option is called Enable Nested VT-x/AMD-V.

An alternative option is to run the following command (for a virtual machine named MyVM):

VBoxManage modifyvm MyVM --nested-hw-virt on

Since version 6.1.x, nested virtualization is supported on both AMD processors and Intel processors (5th generation or later). It should be noted that not all hypervisors are supported as nested.