You are on page 1of 36

02/11/2023 01:50 How to Install KVM on Ubuntu 22.

04 Step-by-Step

 Menu

How to Install KVM on Ubuntu 22.04 Step-by-Step


Last Updated: September 29, 2023 by James Kiarie

···
This blog post will show you how to install KVM on Ubuntu 22.04 step-by-step. At the tail
end of this post, we will demonstrate how you can create a virtual machine once the
installation of KVM is complete.

KVM, an acronym for Kernel-based Virtual Machine is an opensource virtualization


technology integrated into the Linux kernel. It’s a type 1 (bare metal ) hypervisor that
enables the kernel to act as a bare-metal hypervisor.

KVM allows users to create and run multiple guest machines which can be either Windows
or Linux. Each guest machine runs independently of other virtual machines and the
underlying OS ( host system ) and has its own computing resources such as CPU, RAM,
network interfaces, and storage to mention a few.

···

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 1/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

Prerequisites
Pre Installed Ubuntu 22.04
2 vCPUs & 4 GB RAM
Stable Internet Connectivity

1) Update Ubuntu 22.04


To get off the ground, launch the terminal and update your local package index as follows.

$ sudo apt update

2) Check if Virtualization is enabled


Before you proceed any further, you need to check if your CPU supports KVM virtualization.
For this to be possible, your system needs to either have a VT-x( vmx ) Intel processor or an
AMD-V (svm) processor.

This is achieved by running the following command. if the output is greater than 0, then
virtualization is enabled. Otherwise, virtualization is disabled and you need to enable it.

$ egrep -c '(vmx|svm)' /proc/cpuinfo

From the above output, you can deduce that virtualization is enabled since the result
printed is greater than 0. If Virtualization is not enabled, be sure to enable the virtualization
feature in your system’s BIOS settings.

In addition, you can verify if KVM virtualization is enabled by running the following

command:

$ kvm-ok

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 2/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

For this to work, you need to have installed the cpu-checker package, otherwise, you will
bump into the error ‘Command ‘kvm-ok’ not found’.

Directly below, you will get instructions on how to resolve this issue, and that is to install
the cpu-checker package.

···

Therefore, install the cpu-checker package as follows.

$ sudo apt install -y cpu-checker

Then run the kvm-ok command, and if KVM virtualization is enabled, you should get the
following output.


$ kvm-ok

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 3/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

3) Install KVM on Ubuntu 22.04


Next, run the command below to install KVM and additional virtualization packages on
Ubuntu 22.04.

$ sudo apt install -y qemu-kvm virt-manager libvirt-daemon-system virtinst li

Let us break down the packages that we are installing:

···

qemu-kvm – An opensource emulator and virtualization package that provides


hardware emulation.
virt-manager – A Qt-based graphical interface for managing virtual machines via the
libvirt daemon. 
libvirt-daemon-system – A package that provides configuration files required to run
the libvirt daemon.
virtinst – A set of command-line utilities for provisioning and modifying virtual
machines.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 4/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

libvirt-clients – A set of client-side libraries and APIs for managing and controlling
virtual machines & hypervisors from the command line.
bridge-utils – A set of tools for creating and managing bridge devices.

4) Start & Enable Virtualization Daemon


With all the packages installed, enable and start the Libvirt daemon.

$ sudo systemctl enable --now libvirtd


$ sudo systemctl start libvirtd

Confirm that the virtualization daemon is running as shown.

···

$ sudo systemctl status libvirtd

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 5/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

In addition, you need to add the currently logged-in user to the kvm and libvirt groups so
that they can create and manage virtual machines.

$ sudo usermod -aG kvm $USER


$ sudo usermod -aG libvirt $USER

The $USER environment variable points to the name of the currently logged-in user. To
apply this change, you need to log out and log back again.

···


5) Create Network Bridge (br0)
If you are planning to access KVM virtual machines outside from your Ubuntu 22.04 system,
then you must map VM’s interface to a network bridge. Though a virtual bridge named
virbr0, created automatically when KVM is installed but it is used for testing purposes.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 6/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

To create a network bridge, create the file ‘01-netcfg.yaml’ with following content under the
folder /etc/netplan.

$ sudo vi /etc/netplan/01-netcfg.yaml
network:
ethernets:
enp0s3:
dhcp4: false
dhcp6: false
# add configuration for bridge interface
bridges:
br0:
interfaces: [enp0s3]
dhcp4: false
addresses: [192.168.1.162/24]
macaddress: 08:00:27:4b:1d:45
routes:
- to: default
via: 192.168.1.1
metric: 100
nameservers:
addresses: [4.2.2.2]
parameters:
stp: false
dhcp6: false
version: 2

save and exit the file.

Note: These details as per my setup, so replace the IP address entries, interface name and
mac address as per your setup.

···

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 7/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

To apply above change, run ‘netplan apply’

$ sudo netplan apply

Verify the network bridge ‘br0’, run below ip command

$ ip add show

6) Launch KVM Virtual Machines Manager


With KVM installed, you can begin creating your virtual machines using the virt-manager
GUI tool. To get started, use the GNOME search utility and search for ‘Virtual machine
Manager’.

Click on the icon that pops up.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 8/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

···

This launches the Virtual Machine Manager Interface.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 9/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

Click on “File” then select “New Virtual Machine”. Alternatively, you can click on the button
shown.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 10/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

This pops open the virtual machine installation wizard which presents you with the
following four options:

Local install Media ( ISO image or CDROM )


Network Install ( HTTP, HTTPS, and FTP )
Import existing disk image
Manual Install

In this guide, we have downloaded a Debian 11 ISO image, and therefore, if you have an
ISO image, select the first option and click ‘Forward’.

In the next step, click ‘Browse’ to navigate to the location of the ISO image,

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 11/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

In the next window, click ‘Browse local’ in order to select the ISO image from the local
directories on your Linux PC.

···

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 12/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

···

As demonstrated below, we have selected the Debian 11 ISO image. Then click ‘Open’

Once the ISO image is selected, click ‘Forward’ to proceed to the next step.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 13/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

Next, define the RAM and the number of CPU cores for your virtual machine and click
‘Forward’.

In the next step, define the disk space for your virtual machine and click ‘Forward’.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 14/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

To associate virtual machine’s nic to network bridge, click on ‘Network selection’ and choose
br0 bridge.

Finally, click ‘Finish’ to wind up setting the virtual machine.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 15/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

Shortly afterward, the virtual machine creation will get underway.

Once completed, the virtual machine will start with the OS installer displayed. Below is the
Debian 11 installer listing the options for installation. From here, you can proceed to install
your preferred system.

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 16/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

Conclusion
And that’s it. In this guide, we have demonstrated how you can install the KVM hypervisor
on Ubuntu 22.04. Your feedback on this guide is much welcome.

Read Also: How to Create KVM Virtual Machine Snapshot with Virsh Command

Share Now!

···

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 17/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

3 thoughts on “How to Install KVM on Ubuntu


22.04 Step-by-Step”

Kamus
July 4, 2022 at 10:44 am

Hi James, thanks for this great article, I would like to add a little comment.
If you want to let host machine to access the vm machine by SSH, and let the vm
machine to access internet by the host machine ethernet, there is a additional
package should be installed.
sudo apt install libnss-libvirt

Reply

Pål Bjartan
October 10, 2022 at 10:42 am

Thanks for a detailed tutorial. However, I am facing an issue with creating a


network bridge. I created the `/etc/netplan/01-netcfg.yaml` file as described in step
5, but this resulted in Ubuntu no longer connecting to the WiFi. It now shows a
LAN icon in the top right corner. Deleting the file and running `sudo netplan apply`
again solved the issue. I presume Ubuntu instead attempts to use the bridge to
connect to the Internet.

Is there a way this can be avoided?

Reply

John
October 16, 2022 at 12:01 am

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 18/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

So I upgraded my Ubuntu 20.04 LTS hypervisor to 22..04 LTS.

systemctl status libvirtd says:

VMM is missing/removed and Storage Pool no longer showing up.

tried to re-install via APT, APT-GET ‘virt-manager’ and ‘virtinst’ packages, neither
one is found.
Anyone else encountering this issue after Ubuntu 22.04 LTS ‘jammy jellyfish’
upgrade from 20.04 LTS?

Reply

Leave a Comment

Name *

Email *

Post Comment

Search … 

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 19/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 20/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

Recent Posts

How to Install MySQL on Ubuntu 22.04 Step-by-Step

How to Install VirtualBox on Linux Mint 21 Step-by-Step

How to Install VirtualBox Guest Additions on Linux Mint 21

How to Register Existing Kubernetes Cluster in Rancher

How to Install and Configure VNC Server on RHEL 9

How to Install LMDE 6 (Linux Mint Debian Edition)

How to Install Rancher on Rocky Linux 9 / AlmaLinux 9

How to Install VirtualBox Guest Additions on RHEL 9

How to Install Kubernetes on Rocky Linux 9 | AlmaLinux 9

How to Create Virtual Machine in Proxmox VE Using Web UI

···

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 21/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 22/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 23/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 24/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 25/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 26/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 27/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 28/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 29/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 30/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 31/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 32/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 33/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 34/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 35/36
02/11/2023 01:50 How to Install KVM on Ubuntu 22.04 Step-by-Step

HTML Sitemap Privacy Policy Contact Us About Us Write For LinuxTechi

Follow Us

© 2023 LinuxTechi

https://www.linuxtechi.com/how-to-install-kvm-on-ubuntu-22-04/ 36/36

You might also like