Is it possible to setup a virtual machine inside another virtual machine

I've been playing with virtual machines lately, and I wondered if I could run a virtual machine inside a virtual machine.
Is this possible?
Is it practical?


Solution 1:

Nesting VMs is something that has been done for forever on IBM Mainframe hardware. That hardware does lots of stuff to make the process very very efficient. You can have VMs nested to an arbitrary depth and it works very well.

PC hardware very recently has kinda made this barely possible. A document on VMware's web site discusses it, but the gist is that you can have VMs nested 2 deep, but only on very modern hardware that supports true hardware virtualization (VT-x or AMD-V), and the second VM depth must be running the older style BT/binary translation style virtualization. There are also severe restrictions on the virtual monitors you're able to run on the inner guest.

Needless to say, it's not supported and I'd expect it to be really flakey if you do anything even remotely weird (like Hyper-V under ESX). And performance will not be good, regardless of if it is stable.

Solution 2:

Yes you can. For example, on Linux, you may run Xen with multiple VMs running OpenVZ, VirtualServer or some other kind of VM system. It is most certainly possible and also very practical depending on your purpose.

One reason that I could think of for doing this is to run multiple servers on a single physical machine. Whether you run it as a single level of VM hierarchy or multiple ones is dependent on your resource isolation plan.

Solution 3:

If you need some specific, say legacy, system to be virtualized you can always do it in software, the nesting is not an issue then. Try qemu, I did it 2 level deep with it, but you can go deeper, the performance will probably make it useless, though. BTW, PC architecture was nomen omen made by IBM, but for totally different uses compared to what it is used for today.

Solution 4:

I don't believe most virtualization packages will allow you to run a VM in a VM. I know that VMware will check when it's installed to see if its being installed in a VM, and I hope other products do the same. I don't think the necessary CPU instructions would be presented through from the hypervisor running on the hardware up through the VM to reach the second VM. If it did work, you'd also be adding overhead without getting anything in return.

As for whether it's practical - I don't see why. If you need another VM, you can just run it next to the one you already have running. I can't imagine a case where you must have a VM running inside another VM. The additional overhead without a proportional gain of some resource would make this impractical.