4

I have seen some tutorials for Raspberry pi 2, but they are either a bit old, or do not work on the 3 model. I would like basically to run QEMU with KVM, for a x86 guest, in order for it to perform at a satisfactory level, right now it is very slow. The big picture is to run as a nova compute node for openstack. But for now the simple virtualization is a step.

  • 2
    the Pi is not powerful enough for virtualisation – Darth Vader Apr 17 '16 at 11:25
5

This is an old question, but:

You won't be able to use KVM to run an x86 guest on the Raspberry Pi (any version), as the Raspberry Pi uses an ARM CPU core. Now, this doesn't mean that you can't run an x86 guest at all, but performance will be quite slow. (The link above is likely about using KVM to run an ARM guest, not an x86 guest).

Before the KVM extensions, QEMU was essentially an "emulator" - not virtualization. KVM allows a certain level of "passthrough" of operations from the guest CPU to the host CPU - that's what defines it as "virtualization" rather than emulation. (One main reason that VMWare became king in this arena is that they were able to perform that type of "virtualization" before the x86 CPUs had added the virtualization extensions to the architecture. Those same virtualization extensions are what is required to run KVM, or in fact any modern virtualization hypervisor, as opposed to emulation).

So, it's theoretically possible to run x86 "Virtual machines" on a Raspberry Pi, but performance will be very slow, as every x86 instruction has to be translated / emulated by the ARM CPU on the Pi. Per this project dedicated to running Wine with a QEMU x86 execution layer, you can expect performance on par with a "300mhz Pentium" (Presumably they mean a Pentium II, or such). Depending on what tasks you want to be doing, you may not find this performance adequate. If you're looking to run a Windows application, the Wine/QEMU option is almost certainly a better option than fully emulating a Windows environment with QEMU.

1

Not that I'm aware of. But, you can do it yourself. (link)

But, the interesting thing here is there's no difference between the Pi2 and the Pi3 kernel (yet). So, go use a KVM-enabled Pi2 kernel. Good luck with performance though.

1

Given the similarity in kernels between the 2 and 3, this tutorial might provide some guidance.

https://blog.flexvdi.com/2015/03/17/enabling-kvm-virtualization-on-the-raspberry-pi-2/

The context is CentOS running on top of KVM, but the author has done a detailed job of describing the steps to getting the Pi ready for virtualization.

0

As the other answer says, it's not possible to run KVM for x86 images running on arm.

But, if you want to try KVM on the RPi 3, the easiest way that I found is using ArchLinux: https://archlinuxarm.org/platforms/armv8/broadcom/raspberry-pi-3.

Install qemu with pacman: pacman -S qemu and if wanted pacman -S qemu-arch-extras. The version is quite new:

# qemu-system-aarch64 --version
QEMU emulator version 2.11.0
Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers

With that OS installed, you have kvm enabled.

# dmesg | grep kvm
[    0.632551] kvm [1]: 8-bit VMID
[    0.636143] kvm [1]: IDMAP page: 1c7d000
[    0.639532] kvm [1]: HYP VA range: 800000000000:ffffffffffff
[    0.644281] kvm [1]: Invalid trigger for IRQ4, assuming level low
[    0.647576] kvm [1]: virtual timer IRQ4
[    0.650829] kvm [1]: Hyp mode initialized successfully

And to run for example CirrOS, I used the following guide: https://www.cnx-software.com/2016/05/10/how-to-run-ubuntu-16-04-aarch64-64-bit-arm-cloud-images-on-your-intelamd-linux-computer/. In short:

curl http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-aarch64-disk.img --output cirros-0.4.0-aarch64-disk.img
curl https://releases.linaro.org/components/kernel/uefi-linaro/15.12/release/qemu64/QEMU_EFI.fd --output QEMU_EFI.fd

Then I create the cloud.img in my x86_64 (Ubuntu) machine with cloud-utils (skipped, check reference).

And execute in the RPI with the following:

qemu-system-aarch64 -smp 2 -m 300 -M virt -bios QEMU_EFI.fd -nographic \
-device virtio-blk-device,drive=image \
-drive if=none,id=image,file=cirros-0.4.0-aarch64-disk.img \
-device virtio-blk-device,drive=cloud \
-drive if=none,id=cloud,file=cloud.img \
-netdev user,id=user0 -device virtio-net-device,netdev=user0 -redir tcp:2222::22 \
-cpu host --enable-kvm

It should fly!

-1

If a linux guest is enough for you -- go on with the LXD/LXC. Snap install is the solution here. You can even run a VirtualBox on top if it ;) Some more details on networking setup of Pi host: http://www.makikiweb.com/Pi/lxc_on_the_pi.html

  • 1
    Nothing will remain of this answer once the link is gone. Could you please add the relevant content in this post? – Dmitry Grigoryev May 21 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.