Cyberithub

How to Install QEMU on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, I will take you through the steps to install QEMU on Ubuntu 20.04 LTS (Focal Fossa). Quick Emulator (QEMU) is a free and open source emulator which also happens to be a main component of the QEMU/KVM virtualization technology suit. It provides hardware virtualization and processor emulation. QEMU runs in userspace and, without the need for kernel, drivers are responsible for providing fast system emulation. It can be easily installed on a Linux or Unix based systems. But here we will only see the steps to install on a Ubuntu 20.04 LTS System.

 

Important Features

  • It runs operating systems for any machine, on any supported architecture.
  • It run programs for another Linux/BSD target, on any supported architecture.
  • It runs KVM and Xen virtual machines with near native performance.

 

Operating Modes

QEMU supports two operating modes:-

  • Full system emulation, where QEMU emulates an entire computer system, including the CPU type and peripherals.
  • User mode emulation, where QEMU can run a process that has been compiled on a different CPU architecture natively.

How to Install QEMU on Ubuntu 20.04 LTS (Focal Fossa)

How to Install QEMU on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: How to Install Oh My ZSH on Ubuntu 20.04 LTS (Focal Fossa)

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS System.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get and wget or curl utility available in your System.

 

Step 2: Update Your Server

In the first step, you need to sync all the installed packages with the latest available versions from the default Ubuntu repo and upgrade the required packages by using sudo apt-get update && sudo apt-get upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for cyberithub:
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Hit:4 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:6 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:7 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:8 http://ppa.launchpad.net/wireshark-dev/stable/ubuntu focal InRelease
Hit:9 https://apt.boltops.com stable InRelease
Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [92.7 kB]
Get:13 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [745 kB]
Get:15 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,196 kB]
Get:16 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]
Get:17 http://in.archive.ubuntu.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [405 kB]
Get:18 http://in.archive.ubuntu.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:19 http://in.archive.ubuntu.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [7,996 B]
Get:20 http://in.archive.ubuntu.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.5 kB]
Fetched 4,132 kB in 4s (1,055 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://apt.boltops.com stable InRelease' doesn't support architecture 'i386'
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
fonts-wine glib-networking:i386 gstreamer1.0-plugins-good:i386 gstreamer1.0-x:i386 i965-va-driver:i386 intel-media-va-driver:i386 libaa1:i386
libaom0:i386 libavc1394-0:i386 libavcodec58:i386 libavutil56:i386 libcaca0:i386 libcairo-gobject2:i386 libcapi20-3 libcapi20-3:i386 libcodec2-0.9:i386
...........................................

 

Step 3: Install Essential Packages

There are few essential packages which needs to be available in the system to install qemu emulator. All those packages can be installed by using below apt install command.

cyberithub@ubuntu:~$ sudo apt install libpixman-1-dev libcairo2-dev libpango1.0-dev libjpeg8-dev libgif-dev ninja-build

 

Step 4: Install QEMU

There are different ways available to install qemu emulator on Ubuntu 20.04 LTS System. We will look into two of the best ways.

a) Using default repo

The easiest way to install is through default Ubuntu repo by using sudo apt install qemu command as shown below. But there is a chance that you might not get the latest available qemu version from Ubuntu repo. So if the version does not matter then you can think of installing by this method.

cyberithub@ubuntu:~$ sudo apt install qemu
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
qemu
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 15.1 kB of archives.
After this operation, 126 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 qemu amd64 1:4.2-3ubuntu6.23 [15.1 kB]
Fetched 15.1 kB in 1s (22.4 kB/s)
Selecting previously unselected package qemu.
(Reading database ... 269656 files and directories currently installed.)
Preparing to unpack .../qemu_1%3a4.2-3ubuntu6.23_amd64.deb ...
Unpacking qemu (1:4.2-3ubuntu6.23) ...
Setting up qemu (1:4.2-3ubuntu6.23) ...

b) Using source code

If you are looking to install the latest qemu version then this is the method to use. You need to first download the latest qemu source code from official website using wget or curl utility.

cyberithub@ubuntu:~$ wget https://download.qemu.org/qemu-7.1.0.tar.xz
--2022-10-30 18:59:20-- https://download.qemu.org/qemu-7.1.0.tar.xz
Resolving download.qemu.org (download.qemu.org)... 13.107.246.58, 13.107.213.58, 2620:1ec:bdf::58, ...
Connecting to download.qemu.org (download.qemu.org)|13.107.246.58|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 121833004 (116M) [application/x-tar]
Saving to: ‘qemu-7.1.0.tar.xz’

qemu-7.1.0.tar.xz 100%[============================================================================>] 116.19M 5.38MB/s in 26s

2022-10-30 18:59:46 (4.51 MB/s) - ‘qemu-7.1.0.tar.xz’ saved [121833004/121833004]

Then extract the tar file by using tar xvJf qemu-7.1.0.tar.xz command as shown below.

cyberithub@ubuntu:~$ tar xvJf qemu-7.1.0.tar.xz

Switch to directory qemu-7.1.0 using cd qemu-7.1.0 command.

cyberithub@ubuntu:~$ cd qemu-7.1.0

Configure all the settings according to the local system by using ./configure as shown below.

cyberithub@ubuntu:~/qemu-7.1.0$ ./configure
Using './build' as the directory for build output
The Meson build system
Version: 0.59.3
Source dir: /home/cyberithub/qemu-7.1.0
Build dir: /home/cyberithub/qemu-7.1.0/build
Build type: native build
Project name: qemu
Project version: 7.1.0
C compiler for the host machine: cc -m64 -mcx16 (gcc 9.4.0 "cc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0")
C linker for the host machine: cc -m64 -mcx16 ld.bfd 2.39
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program scripts/symlink-install-tree.py found: YES (/usr/bin/python3 /home/cyberithub/qemu-7.1.0/scripts/symlink-install-tree.py)
Program sh found: YES (/usr/bin/sh)
Program python3 found: YES (/usr/bin/python3)
WARNING: Broken python installation detected. Python files installed by Meson might not be found by python interpreter.
Program bzip2 found: YES (/usr/bin/bzip2)
Program iasl found: NO
.....................................................

Once configured, compile the source code using make command.

cyberithub@ubuntu:~/qemu-7.1.0$ make
changing dir to build for make ""...
make[1]: Entering directory '/home/cyberithub/qemu-7.1.0/build'
/usr/bin/ninja build.ninja && touch build.ninja.stamp
ninja: no work to do.
/usr/bin/python3 -B /home/cyberithub/qemu-7.1.0/meson/meson.py introspect --targets --tests --benchmarks | /usr/bin/python3 -B scripts/mtest2make.py > Makefile.mtest
[1/9617] Compiling C object libslirp.a.p/slirp_src_ndp_table.c.o
[2/9617] Compiling C object libslirp.a.p/slirp_src_sbuf.c.o
[3/9617] Compiling C object libslirp.a.p/slirp_src_slirp.c.o
[4/9617] Compiling C object libslirp.a.p/slirp_src_socket.c.o
[5/9617] Compiling C object libslirp.a.p/slirp_src_ncsi.c.o
[6/9617] Compiling C object libslirp.a.p/slirp_src_state.c.o
[7/9617] Compiling C object libslirp.a.p/slirp_src_arp_table.c.o
[8/9617] Generating config-poison.h with a custom command (wrapped by meson to capture output)
[9/9617] Compiling C object libslirp.a.p/slirp_src_bootp.c.o
[10/9617] Compiling C object libslirp.a.p/slirp_src_cksum.c.o
[11/9617] Compiling C object libslirp.a.p/slirp_src_dhcpv6.c.o
[12/9617] Compiling C object libslirp.a.p/slirp_src_dnssearch.c.o
[13/9617] Compiling C object libslirp.a.p/slirp_src_if.c.o
[14/9617] Compiling C object libslirp.a.p/slirp_src_ip6_icmp.c.o

Finally install the compiled modules using make install command.

cyberithub@ubuntu:~/qemu-7.1.0$ make install

 

Step 5: Verify Installation

After successful installation, you can verify the qemu metapackage by using dpkg --list | grep qemu command as shown below.

cyberithub@ubuntu:~$ dpkg --list | grep qemu
ii qemu 1:4.2-3ubuntu6.23 amd64 fast processor emulator, dummy package

 

Step 6: Uninstall QEMU

Once you are done using qemu emulator, you can choose to uninstall it from your System by using sudo apt remove qemu command as shown below.

NOTE:

Please check for any unwanted package removal before running below command as sometimes it uninstalls some package which is used by some other active running application. So that might cause a disaster especially when you are performing below step in a production or critical system.
cyberithub@ubuntu:~$ sudo apt remove qemu
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
qemu
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 126 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 269660 files and directories currently installed.)
Removing qemu (1:4.2-3ubuntu6.23) ...

2 thoughts on “How to Install QEMU on Ubuntu 20.04 LTS (Focal Fossa)”

  1. Thank you!
    Your instructions worked flawlessly 'out of the box'. I spent a couple of hours, before this, tearing out lots of hair trying other solutions!

    Reply

Leave a Comment