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?
-
3A practical reason is if you're renting a server. Whether the server is physical or virtual should not matter - it's my server. And if i want to install VirtualPC or Virtual Server on my server: that's my business. – Ian Boyd Jul 28 '09 at 13:59
-
2That's not really a practical reason, since the "practicality" of installing a VM inside of a VM is going to ultimately depend on whether it's "practical" to implement this capability in the chosen HW+SW platform. Just because somebody "wants" to do it doesn't make it practical. – Joe Internet Feb 17 '10 at 00:01
-
1For anyone wondering why one might want to do this, here's my reason, though I admit that it is not a "real world" reason and that I can't really think of one of those. I'm studying for the RHCSA exam but I don't have access to a system with hardware virtualization. Therefore, I was hoping to accomplish this on a RHEL virtual machine running as an Amazon AWS instance. Since the AWS machine is (almost assuredly) a virtual machine itself, running KVM on it would require nested VMs. – Stephen C Jul 14 '15 at 16:28
12 Answers
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.
- 11,784
- 6
- 41
- 51
-
2That document has changed significantly since this was written, as has the state of the art. This answer, as it was written, really isn't applicable today. Consider updating it. – Michael Hampton Nov 11 '15 at 15:30
-
1@MichaelHampton Your comments are very skeptical and sound optimistic; could YOU provide an updated answer or link to one? – ILMostro_7 Dec 06 '15 at 00:22
-
Here's a link to a [fedora-wiki](https://fedoraproject.org/wiki/How_to_enable_nested_virtualization_in_KVM) page describing how to enable **nested virt** in **KVM**. – ILMostro_7 Dec 06 '15 at 00:27
-
1Just for confirmation - As far as Hyper-v offering from MS goes I believe nested VM is not supported till date. – RBT Mar 21 '17 at 09:21
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.
- 131
- 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.
- 7,357
- 1
- 19
- 19
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.
- 299
- 1
- 8
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.
- 2,423
- 18
- 17
Yes. There are even ways to run VMware ESX/vSphere in a virtual machine. I don't know why you would ever want to in practice, but it has been done.
- 9,064
- 1
- 34
- 41
-
I've seen people wanting to test ESX in a VM, but the install requires additional work past just the normal install method. It's not something that works out of the box. – baumgart Jul 28 '09 at 13:58
Yes, you CAN but like so many things doesn't mean you should. I've seen a virtualized ESX server running a virtual machine that has another virtual ESX server within it. Granted it was a test just to see if it could be done (and it can) I really wouldn't recommend it.
- 1,307
- 8
- 10
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!
- 22,534
- 42
- 66
Yes. See here:
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.
- 429
- 1
- 7
- 16
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.
- 31
- 3
-
2The "specialized" hardware you need is virtually any CPU manufactured in the last seven or eight years. – Michael Hampton Nov 11 '15 at 15:32