34

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?

3
  • 3
    A 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, 2009 at 13:59
  • 2
    That'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. Feb 17, 2010 at 0:01
  • 1
    For 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, 2015 at 16:28

12 Answers 12

30

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.

4
  • 2
    That 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. Nov 11, 2015 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 6, 2015 at 0:22
  • Here's a link to a fedora-wiki page describing how to enable nested virt in KVM.
    – ILMostro_7
    Dec 6, 2015 at 0:27
  • 1
    Just for confirmation - As far as Hyper-v offering from MS goes I believe nested VM is not supported till date.
    – RBT
    Mar 21, 2017 at 9:21
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.

2

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.

1

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.

1

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.

1
  • 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, 2009 at 13:58
1

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

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!

1

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.

0

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.

0

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.

0

Yes. See here:

How to run VMWare ESX or ESXi in a virtual machine?

0

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.

1
  • 2
    The "specialized" hardware you need is virtually any CPU manufactured in the last seven or eight years. Nov 11, 2015 at 15:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .