Skip to Content

How to run Nested Virtualization on a Mac

Nested virtualization lets you run a virtual machine inside a virtual machine, and though it may sound silly, it’s very useful for testing apps. This guide will show you how to do it on a Mac.

Introduction

I’m a big fan of open-source software, but I couldn’t get the two main open-source virtualization products (QEMU and VirtualBox) to run nested virtualization.

This is because they don’t pass the hardware assisted virtualization feature of the CPU to the virtual machine.

When trying to run KVM inside a Linux VM running on my Mac with VirtualBox or QEMU, I was getting the following error.

$ kvm-ok
INFO: Your CPU does not support KVM extensions
INFO: For more detailed results, you should run this as root
HINT:   sudo /usr/sbin/kvm-ok

VMware Fusion to the rescue

It turns out, nested virtualization on a Mac is possible with VMware Fusion*.

It can be enabled by ticking the Enable hypervisor applications in this virtual machine option. This is found in the advanced options of the Processors & Memory screen for the virtual machine you want to run nested virtualization on.

Now when running the kvm-ok command I get the following output.

$ kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

Conclusion

Open-source software is good, but sometimes it lacks certain features, and the only way to get nested virtualization working on a Mac at the time of writing, is to use a commercial product like VMware Fusion*.

Jean

Wednesday 6th of September 2023

Thanks, I have been wondering about this. Was it an Apple Silicon? With M1 or M2 chip?

Ben

Friday 8th of September 2023

@Jean, Indeed, macOS does support nested virtualization, but enabling it typically requires using the command line interface (CLI) as it's not available through the VirtualBox GUI. Here's the command and an explanation of what each part does:

Navigate to the VirtualBox Executable Directory:

bash

cd /Applications/VirtualBox.app/Contents/MacOS/

This command uses the cd command to change your current directory to the location where the VirtualBox executable is stored. On macOS, the VirtualBox application is usually located in the /Applications directory, and inside it, you'll find the VirtualBox.app. The Contents/MacOS/ directory contains the VirtualBox executable (VBoxManage) that we need to use.

List Virtual Machines:

bash

VBoxManage list vms

This command uses VBoxManage to list all virtual machines currently configured in VirtualBox. It provides a list of the available VMs along with their details. This step helps you identify the virtual machine you want to enable nested virtualization for.

Enable Nested Virtualization:

bash code

VBoxManage modifyvm "GNS3 VM" --nested-hw-virt on

Here, VBoxManage is again used to modify a virtual machine, specified within quotes. In this example, it's "GNS3 VM," but you should replace it with the name of the VM you want to enable nested virtualization for. The option --nested-hw-virt on is used to turn on nested virtualization support for this VM.

Nested virtualization allows you to run virtual machines within a virtual machine. This can be useful for scenarios like running GNS3 VMs inside VirtualBox.

After running these commands, your specified virtual machine ("GNS3 VM" in this case) should have nested virtualization enabled, allowing it to run virtualization technologies like KVM inside it.

Remember to run these commands with the necessary permissions, which might require using sudo (superuser) depending on your system setup.