How to enable Nested Virtualization in VirtualBox (New Feature)

Did you ever want to have labs where you could play with different hypervisors within a single virtual machine on your laptop? I know this sounds more like an INCEPTION remake than a decent requirement but you can’t blame us for being greedy knowing all that tools like VirtualBox can help us do nowadays.

To give more context to this issue. I have been playing with KVM lately when I realized that I was actually installing a Hypervisor inside a guest machine within another Hypervisor. Pretty weird indeed when you think of it, but I only stopped because a tool was complaining that no Hypervisor was recognized.

So, how to make a Hypervisor (KVM) aware of the Host hardware when it’s only installed under another Hypervisor layer (VirtualBox)? This is called nested Virtualization

Well, after digging a little online, it turns out that the latest versions of VirtualBox do provide this feature and it is very simple to enable even after your VM has been provisioned.

 

1. Environment
Host: Intel-based Dell laptop with windows 10
Hypervisor: VirtualBox
Guest OS: Oracle Linux 7
Hypervisor installed within the guest: KVM
Issue description from KVM.org:
For KVM to run from a VM it needs access to a set of CPU instructions (intel VT or AMD) to enable running fully isolated virtual machines at native hardware speeds (HVM ). Learn more.

 

2. Symptoms

In my case the Host CPU socket is intel hence I would be looking whether Intel VT (Virtualization Technology) is listed as virtualization capability on the guest machine.

– So I ran the below which should display 2 if intel Virtualization capability is enabled. I got 0

– Alternatively, you can also check if nested virtualization is enabled in kvm (kvm_intel). Still nothing

3. Solution

All you have to do is to make sure your VirtualBox is of version 6.1.4 and from there you can “activate” nested virtualization. Use either one of the below options.

  • Adding <NestedHWVirt enabled=”true”/> in CPU section of your .vbox file inside your VM folder (usually hidden in windows)
  • Running the following vboxmanage command

Here is the result of to same lsmod command after applying the change.

Another quick way to check if the change is effective is by opening the processor setting tab in VirtualBox.

  • Enable Nested Virtualization on Vagrant
    If you are using vagrant to provision your VM you can also do it by adding below customize line in your vagrant file.

Share:

No Comments

No comments yet.

RSS feed for comments on this post.

Leave a comment