To run virtual machines, most organizations use commercial virtualization solutions on the market, such as VMware, Hyper-V, and Nutanix. As an alternative, you can consider the free kernel-based virtual machine (KVM) that turns Ubuntu Linux into a hypervisor host.

Like other commercial hypervisors, KVM provides the benefit of enabling the guest operating system with the expected components of a physical system. Because it is a native Linux kernel module, it directly benefits from the improvements and capabilities of each new release of the Linux kernel. As for most hypervisors, you need a CPU that supports virtualization extensions, such as Intel-VT or AMD-V.

Benefits of the KVM hypervisor

There are many obvious and implied benefits of running virtual machines on KVM:

  • License cost: Since KVM is open source and readily available in modern Linux distributions, it is a free solution.
  • Massive scalability: KVM is built to provide massive scalability. The Amazon AWS EC2 service is said to be built on top of a highly customized version of KVM.
  • Performance: KVM is a true type-1 hypervisor that allows guest virtual machines to run with the near bare-metal performance of a physical host.
  • Storage: KVM can use any storage supported by Linux. This includes local disks, NAS, and multipath I/O storage capabilities.
  • Hardware support: You can use KVM on any supported Linux hardware.

In this walkthrough, we will use Ubuntu Server 22.04 for the virtualization host. Next, we will load the virt-manager tool on an Ubuntu workstation to interact with the KVM host and access GUI-based configuration and management tools.

Install KVM on an Ubuntu Server

Once we have a fresh installation of Ubuntu Server 22.04 and patches installed, we can add KVM and the required components using the following command:

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

Installing the required KVM components on the Ubuntu Server

Installing the required KVM components on the Ubuntu Server

After installing the KVM components, you can verify that the KVM installation is ready with the command:

kvm-ok

Checking the KVM status on the Ubuntu Server

Checking the KVM status on the Ubuntu Server

On my Ubuntu workstation, I am verifying that I can connect via SSH to the remote Ubuntu Server running KVM, since virt-manager will use SSH for connectivity.

Verifying SSH connectivity on the Ubuntu Server

Verifying SSH connectivity on the Ubuntu Server

Install virt-manager on an Ubuntu workstation

Now, let's install virt-manager on an Ubuntu workstation. You can do that with the following command:

sudo apt install virt-manager

Installing virt manager in Ubuntu

Installing virt manager in Ubuntu

Next, we need to install a utility called ssh-askpass. It allows us to have SSH password prompts when using virt-manager.

Installing SSH ask pass

Installing SSH ask pass

Connecting to the remote Ubuntu Server KVM host

Once virt-manager is installed, we can launch it and add a connection to our KVM server.

Connecting to the Ubuntu Server running KVM

Connecting to the Ubuntu Server running KVM

The ask-ssh utility will launch. One thing that isn't intuitive is there is no area to type your password. So, instead, you simply start typing your password, and it will record it as you type.

Enter your SSH password for the remote Ubuntu Server running KVM

Enter your SSH password for the remote Ubuntu Server running KVM

We are now connected to the KVM server running on Ubuntu.

Creating a new virtual machine on KVM

Now, we can create a new virtual machine. Click the File > New Virtual Machine option.

The New VM wizard launches. First, select how you would like to install the operating system. I will be using an ISO image uploaded to the Ubuntu Server. So, I am selecting the first option.

Choose how you would like to install the operating system

Choose how you would like to install the operating system

The default location to which you can upload your images is /var/lib/libvirt/images. I have uploaded Windows Server 2022 ISO to this directory. Choose the ISO file, and double-click it to return to the New VM wizard.

Upload your installation media to your Ubuntu Server

Upload your installation media to your Ubuntu Server

The ISO is now populated in the install media field. In the Choose the operating system you are installing field, you can start typing the name of the OS, such as "Windows," and it will list the available options.

Installation media chosen and guest operating system selected

Installation media chosen and guest operating system selected

Next, select your memory and CPU configuration.

Configure the memory and CPUs

Configure the memory and CPUs

Select the disk size for the new virtual machine.

Create the storage for the virtual machine

Create the storage for the virtual machine

Name the virtual machine, and select your network configuration.

Name the virtual machine and select the networking configuration

Name the virtual machine and select the networking configuration

I had to change the Boot Options to ensure that the ISO was enabled and selected as the first boot option. Place a check by the CDROM, and ensure it is listed first.

Verify the boot order for the VM

Verify the boot order for the VM

Also, I kept getting prompted for the SSH password when connecting to the console until I ensured that the VNC Server option was selected under the VNC Server type.

Verify the display VNC server

Verify the display VNC server

After booting the server and selecting the console, you will see your guest operating system booting up with the expected installation prompts.

Booting the Windows installation in the new KVM virtual machine

Booting the Windows installation in the new KVM virtual machine

It is recommended to install paravirtualized drivers in Windows guests to enhance performance. These drivers are included in the virtio package. The package supports block (storage) devices and network interface controllers.

Wrapping up

KVM is a great option for virtualization, as it provides a tried-and-true zero-cost hypervisor for running virtual machines on top of your favorite Linux distribution.

Subscribe to 4sysops newsletter!

As shown, the steps for installing KVM in Ubuntu are fairly simple. In addition, you can use the virt-manager console to have GUI management tools for creating and configuring your virtual machines. With these simple tools, KVM provides a robust virtualization platform with many benefits.

avataravatar
6 Comments
  1. Samir 12 months ago

    Neat. Any way to run KVM bare metal?

    • I don’t think it is possible since KVM is just a kernel module and other core components needed for virtualization.

      avatar
      • It requires a minimal OS to operate at least.

      • Samir 12 months ago

        Ah, I see. Still a great alternative to running a traditional hypervisor on top of an OS like Hyper-V.

    • jrizzler 12 months ago

      Excellent article, I use ProxMox. I’m able to run a VM with a GPU passthrough so I can run my desktop on a hypervisor. Passing through a discrete GPU is easier than a integrated GPU though.

      avatar
  2. mehdi 10 months ago

    What is your situation? how that work for you? are you still using Proxmox?

Leave a reply

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

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account