Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Say I have a x86 machine. It's easy to create a x86 VM through Linux KVM API.

See: vm_init() in 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.

My question is, however, what if i want that VM to be a ARM architecture?

I believe that is applicable because we have qemu-system-arm, and what I try to achieve is exactly what it does.

like image 348
Ztex Avatar asked Dec 31 '25 16:12

Ztex


2 Answers

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. If you want to run an ARM VM using KVM you will have to do that on an ARM processor. 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.

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. You will be able to use KVM with qemu-system-arm only if you are on an ARM machine which supports KVM. For more info see KVM Processor Support.

like image 95
Marco Bonelli Avatar answered Jan 04 '26 16:01

Marco Bonelli


I have the feeling that your question was misunderstood or was not answered correctly.

If I understand your question correctly, you want to run an emulated arm64 VM on a x86 host. The answer is yes you can, with QEMU and with the support of qemu-system-arm.

I could run an emulated ubuntu server for arm64 on a x86 host.

Guest:

root@ubuntu:~# uname -a
Linux ubuntu 5.15.0-117-generic #127-Ubuntu SMP Mon Jul 8 13:10:05 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux

Host:

root@my-laptop:~# uname -p
x86_64

Refer to this quick how-to: https://ubuntu.com/server/docs/boot-arm64-virtual-machines-on-qemu

like image 30
Ahmad Alzoubi Avatar answered Jan 04 '26 17:01

Ahmad Alzoubi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!