Question

I want to be able to distribute a Linux running inside my application. The reason is that I need to add software functionality which is most easily added inside a Linux container and distributed with the application.

Is there any way to run a VM inside a C/C++ application on Windows, OSX, Linux?

Was it helpful?

Solution

VirtualBox has an API for creating/running VMs. The program Vagrant uses this to give developers a simple cross-platform way to develop. You can run vagrant up from Windows, Linux or Windows, and it does the same thing.

You can also script adding ports to your VM, so your C++ program could say "VirtualBox, boot me this image", then just connect to a TCP port to talk to the "Linux program". But debugging problems will be hard.

But if your goal is to sell a Linux program to non-Linux desktop people, it's probably best for you and your sanity to bite the bullet and port it to Windows/Mac. (Or go Cloud and sell it as a service.)

OTHER TIPS

Two frameworks come to mind:

  • User mode Linux runs the Linux kernel as an application. This give you ultimate control over launching and managing the virtual machine from within a Linux application.
  • libvirt provides a toolkit for programmatically managing all manner of virtual machines.

These may both requires a Linux host. For other host operating systems, it may be necessary to manage the virtual machine manually -- or using ad hoc scripting.

QEMU can run a VM and it can be compiled on Windows and Linux and OSX. http://wiki.qemu.org/Main_Page QEMU can be compiled as it is written in C++.

So in theory, QEMU could be embedded in a C++ program and used to run a Linux VM.

An example QEMU running Puppy Linux http://www.erikveen.dds.nl/qemupuppy/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top