How to install KVM Hypervisor on Ubuntu 20.04 (Focal Fossa)

In this guide, you will learn to install a KVM Hypervisor virtualization server on Ubuntu 20.04 (Focal Fossa). KVM (Kernel-based Virtual Machine) is a free and open source virtualization solution for Linux systems running on x86 hardware. It requires the server to have a CPU virtualization extension (Intel VT or AMD-V).

Check the link to install KVM on Fedora, RHEL / CentOS 8, Ubuntu

KVM contains a loadable kernel module,kvm.koIt provides the core virtualization infrastructure and processor-specific modules kvm-intel.ko or kvm-amd.ko.

Install KVM / QEMU on Ubuntu 20.04 (Focal Fossa)

Here are the steps to follow when installing KVM virtualization tools on an Ubuntu 20.04 (Focal Fossa) Linux computer. All KVM packages for Ubuntu are available in the upstream repository. The apt package manager is used for all package installations.

sudo apt -y install qemu-kvm libvirt-daemon bridge-utils virtinst libvirt-daemon-system

Aso installs other useful virtual machine management tools.

sudo apt -y install virt-top libguestfs-tools libosinfo-bin  qemu-system virt-manager

make sure vhost_net The module is loaded and enabled.

$ sudo modprobe vhost_net 
$ lsmod | grep vhost
vhost_net              24576  0
tun                    49152  1 vhost_net
vhost                  49152  1 vhost_net
tap                    28672  1 vhost_net

$ echo vhost_net | sudo teaa -a /etc/modules 

This will give you tools similar to Linux ls, cat, top Commands used with virtual machines.

Create KVM Bridge on Ubuntu 20.04 (optional)

In order for your virtual machine to talk to the outside world, a Linux bridge is required. Installing KVM on Ubuntu 20.04 creates a file called virbr0. This can be used in all test environments.

However, if you want to access the virtual machine over the network, you need to create a bridge on the physical network interface connected to the computer.

Create one on your Debian server / workstation as shown below.

sudo nano /etc/network/interfaces

My bridge configuration uses a network interface (ens33) Create a file named br1. Replace with the value you provided.

# Primary network interface
auto ens33
iface ens3 inet manual

# Bridge definitions
auto br1
iface br1 inet static
bridge_ports ens33
bridge_stp off

Restart the computer for the network configuration changes to take effect.

sudo reboot

Confirm the IP network details.

$ ip addr

See screenshot below.

Create a virtual machine on KVM

You can create instances on KVM using the Virtual Machine Manager GUI, or you can Install virt Command line tools.

For virt-install, the installation snippet is shared below.

$ sudo virt-install 
--name de10 
--ram 2048 
--vcpus 2 
--disk path=/var/lib/libvirt/images/deb10.qcow2,size=20 
--os-type linux 
--os-variant debian10 
--network bridge=br1 
--graphics none 
--console pty,target_type=serial 
--location '' 
--extra-args 'console=ttyS0,115200n8 serial'

This will download the kernel and initrd images before starting the installation.

How to install KVM Hypervisor on Ubuntu 20.04 (Focal Fossa)

The installation process will begin shortly. Follow the installation instructions for the Debian system on KVM.

How to install KVM Hypervisor on Ubuntu 20.04 (Focal Fossa)How to install KVM Hypervisor on Ubuntu 20.04 (Focal Fossa)

We also provide a guide on installing virtual machines on KVM using Terraform.

For more information on Ubuntu 20.04:

How to install LAMP Stack on Ubuntu 20.04 (Focal Fossa)

How to install MariaDB Server on Ubuntu 20.04 (Focal Fossa)

Also check out related KVM articles:

How to expand / increase KVM virtual machine (VM) disk size

How to create a CentOS / Fedora / RHEL VM template on KVM

How to run Minikube on KVM