MauriceRandomNumber
MauriceRandomNumber

Reputation: 412

How to start a virtual machine guest armv8 on amd64 host with qemu

How to run a virtual machine with qemu on an Ubuntu 18.04 x86_64 host system, when I want the guest system to be ARMv8 (Raspberry Pi 3, more specifically interested in the Cortex A53 processor)?

Background:

I want to compile a project for a real machine with ARMv8 on the mentioned host system. Currently, this is done with cross compile directly in the host system. For many different reasons, I want to set up a virtual machine which compiles binaries (virtually) native for the ARMv8. The binaries need to be runable on the real ARMv8 machine later.

Apart from Qemu and the right qemu-system-aarch64 to be installed on the host system, there is an image of the operating system needed. Ideally the same as the one running on the real ARMv8 device. The Ubuntu IoT Core 18.04 64-bit is available at https://ubuntu.com/download/raspberry-pi and I saved it to a local folder with the name ubuntu18045arm64rpi3.img.xz.

After extracting it, I got the extracted image 'ubuntu18045arm64rpi3.img'

To start a virtual machine with the given image and the wanted architecture, I type this:

sudo qemu-system-aarch64 -m 1024 -cpu cortex-a53 -M virt -drive if=none,file=ubuntu18045arm64rpi3.img,id=hd0

which gives me a window like that: qemu monitor

Now my main questions are:

  1. I expected a virtual machine to boot up, where I can install the OS from the given image. What did I do wrong or how to achieve this goal?

  2. Later on, I want to install a compiler (if not already there) on the guest ARMv8 machine and compile my project there. Afterwards I plan to transfer the compiled binaries to the real ARMv8 machine and expect them to run without difficulties. Is this possible with the current approach?

Upvotes: 5

Views: 9906

Answers (1)

Peter Maydell
Peter Maydell

Reputation: 11523

You can't just pass a disk image to the aarch64 QEMU and have it boot. You need to either pass a kernel to boot, or a BIOS (probably UEFI) image (which can then read a kernel off a disk image).

This blog post has an example of running Debian on QEMU; getting Ubuntu booting is probably similar. https://translatedcode.wordpress.com/2017/07/24/installing-debian-on-qemus-64-bit-arm-virt-board/

Your link is to a raspberry pi specific disk image -- since you are not asking QEMU to model a raspberry pi board I would recommend against using that. You want whatever Ubuntu provides as their most normal/generic aarch64 image. If you're going the "boot via UEFI" route then you want a disk image intended for SBSA/UEFI systems.

On your second question about portability of compiled binaries, this is the same as for any two Linux systems, really. If the two systems have the same OS/distro version (so they have the same library versions etc), and the same sets of runtime libraries installed, and you didn't tell the compiler to compile to use CPU features that the destination CPU doesn't have, then it should work.

Compiling inside this emulated setup is going to be significantly slower than either your current cross-compile setup or compiling the binaries directly on the real AArch64 hardware, incidentally.

Upvotes: 1

Related Questions