KVM, (kernel-based Virtual Machine) is a free and opensource virtualization platform for the Linux kernel. When installed on a Linux system, it becomes a Type-2 hypervisor.
In this article, we look at how you can install KVM on Ubuntu 20.04 LTS.
Step 1: Check Virtualization Support in Ubuntu
Before installing KVM on Ubuntu, we are first going to verify if the hardware supports KVM. A minimum requirement for installing KVM is the availability of CPU virtualization extensions such as AMD-V and Intel-VT.
To check whether the Ubuntu system supports virtualization, run the following command.
$ egrep -c '(vmx|svm)' /proc/cpuinfo
An outcome greater than 0 implies that virtualization is supported. From the output below, we have confirmed that our server is good to go.
To check if your system supports KVM virtualization execute the command:
$ sudo kvm-ok
If the “kvm-ok” utility is not present on your server, install it by running the apt command:
$ sudo apt install cpu-checker
Now execute the “kvm-ok” command to probe your system.
$ sudo kvm-ok
The output clearly indicates that we are on the right path and ready to proceed with the installation of KVM.
Step 2: Install KVM on Ubuntu 20.04 LTS
With the confirmation that our system can support KVM virtualization, we are going to install KVM, To install KVM, virt-manager, bridge-utils and other dependencies, run the command:
$ sudo apt install -y qemu qemu-kvm libvirt-daemon libvirt-clients bridge-utils virt-manager
A little explanation of the above packages.
- The qemu package (quick emulator) is an application that allows you to perform hardware virtualization.
- The qemu-kvm package is the main KVM package.
- The libvritd-daemon is the virtualization daemon.
- The bridge-utils package helps you create a bridge connection to allow other users to access a virtual machine other than the host system.
- The virt-manager is an application for managing virtual machines through a graphical user interface.
Before proceeding further, we need to confirm that the virtualization daemon – libvritd-daemon – is running. To do so, execute the command.
$ sudo systemctl status libvirtd
You can enable it to start on boot by running:
$ sudo systemctl enable --now libvirtd
To check if the KVM modules are loaded, run the command:
$ lsmod | grep -i kvm
From the output, you can observe the presence of the kvm_intel module. This is the case for Intel processors. For AMD CPUs, you will get the kvm_intel module instead.
Step 3: Creating a Virtual Machine in Ubuntu
With KVM successfully installed, We are now going to create a virtual machine. There are 2 ways to go about this: You can create a virtual machine on the command-line or using the KVM virt-manager graphical interface.
Create a Virtual Machine via Command Line
The virt-install command-line tool is used for creating virtual machines on the terminal. A number of parameters are required when creating a virtual machine.
Here’s the full command I used when creating a virtual machine using a Deeping ISO image:
$ sudo virt-install --name=deepin-vm --os-variant=Debian10 --vcpu=2 --ram=2048 --graphics spice --location=/home/Downloads/deepin-20Beta-desktop-amd64.iso --network bridge:vibr0
--name option specifies the name of the virtual machine – deepin-vm The
--os-variant flag indicates the OS family or derivate of the VM. Since Deepin20 is a derivative of Debian, I have specified Debian 10 as the variant.
To get additional information about OS variants, run the command
$ osinfo-query os
--vcpu option indicates the CPU cores in this case 2 cores, the
--ram indicates the RAM capacity which is 2048MB. The
--location flag point to the absolute path of the ISO image and the
--network bridge specifies the adapter to be used by the virtual machine. Immediately after executing the command, the virtual machine will boot up and the installer will be launched ready for the installation of the virtual machine.
Create a Virtual Machine via virt-manager
The virt-manager utility allows users to create virtual machines using a GUI. To start off, head out to the terminal and run the command.
$ virt manager
The virtual machine manager window will pop open as shown.
Now click the monitor icon to start creating a virtual machine.
On the pop-up window, specify the location of your ISO image. In our case, the ISO image is located in the ‘Downloads’ folder in the home directory, so we’ll select the first option – Local Install Media ( ISO image or CDROM). Next, click the ‘Forward’ button to continue.
In the next step, browse to the ISO image on your system and directly below, specify the OS family that your image is based on.
Next, select the memory capacity and the number of CPUs that your virtual machine will be allocated, and click ‘Forward’.
And finally, in the last step, specify a name for your virtual machine and click on the ‘Finish’ button.
The creation of the virtual machine will take a few minutes upon which the installer of the OS you are installing will pop open.
At this point, you can proceed with the installation of the virtual machine.
And that’s how you go about installing KVM hypervisor on Ubuntu 20.04 LTS.