简体   繁体   English

如何在 x86 上通过 Linux KVM API 实例化基于 ARM 的 VM?

[英]How to instantiate an ARM-based VM through Linux KVM API on x86?

Say I have a x86 machine.假设我有一台 x86 机器。 It's easy to create a x86 VM through Linux KVM API.通过 Linux KVM API 创建 x86 VM 很容易。

See: vm_init() in kvm-host :参见: vm_init()kvm-host 中

if ((v->kvm_fd = open("/dev/kvm", O_RDWR)) < 0)
        return throw_err("Failed to open /dev/kvm");

    if ((v->vm_fd = ioctl(v->kvm_fd, KVM_CREATE_VM, 0)) < 0)
        return throw_err("Failed to create vm");

    if (ioctl(v->vm_fd, KVM_SET_TSS_ADDR, 0xffffd000) < 0)
        return throw_err("Failed to set TSS addr");
...
if ((v->vcpu_fd = ioctl(v->vm_fd, KVM_CREATE_VCPU, 0)) < 0)
        return throw_err("Failed to create vcpu");

In this project, it's easy to create a x86 VM on a x86 machine.在这个项目中,很容易在 x86 机器上创建一个 x86 VM。

My question is, however, what if i want that VM to be a ARM architecture?但是,我的问题是,如果我希望该 VM 成为 ARM 架构怎么办?

I believe that is applicable because we have qemu-system-arm , and what I try to achieve is exactly what it does.我相信这是适用的,因为我们有qemu-system-arm ,而我试图实现的正是它的作用。

What you are asking for is not possible.你所要求的是不可能的。 KVM cannot run virtual machines for different architectures than the one the kernel was built for and runs on. KVM 不能运行与内核构建和运行的架构不同的虚拟机。 If you want to run an ARM VM using KVM you will have to do that on an ARM processor.如果要使用 KVM 运行 ARM VM,则必须在 ARM 处理器上执行此操作。 KVM merely takes advantage of the hardware capabilities of the underlying CPU for virtualization, which means that instructions are effectively ran by the host CPU, so you cannot run ARM code on an x86 machine. KVM 只是利用底层 CPU 的硬件能力进行虚拟化,也就是说指令由主机 CPU 有效运行,因此您无法在 x86 机器上运行 ARM 代码。

What qemu-system-arm does on an x86 machine is emulate all the instructions in software and in userspace, without any help from the host kernel/CPU. qemu-system-arm在 x86 机器上所做的是模拟软件和用户空间中的所有指令,而无需主机内核/CPU 的任何帮助。 You will be able to use KVM with qemu-system-arm only if you are on an ARM machine which supports KVM.只有在支持 KVM 的 ARM 机器上,您才能将 KVM 与qemu-system-arm一起使用。 For more info see KVM Processor Support .有关更多信息,请参阅KVM 处理器支持

You can build a vm with qemu-arm-system registered as the appropriate interpreter with only arm executable files inside its file system.您可以使用注册为适当解释器的 qemu-arm-system 构建 vm,其文件系统中只有 arm 可执行文件。 It is kinda overkill, since you can do the same with just chroot, and owing to the interposition of qemu have about the same level of system control.这有点矫枉过正,因为你可以只用 chroot 做同样的事情,而且由于 qemu 的插入,系统控制水平大致相同。

This github link has a recipe for it;这个github 链接有一个食谱; but you can find a bunch by searching around.但是你可以通过搜索找到一堆。 Once you set this up, you could readily wrap it inside a vm if you wished.一旦你设置好了,如果你愿意,你可以很容易地将它包装在一个虚拟机中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM