How to update QEMU on Ubuntu

Ubuntu 18.04 ships with QEMU version 2.11. If you want to use a newer version, 4.1 in my case, you can build it on your own. In case you are using Libvirt qith QEMU, keep in mind that you might need to update Libvirt as well.

The easiest way to update QEMU and Libvirt, is to simply use a custom PPA archive like this one.

How to build QEMU, example for version 4.1 on Ubuntu 18.04

This article is basically copy and paste from the excellent reddit post by liquify. It was suggested to use checkinstall in order to create an .deb-file and install it via aptitude (this would for example automatically take care of the apparmor configuration).

Unfortunately, I was unable to get this working. Thus, I sticked with the original post by liquify. This way the hand build version will not compromise the distro managed version.

  • Enable source apt list (check Source Code in “Software & Updates“, “Ubuntu Software” tab.)
  • Download the build dependencies for qemu via:
    sudo apt-get build-dep qemu
  • Download the latest QEMU source code (4.1 in my case)
wget https://download.qemu.org/qemu-4.1.0.tar.xz 
tar xvJf qemu-4.1.0.tar.xz 
cd qemu-4.1.0
./configure --target-list=x86_64-softmmu --audio-drv-list=alsa,pa
make
  • When this is done go into the build directory. QEMU builds are meant to be placed in /usr/local/bin (use --prefix= argument to change this).
  • Move the QEMU binary and BIOS directory to its build target destination.
    cd build
    sudo cp x86_64-softmmu/qemu-system-x86_64 /usr/local/bin/qemu4.1-system-x86_64
    sudo cp -r pc-bios /usr/local/share/qemu

Attention: I had the problem with bins from the pc-bios folder that only links have been created, instead of copying the actual file.

  • Add the first Apparmor addition (libvirt-qemu)
    sudo nano /etc/apparmor.d/abstractions/libvirt-qemu
  • find the block starting with #Site-specific additions and overrides and paste the following at the end of the block
    # Custom QEMU binary rules
    /usr/local/bin/qemu4.1-system-x86_64 rmix,
    /usr/local/share/qemu/** r,
  • Make sure the indent is matching with the other lines. Save and close the file.
  • Add the second Apparmor addition (libvirtd)
    sudo nano /etc/apparmor.d/usr.sbin.libvirtd
  • find the block starting with #Site-specific additions and overrides and paste the following at the end of the block
    # Custom QEMU binary rule
    /usr/local/bin/qemu4.1-system-x86_64 PUx,
  • Make sure the indent is matching with the other lines. Save and close the file.
  • Reload the Apparmor service, or reboot. Reload is triggered via:
    sudo service apparmor reload
  • When this is done you can later use in your Libvirt config file.
<os>
   ...
   <type arch='x86_64' machine='pc-q35-4.1'>hvm</type>
   ...
</os>
and 
<devices>
   ...
   <emulator>/usr/local/bin/qemu4.1-system-x86_64</emulator>
   ...
</devices>

How to use a custom archive to update QEMU on Ubuntu 18.04

I use the virtualisation ppa from Jakob Zimmermann.

For the sake of completeness and beginner friendliness this is how you use it.

Open a terminal and run:
sudo add-apt-repository ppa:jacob/virtualisation

When the repository is added successfully, you can update QEMU and libvirt.
sudo apt-get update
sudo apt-get upgrade

Sources

Great reddit post by liquify, and askubuntu.com answer by N0rbert

Is this content any helpful? Then please consider supporting me.

If you appreciate the content I create, this is your chance to give something back and earn some good old karma.

Although ads are fun to play with, and very important for content creators, I felt a strong hypocrisy in putting ads on my website. Even though, I always try to minimize the data collecting part to a minimum.

Thus, please consider supporting this website directly 😘

2 comments on “How to update QEMU on Ubuntu”

  1. Chaython

    Is there anyway to view diff in the packages before upgrading to the ones in the PPA? How do I know I can trust the PPA?

    Reply
    1. luc

      just build it yourself, if you had the prebuilt packages you wouldnt need the PPA

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *