Virtualization

Install KVM Ubuntu 22.04 – Step-by-Step

Many hypervisors are great platforms for running virtual machines in your environment, including commercial hypervisors and open-source options. However, let’s look at Kernel-based virtual machine (KVM). KVM on ubuntu 22.04 is a great option for running an open-source virtual machine manager platform and is easy to get up and running on. What does it take to get the KVM hypervisor running in Ubuntu 22.04? Let’s see.

Video overview

Take a look at the video overview of the process here:

What is Kernel-based virtual machine (KVM)?

The KVM hypervisor is freely available hypervisor found as part of modern Linux distributions since around 2006. KVM is a type 1 hypervisor that is part of the Linux kernel and is a loadable kernel module that provides virtualization capabilities in Linux systems, allowing you to run virtual machines.

A type 1 hypervisor

Type 1 means it is a bare metal hypervisor capable of really robust performance. It allows running virtual machines on top of your host hardware by using host hardware emulation.

Many available tools

There are also many tools available that allow you to manage virtual machines running on KVM effectively. KVM virtual machines operate and run like virtual machines on other hypervisor platforms.

Features of KVM

The KVM kernel-based virtual machine configuration has many of the features and capabilities you would find in commercially available enterprise hypervisors. Like many other hypervisors, it emulates a physical machine, including a system BIOS, CPU, memory, disk, and other components needed to run a full operating system in its own environment.

It allows admins to granularly assign CPU cores, and other resources as needed for specific virtual machine workloads.

Benefits of KVM hypervisor

What are the benefits of the KVM hypervisor? There are many, but below are a few of the ones to note:

  • It is free
  • It is easy to install
  • There are GUI management tools available
  • It has proven scalability – capable of thousands of nodes in a cluster
  • Amazon AWS EC2 services are said to be built on a version of KVM

What are the requirements for running KVM on ubuntu 22.04?

The main requirement for running KVM on ubuntu 22.04 is to ensure you have a processor with CPU virtualization extensions built into the CPU.

Processors with this capability include the Intel VT and AMD-V technologies. This allows for KVM acceleration of the virtual machines to be able to perform as quickly as possible.

Checking for the CPU requirements

You can check to make sure you see the VMX capabilities listed (Intel) which indicates you have CPU hardware virtualization. Linux has a built-in CPU checker from the command line.

grep --color vmx /proc/cpuinfo
Verifying CPU virtualization capabilities on a prospective KVM host
Verifying CPU virtualization capabilities on a prospective KVM host

You want to ensure your host machine has a compatible CPU and plenty of memory and disk space for running KVM virtualization. Storage space needed and other resources will depend on the number of virtual machines ran on the host.

Network resources

You will likely want to have a few network interface cards in your KVM hypervisor host to provide options when configuring your bridge interface and bridge network.

If it is configured as a production host, you will most likely want to have a bonded network interface configuration for high availability and redundancy for better bandwidth.

You can also create virtual bridge configurations as well for VLANs and other use cases.

Healthy ecosystem of support and applications

Running KVM on an Ubuntu system provides benefits since Ubuntu is an extremely popular distribution, with great community support, and a healthy app repository.

Install KVM on Ubuntu 22.04

Let’s look at a KVM installation on Ubuntu 22.04 and see what command line commands are needed to install KVM and the required components on your Ubuntu 22.04 system. First of all, you will need to have an Ubuntu 22.04 system built and ready to go for the install kvm on ubuntu 22.04 process.

Below, I am running a sudo apt update to ensure we have the latest Ubuntu packages installed.

Running updates in Ubuntu 22.04
Running updates in Ubuntu 22.04

If you would like to see how to quickly build up an Ubuntu 22.04 template in your VMware vSphere environment, take a look at my post on how to do that here:

Packer Build Ubuntu 22.04 for VMware vSphere

Installing packages overview

What KVM packages are required to install kvm on ubuntu 22.04?

  • You need to install qemu kvm
  • You need to install qemu kvm libvirt
  • virt install qemu kvm
  • You will want to install KVM virt-manager for a graphical interface using the apt install virt manager command from the apt package manager

KVM virtual machines packages install:

Note the following command line commands in Ubuntu 22.04:

sudo apt install libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils qemu qemu-kvm
Installing the required KVM components
Installing the required KVM components

Checking for KVM virtual machines capabilities

There is a quick command we can run to check for the KVM virtualization capabilities in our Ubuntu 22.04 installation. Simple run the command:

kvm-ok

You should see the return listed below that KVM acceleration can be used.

KVM acceleration can be used
KVM acceleration can be used

Install Virt-Manager in Ubuntu 22.04 workstation

To easily manage your KVM installation in Ubuntu with a graphical interface and have the ability to easily create virtual machines, the Virt-Manager utility is a graphical interface allowing you to manage your KVM installation.

With Virt-Manager, you can create a new virtual machine, manage local install media, including an ISO file for OS installation on your new virtual machine.

Below, we are using the command:

sudo apt install virt-manager
Install Virt manager in Ubuntu
Install Virt manager in Ubuntu

Install ssh-askpass

Another required tool for using password authentication to your KVM host is the ask-ssh package. The ssh-askpass utility allows getting a prompt to input your SSH credentials from Virt-Manager.

The user you use needs to be a member of the libvirt group to manage the KVM installation.

sudo apt install ssh-askpass
Installing ssh askpass in Ubuntu
Installing ssh askpass in Ubuntu

Adding a new connection to your KVM installation in Virt-Manager

After installing Virt-manager, we can now add a connection to our KVM host.

Adding a connection in Virt Manager
Adding a connection in Virt Manager

Once the connection is added, you will see the KVM host listed. At this point, you can simply double-click the host to connect.

KVM host added to Virt manager
KVM host added to Virt manager

Upload an ISO image to use for guest operating system installation

Now, we can upload an ISO file to the KVM host to use for installing the guest operating system. The default location for uploading ISO image files to KVM is the /var/lib/libvirt/images location.

After you have uploaded the ISO file to the KVM host, we can begin the process to create a virtual machine using Virt-Manager.

Create a new virtual machine in KVM virt manager

Now, we can begin the process to create a new virtual machine. Click the File > New Virtual Machine option. First, we need to select the ISO image to use for the installation.

Select the ISO image
Select the ISO image

Click Browse.

Browse to select the ISO image
Browse to select the ISO image

Select the ISO image displaying in the default images location.

Select the ISO image you have uploaded to the KVM host
Select the ISO image you have uploaded to the KVM host

I noticed that the operating system didn’t get populated with Windows Server 2022. If you begin typing in the operating system field, it will display a list that you can choose from. I chose the Windows Server 2022 installation operating system option.

ISO image is selected and ready to move forward
ISO image is selected and ready to move forward

Choose your CPU and memory configuration.

Configure CPU and memory
Configure CPU and memory

Configure the disk size for the installation.

Configure the disk size for the new virtual machine
Configure the disk size for the new virtual machine

On the review configuration screen, you can also choose the network interface you want to use such as the default bridge. It will default to a NAT’ed configuration out of the box.

Ready to begin and select the network configuration
Ready to begin and select the network configuration

I found I needed to change the default boot order as the CD-ROM will not be enabled or set to boot first.

Changing the boot order
Changing the boot order

After changing the boot order, the new virtual machine manager VM booted correctly.

Connecting to your guest operating system loading
Connecting to your guest operating system loading

Wrapping Up

All in all, the experience getting up and running with KVM in Ubuntu 22.04 is painless. After running a Ubuntu 22.04 machine, it is as simple as installing the KVM packages required for KVM to run. After that, you can use another Ubuntu workstation machine to install Virt-Manager and easily connect to the KVM host.

Subscribe to VirtualizationHowto via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

One Comment

  1. Thanks for the tutorial. Was able to get some VMs up with this.

    You have some reference, tutorials about KVM networking?

    I have VM a and VM b. VM a needs to be able to communicate with VM b as well as the LAN and Internet whereas VM b only talks to VM a.

    I probably need a combination of NAT and bridge network but don’t know where to start. Txs

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.