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.
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.
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.
INFO: /dev/kvm exists
KVM acceleration can be used
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*.
David Miller is a seasoned tech aficionado with a profound expertise in NGINX and Ubuntu. With a career spanning over a decade, David has honed his skills in optimizing web servers and enhancing server performance to perfection. His deep-rooted passion for open-source technologies has led him to become a go-to resource in the field. Whether it’s crafting intricate NGINX configurations or troubleshooting complex Ubuntu server issues, David’s problem-solving prowess shines through.