Links

A Quick'n'Dirty Set-up of an Aarch64 Ubuntu 14.04 VM with QEMU

Lately, I came up with the idea to do some development on Aarch64. However, I couldn't get my hands on real hardware easily so I started to look for alternatives (i.e., emulators). The ARMv8 Foundation Model seemed to be the trivial solution but I've heard that QEMU is somewhat faster so I gave it a try. My goal was to set up the VM as quick as possible: reuse whatever is already "out there" and rebuild only what's utterly necessary. In the end it turned out that it's quite easy to get such a VM working ... once you know what you need. To figure that out, well, that required some googling and emailing around. Below are my notes (I cleaned them up a bit and tried to make them somewhat coherent), so that others won't need to compile all these information again. I hope that someone will find it useful.

Build your own QEMU/Aarch64

Okay, my goal was not to rebuild, and I failed at the very first step. For Aarch64, it's best to build QEMU from source. Fortunately, building QEMU is really simple:

sudo apt-get build-dep qemu # install the dependencies
git clone git://git.qemu.org/qemu.git # get the source (at the time of writing, HEAD was at revision 69f87f713069f1f70f86cb65883f7d43e3aa21de)
cd qemu
./configure --target-list=aarch64-softmmu --enable-virtfs # configure for aarch64 (virtfs only needed if you'd like to mount up a dir of the host in the guest OS)
make # build qemu (make install is not necessary)

That's it, QEMU is ready to run. The questions are "what" (images) and "how" (command line options)?

Create a clean Aarch64 Ubuntu Core 14.04.1 image

First, I wanted a well-prepared and well-maintained root filesystem. And the good news is that Ubuntu has 14.04 out for Aarch64 as well. So, it only takes a download from the official website, and either some manual work or the help of a useful script to turn the downloaded tarball into a QEMU-compatible image. The script I ended up using is attached to this blogpost.

(Note: The script creates a 32 GB file! See at the end of the post how to change that.)

Get your hands on suitable kernel & initrd (for those who are lazy to build their own)

Beside the root filesystem, I also needed the images of an already built kernel and an initrd. Again, Ubuntu has those, even if a bit hidden away: they can be taken from inside a QCOW2-format Ubuntu 14.04 cloud image. This needs a bit more steps than creating the rootfs image before but it's still not rocket science (and needs to be done only once).

The first login prompt will already be lost somewhere amidst the startup log messages by the time they stop rolling. Just press enter to get a new one.

The initial password for root is root. (Don't forget to change it after the first login!)

The current command line sets up user mode networking for the VM. It has its limitations (e.g., no ping) but it should be fine for simple web access for the start.

Do apt-get update && apt-get upgrade at least at the first startup.

Don't forget to properly shut down your VM if you're done with it (shutdown -h now). Just killing the qemu process is as rude as plugging out the power cord from your PC! Once you see "reboot: System halted" on the console, you can switch to the QEMU monitor by pressing CTRL+A C and then type quit.

Customization

So, all the above is OK, so-so, but not exactly what you want. Then, you may want to:

change the size of the disk image holding the root fs: change the count=32768 argument of dd in the arm64-prepare-image-qemu script (specify size in MB).

change the memory allocated for the VM: change the -m 4096 command line parameter of qemu-system-aarch64 (specify size in MB).

replace the default user networking (slirp) with a more powerful networking setup: experiment with the -netdev command line options.

build your own kernel & initrd: good luck with that :)

Acknowledgements / Sources of information

I received a lot of help from Alex Bennée, for which I'm really thankful, and collected info/inspiration from the sources below:

Now, that you're asking, I wonder too. :) I must have been tempted by the fact that the core image was 14.04.1 already, so a little bit newer than the cloud image, and the very same version I'm using on my desktop box. (Not that upgrading the cloud image should be a big issue...)

So, the cloud image could also work. Are you up to give it a try and share the results here?