Ubuntu Core: Preparing a virtual machine with graphics support

Ubuntu Core: Preparing a virtual machine with graphics support

Overview

Duration: 0:30

When developing for Ubuntu Core it is often convenient to work in a virtual machine [VM]. Unfortunately, the archive build of qemu on Ubuntu doesn’t support graphics passthrough. This is a quick guide to setting up an Ubuntu Core VM using qemu-virgil.

Setup qemu with graphics support

Duration: 1:00

As the default build of qemu on Ubuntu doesn’t support graphics, we will use a handy snap containing a build that enables this:

$ sudo snap install qemu-virgil
$ sudo snap connect qemu-virgil:kvm

Download and prepare the Ubuntu Core image

Duration: 2:00

We also download an Ubuntu Core image. It’s currently easiest to get core18 working (as core20 requires UEFI and our qemu backend doesn’t support UEFI booting). On an x86 computer download the ubuntu-core-18-amd64.img.xz image from here:

https://cdimage.ubuntu.com/ubuntu-core/18/stable/current/

Now, uncompress the image and move it to a convenient location:

$ unxz ~/Downloads/ubuntu-core-18-amd64.img.xz
$ mv ~/Downloads/ubuntu-core-18-amd64.img ~/snap/qemu-virgil/common/

Initialize a VM with the Ubuntu Core image

Duration: 4:00

$ qemu-virgil -enable-kvm -m 512 -device virtio-vga,virgl=on\
 -display sdl,gl=on -netdev user,id=ethernet.0,hostfwd=tcp::10022-:22\
 -device rtl8139,netdev=ethernet.0 -soundhw ac97\
 ~/snap/qemu-virgil/common/ubuntu-core-18-amd64.img

This will create a QEMU window on your desktop and you need to follow through the prompts to initialise the VM with your launchpad account. (If you don’t have a launchpad account, you will need it to work with Ubuntu Core: get one and set up a public SSH key.)

Connect to the VP using ssh from a terminal window (ignore the address shown in the QEMU window and use the port set in the above command):

$ ssh -P 10022 <your‑user>@localhost

Congratulations!

You should now have terminal access to your VM and a window containing a virtual display. You can install and run a variety of graphical snaps. You can stop the VM and restart it at any time using the same commands as in the last step.

Further reading