[英]Any way to run a Linux inside a virtual machine, inside my application?
I want to be able to distribute a Linux running inside my application. 我希望能够分发在我的应用程序中运行的Linux。 The reason is that I need to add software functionality which is most easily added inside a Linux container and distributed with the application. 原因是我需要添加最容易在Linux容器中添加并随应用程序一起分发的软件功能。
Is there any way to run a VM inside a C/C++ application on Windows, OSX, Linux? 是否可以在Windows,OSX,Linux上的C / C ++应用程序中运行VM?
Two frameworks come to mind: 我想到了两个框架:
These may both requires a Linux host. 这些都可能需要Linux主机。 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. QEMU可以运行VM,并且可以在Windows,Linux和OSX上进行编译。 http://wiki.qemu.org/Main_Page QEMU can be compiled as it is written in C++. http://wiki.qemu.org/Main_Page QEMU可以使用C ++进行编译。
So in theory, QEMU could be embedded in a C++ program and used to run a Linux VM. 因此,从理论上讲,QEMU可以嵌入C ++程序中并用于运行Linux VM。
An example QEMU running Puppy Linux http://www.erikveen.dds.nl/qemupuppy/ 运行Puppy Linux的示例QEMU http://www.erikveen.dds.nl/qemupuppy/
VirtualBox has an API for creating/running VMs. VirtualBox具有用于创建/运行VM的API。 The program Vagrant uses this to give developers a simple cross-platform way to develop. Vagrant程序使用此程序为开发人员提供了一种简单的跨平台开发方式。 You can run vagrant up
from Windows, Linux or Windows, and it does the same thing. 您可以从Windows,Linux或Windows上运行vagrant up
,并且执行相同的操作。
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". 您也可以通过脚本编写将端口添加到VM的脚本,以便您的C ++程序可以显示“ VirtualBox,请引导我此映像”,然后只需连接到TCP端口即可与“ Linux程序”对话。 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. 但是,如果您的目标是将Linux程序出售给非Linux桌面用户,那么您和您的理智选择将子弹移植到Windows / Mac可能是最好的选择。 (Or go Cloud and sell it as a service.) (或转到Cloud并将其作为服务出售。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.