In this guide, we want to teach you How To Install KVM on Ubuntu 20.04.
A kernel-based virtual machine (KVM) is a virtualization infrastructure built for Linux OS and designed to operate on x86-based processor architecture.
KVM is developed by Red Hat Corporation to provide a virtualization solution and services on the Linux operating system platform. It is designed over the primary Linux OS kernel.
KVM is a type of hypervisor that enables, emulates, and provides for the creation of virtual machines on operating systems. These machines are built on top of the Linux kernel, using operating systems such as Linux, Ubuntu, and Fedora. It can be installed on all x86 processors and provide separate instruction set extensions for Intel and AMD processors.
Install KVM hypervisor on Ubuntu 20.04
To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Ubuntu 20.04.
Check Virtualization Support on Ubuntu 20.04
Before installing KVM, you need to make sure that KVM is compatible with your system. Otherwise, you will keep running into errors, and KVM won’t install properly.
First, update and upgrade your local package index with the following command:
sudo apt update && sudo apt upgrade -y
To check whether the Ubuntu system supports virtualization, run the following command:
egrep -c '(vmx|svm)' /proc/cpuinfo
If the output you get is greater than 0, that means KVM is compatible with the system and can be installed.
To check if your system supports KVM virtualization execute the command:
If the “kvm-ok” utility is not present on your server, install it by running the apt command:
sudo apt install cpu-checker
Now execute the “kvm-ok” command to probe your system.
Output INFO: /dev/kvm exists KVM acceleration can be used
Installing KVM on Ubuntu 20.04
At this point, you need to install the required packages and dependencies by running the command below:
sudo apt install -y qemu qemu-kvm libvirt-daemon libvirt-clients bridge-utils virt-manager
Then, you need to check that that the virtualization daemon – libvritd-daemon – is running on Ubuntu 20.04:
sudo systemctl status libvirtd
Output ● libvirtd.service - Virtualization daemon Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor pres> Active: active (running) since Wed 2022-08-31 10:15:31 CEST; 1min 19s ago TriggeredBy: ● libvirtd.socket ● libvirtd-ro.socket ● libvirtd-admin.socket Docs: man:libvirtd(8) https://libvirt.org ...
Also, you can use the command below to enable it to start on boot:
sudo systemctl enable --now libvirtd
To check if the KVM modules are loaded, run the command:
lsmod | grep -i kvm
Now add your user to KVM and libvirt group to get up KVM and avoid running into issues. The user can be added to the KVM group using this command:
sudo usermod -aG kvm $USER
Next, add the user to the libvirt group by using this command:
sudo usermod -aG libvirt $USER
At this point, you learn to test the compatibility between KVM and your Ubuntu system. After that, you installed the necessary KVM packages and then installed KVM.
Hope you enjoy it.
You may be interested in these articles: