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
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.
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
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.
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 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
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.
Once the connection is added, you will see the KVM host listed. At this point, you can simply double-click the host to connect.
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.
Click Browse.
Select the ISO image displaying in the default images location.
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.
Choose your CPU and memory configuration.
Configure the disk size for the installation.
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.
I found I needed to change the default boot order as the CD-ROM will not be enabled or set to boot first.
After changing the boot order, the new virtual machine manager VM booted correctly.
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.
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