Can you run a machine emulator (Bochs) inside a virtual machine?

82

27

Is it possible to, say, run VirtualBox on Windows 7 with a Linux guest, and inside that Linux machine run Bochs?

The reason is that I'm interested in starting OS development, and I've found that all the tutorials and stuff are much easier to follow on *nix machines. I tried using Cygwin, but I think it's adding another layer of complexity and not necessarily making things easier.

Javier

Posted 2011-07-19T17:33:56.390

Reputation: 3 053

2VirtualMachine-ception :D You have the danger of losing track of how many levels deep in virtual machines you are. That moment when you realise you just corrupted your physical hard disk instead of one of the nested virtual ones you were meant to be testing on :P – developerbmw – 2015-05-19T10:38:22.487

1Dual booting is Linux and Windows is relatively easy to do, and the end result runs much more quickly. The only real downside being you have to reboot to switch OSes. – lyallcooper – 2011-07-19T20:44:36.293

@AUAnonymous: I know that, but I want to keep running Windows. – Javier – 2011-07-19T20:58:27.330

It's just always an option if you don't manage to get the VMs working or if they don't work too well. – lyallcooper – 2011-07-19T21:11:53.080

While you could do a great deal of work with this sort of setup, I strongly urge you to investigate Simics if you are going to be writing a serious kernel. The insight and debugging alone are priceless, however it is rather expensive. – Tim Post – 2011-07-20T03:11:00.147

12

I'm going to argue that this question is poorly titled. Bochs isn't virtualization software in the same sense as VirtualBox and VMWare. It is an emulator. It offers no CPU virtualization. The distinction here is not merely pedantic. You can expect an emulator like bochs to work inside a VM with fairly high confidence. Running a true virtualization software "nested" in a VM is a much trickier problem. For example, this feature was only implemented in VMWare as of Fusion 4.

– superbatfish – 2013-05-22T22:03:47.333

Answers

63

Long story short: yes.

Each virtual machine is technically "independent" of one another, and with VirtualBox, you could easily do this, since it is supported on both Windows and Linux host operating systems (emulated or not). You could simply use Windows as your "base-host" OS, run Linux in a VM, and then use that operating system as the new base-host for Bochs.

Do note that your only limitation here is your hardware. Depending on the requirements of your development, you may require more memory, or an upgrade to a 64-bit "base-host" operating system. That being said, if you choose your Linux distros wisely, any modern system should be capable of arbitrary nesting like this.

You will see improved performance if you enable x86 virtualization support on your computer (if your motherboard and CPU support it), and AFAIK, you can "pass through" this feature to multiple nested virtual machines. If we have n virtual machines nested in eachother, this is supported so long as the 1st to the n-1th nested guest OS has support for x86 virtualization (the base host must also support it). Do note that there are still some security issues to be aware of if you do this, so take the appropriate precautions.

Breakthrough

Posted 2011-07-19T17:33:56.390

Reputation: 32 927

Isn't this answer contradicted by TobyJ's answer and the unresolved VirtualBox feature request which his answer links to?

– ChrisW – 2019-09-09T08:58:13.773

2It seems it actually works. After all, if I needed speed I wouldn't be using Bochs in the first place. While not the most upvoted, I feel your answer is the more complete and to the point, so I'll accept it. – Javier – 2011-07-20T04:16:21.287

Is it just me, or doesn't this answer seem to be about running multiple virtual machines, not nested ones? – Thomas Padron-McCarthy – 2011-07-20T06:41:35.227

@Thomas Padron-McCarthy, I was talking about nested ones. I modified the answer to be more explicit with this regard. – Breakthrough – 2011-07-20T10:21:33.080

7Bochs is not the best test-case for this general question, since it is an emulator, not a VM. (See my comment on the OP.) – superbatfish – 2013-05-22T22:06:56.093

40

I sometimes run a whole VMware vSphere virtual infrastructure within VMware Workstation, along with virtual Cisco routers and switches and EMC Celerra Virtualized Storage Appliance, for self-learning and testing purposes.

I call it 'Inception Computing', and it can get pretty confusing. It is however somewhat cheaper than using the real gear.

paradroid

Posted 2011-07-19T17:33:56.390

Reputation: 20 970

1@paradroid you should have named "CompCeption" or "VirtuaCeption". – Mohd Abdul Mujib – 2014-11-05T04:15:31.843

This is a question about Virtualbox not VMWare – Chris S – 2016-05-19T08:45:04.190

@ChrisS No, Virtualbox was used as an example if you read more carefully. Also, look at the title. – paradroid – 2016-05-19T13:46:27.340

1

This should prove the viability of this. http://vinf.net/2010/02/25/8-node-esxi-cluster-running-60-virtual-machines-all-running-from-a-single-500gbp-physical-server/

– Mike Soule – 2011-07-19T22:55:25.043

1

@Mike: Your link details running ESXi within ESX, but I have used some of the links, like TechHead, which is one of the main sites which got me into virtualisation in the first place. There is a lot of information on running a vSphere infrastructure within VMware Workstation as well: http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=vmware+vsphere+workstation

– paradroid – 2011-07-19T23:17:14.910

2You know that the term "inception" doesn't refer to the [thing within a thing] concept, right? – ekillaby – 2013-08-16T22:51:28.107

7@countfloortiles: It's a reference to the film, of course. – paradroid – 2013-08-17T14:03:18.623

32

To anyone who reads this question, sees the accepted answer, and thinks this will apply to VirtualBox as well, please see comment from @superbatfish on the original question. He makes a good point about the difference between virtualization and emulation.

Specifically, "hardware assisted VM" will not be available in the "top-level" guest OS (that is, at the time of this writing, VirtualBox doesn't provide hardware VM in guest OSes). With VirtualBox, this means you can only create 32-bit "nested guest" OSes, even if the top-level guest is 64 bit and your "real" host has hardware VM.

May not be a showstopper for you, but it's worth noting. I needed this in order to run Vagrant on an Ubuntu guest inside Windows, for Chef cookbook testing.

Tobias J

Posted 2011-07-19T17:33:56.390

Reputation: 990

So were you able to run Vagrant on Ubuntu guest inside Windows host? – wisbucky – 2015-03-21T01:55:44.637

2@wisbucky yes, I could run it in 32-bit mode, but not 64-bit. Since all my production systems are 64-bit, it wasn't a perfect test but still worked well enough. – Tobias J – 2015-03-21T17:02:29.437

3

Unless I'm mistaken you could now run 64-bit Vagrant boxes within the Ubuntu VM by using the Docker provider for Vagrant, since containers don't rely on hardware virtualisation: https://www.vagrantup.com/docs/docker/. The Vagrant box you're using will have to support that, though.

– Brendan – 2016-01-22T13:16:53.757

@Brendan, unless you have to run specific 64bit programs, then using the docker container compared to running 32bit virtual box, is performance wise the same or is it? – serup – 2016-11-22T23:52:41.167

11

Linux-KVM has some support for nested virtual machines. I've asked on the KVM IRC channel and have gotten the following information (but don't take my word, try it yourself):

  • AMD CPUs should work well, guests with Xen and Hyper-V are known to work,
  • Intel CPUs need the latest KVM Git source code, and only guests with KVM work

I haven't tried this myself yet. A search for "KVM nested" should give you enough info to try it yourself.

EDIT: KVM will run on a Linux host only. I haven't gotten any reliable info on Windows virtualization software concerning proper nested VM support. By 'proper' I mean that the hypervisor exposes virtualization extensions to the guest. You can always run a nested VM using a pure software hypervisor (e.g. dynamic translation), but that will be noticably slower.

EDIT: Bochs, which you mentioned, is a software-only hypervisor. This means that it will always be slow, and it's irrelevent if the hypervisor on the host exposes virtualization extensions to the guest (like KVM does). Most other virtualization softare (KVM, VirtualBox, VMWare) however can make use of those extensions and will perform much better if they are available.

Ambroz Bizjak

Posted 2011-07-19T17:33:56.390

Reputation: 4 265

Regarding Windows virtualization... it seems to be possible, but (as of June 2016) only works with HyperV-on-HyperV, with "Windows Insider" OS builds, and on Intel hardware. From https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/user_guide/nesting

– Mark – 2016-09-13T20:20:58.310

To your second edit: So if I'm just going to be running Bochs (and I don't care too much if it's slow), do I need to worry about the KVM thing? – Javier – 2011-07-19T20:08:03.237

If you're running Bochs inside the virtual machine, it will be as slow as if you ran it on hardware (assuming your hardware has virtualization extensions, i.e. AMD-v or VT-x and they are enabled in BIOS; otherwise it will be even slower, as will everything in the VM). – Ambroz Bizjak – 2011-07-19T22:15:37.387

3

Its possible, but not very feasible, especially for development. You should probably look at running Linux as your native OS, or getting a second box to host the VMs on.

peelman

Posted 2011-07-19T17:33:56.390

Reputation: 4 580

I understand that it's likely to be complicated, but what exactly do you mean by "not very feasible"? – Javier – 2011-07-19T17:58:07.543

1I would bet that @peelman means: "It is too slow for practical purposes." I haven't tried it myself. – CarlF – 2011-07-19T21:06:35.283

@carlf precisely. – peelman – 2011-07-20T04:11:38.353

1

Detailed description of this process is on this page: https://wiki.openstack.org/wiki/XenServer/VirtualBox

In VirtualBox machine network cards you have to set allow all in Promiscuous Mode and several other options and you can have os inside vm e.g. Xenserver inside vm e.g. VirtualBox.

42n4

Posted 2011-07-19T17:33:56.390

Reputation: 111

1

Yes, you can run a virtual machine in a virtual machine. What I did was get a Windows 7 Ultimate x64 computer, run the same OS on the virtual machine, then run a 32 bit version (it couldn't handle 64 bit on the 3rd layer) on the 3rd layer. It was pretty laggy but i managed to get to the new york times on internet explorer with it. This may be difficult if you don't have a powerful computer, but you're running Linux and Bochs, which are lightweight Operating Systems, so it should be possible.

FluorescentGreen5

Posted 2011-07-19T17:33:56.390

Reputation: 121

-2

Yes, it is possible, given that your computer is powerful enough to handle it.

On my machine (i7 4770S, 16GB RAM) I managed to get a VM-ception-ness level of 4.5 (the last one crashes half of the time).

I used VMware Player 12, because VirtualBox didn't like emulating VM-x, and it was reaaaally slower. Right now, I'm trying to make W2K work on XP, but VMware can't install, VirtualBox produces BSODs so I'm trying using QEMU.

See this screenshot (one of the most beautiful screenshots I've ever seen):

enter image description here

zdimension

Posted 2011-07-19T17:33:56.390

Reputation: 2 523

What new information does this answer provide? – Ramhound – 2016-11-03T00:50:01.767