- Docker logs tail: Troubleshoot Docker containers with real-time logging - Wed, Sep 13 2023
- dsregcmd: Troubleshoot and manage Azure Active Directory (Microsoft Entra ID) joined devices - Thu, Aug 31 2023
- Ten sed command examples - Wed, Aug 23 2023
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
After installing the KVM components, you can verify that the KVM installation is ready with the command:
kvm-ok
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.
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
Next, we need to install a utility called ssh-askpass. It allows us to have SSH password prompts when using virt-manager.
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.
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.
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.
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.
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.
Next, select your memory and CPU configuration.
Select the disk size for the new virtual machine.
Name the virtual machine, and select your network 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.
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.
After booting the server and selecting the console, you will see your guest operating system booting up with the expected installation prompts.
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.
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.
It requires a minimal OS to operate at least.
Ah, I see. Still a great alternative to running a traditional hypervisor on top of an OS like Hyper-V.
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.
What is your situation? how that work for you? are you still using Proxmox?