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?
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.
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.
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.
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.
It depends on the virtualisation technique. If you use solutions that are not "real" virtualisation like UML then you can run those inside, say, VMWare. Or themselves for that matter.
UML based installs can run inside VMWare VMs and other UML based installs (even nested). The performance metrics are not going to be pretty though!
Yes, it is possible but really slow.
It's particulary useful if you're renting a server with limited allocated public IP (which depends for example on your MAC adress to not poison the network of your server provider); and that you want your VM IP to be bridged to communicate directly with internet. So when you can't have more than, for example, 3 public IP adress, but that you need 10 VM, it's a pretty good idea to have VMs in a global VM : you will use only one of your given public IP and then have many sub bridged VMs.
But you could actually use a mix of bridge and routed network config, it's just more tough concerning configuration.
As far as I know it is not possible, but VMware ESX can run in VMware Workstation for example. IMHO it is only good for testing.
Like many people have all ready said: of course it's possible. It depends on how well the VM hardware is emulated and what virtualization software you're using. VMWare Workstation, at least, doesn't want you to virtualize it.
As for if it's practical, maybe we should pose the question back to you: why would you need to do that kind of thing? What's wrong with just running two VMs side by side? And to what degree do you ask if it's practical? That is, if you're worried about it being practical to set up and configure, probably not. If you're more worried about it's practical usage, again, I can't think of anything I'd need to do this for unless I'm looking for bugs in the virtualization software or something.
Yes. See here:
You can, but I don't recommend it.
Performance is usually hit pretty heavily in this whole process on the "guest of the guest" machine. If you really must do this without the specialized hardware and software, good luck to you. However, it's generally not good practice especially with the common methods used to achieve virtualization.
I do know that if you try to run VMWare within VMWare systems, it will complain and not let you do it. I am unsure about VirtualBox. I do know of a few people who, for whatever reason, deploy Docker containers within Docker containers (or so they say). Moral of the story is: while it may be possible, it's probably not smart to do it unless you really know what you're doing.
I don't personally know any actual use-case for this beyond networking.