KVM refers to the Kernel-based Virtual Machine which helps to run multiple Linux or window-based isolated guests along with their own OS and virtual dedicated hardware. To run KVM, we need processors with hardware virtualization extensions, such as AMD-V or Intel-VT. It was originally designed for x86 processors, so having x86 processors is quite preferable.
This article will guide you to install and configure KVM on Ubuntu 20.04, and I’ll show you how to use Virtmanager to create a virtual machine.
Inspect Virtualization Compatibility
Before jumping into the process, we need to perform some compatibility tests to run KVM. Execute the command given below to test the CPU compatibility.
$ egrep -c '(vmx|svm)' /proc/cpuinfo
The above command will check if the hardware virtualization extensions, such as AMD-V or Intel-VT, are available or not. Once the command is executed, you will get either 0 or more. If you get more than 0, your system supports virtualization.
Now, execute the following command to check KVM acceleration support.
$ sudo kvm-ok
If the kvm-ok command is not present, execute the following apt command to install it.
$ sudo apt install cpu-checker
Then, again execute the kvm-ok command to KVM support.
Installing KVM on Ubuntu 20.04
Once the compatibility test is completed and the response is positive, you can install the KVM and its related utility package. To run the installation execute the following command.
$ sudo apt update
$ sudo apt install -y qemu-kvm qemu libvirt-clients libvirt-daemon virt-manager bridge-utils
In the above apt command, the qemu-kvm package is the actual package for KVM, the qemu package helps in hardware virtualization, the libvirt-clients is used to manage and access the virtual machine where the libvirtd-daemon is the virtualization daemon, the virt-manager manages virtual machines through a graphical user interface, and lastly, the permit other hosts to access a virtual machine through bridge connection.
Now, once the installation is completed check if the libvirtd-daemon is running so, check the status using the systemctl command.
$ sudo systemctl status libvirtd
You can verify if KVM modules are loaded using the following command.
$ lsmod | grep -i kvm
When installing a KVM network bridge called virbr0 is created automatically. This network setup is maybe suitable inside the local network, but guests cannot be accessed from outside its local network. You need to configure manually to access from outside the local network boundaries. Execute the following command to check the network bridge of your local system
$ brctl show
Understanding and Using KVM
You can open the KVM using the virt-manager utility or GUI-based Application manager. Now, execute the following command to kick on the virtual machine.
$ sudo virt-manager
You can see the following user interface of the KVM once the command is executed.
Now, it is possible to add a new virtual machine by clicking on the top left corner monitor button. Then, you will see the pop dialog to choose the method to install the operating system. Choose the method you prefer and follow up the procedure to set up a virtual machine.
Once you finish up creating the virtual machine, you can see the following type of virtual machine listed from where you can power up the virtual machine.
In KVM you can manage and control virtual machine hardware configuration such as memory, disk space, etc, to the max your actual system has integrated. This is the key feature of the KVM, which lets you configure virtual machine hardware according to your need. To configure, simply double-click on the virtual machine or open the virtual machine, then click on the blue icon button. As you can see, there are several hardware component configurations from where you can reconfigure your VM hardware.
The virtual machine helps set up multiple systems with separate OSs, which can use a different distro of the Operating system virtually. After reading this article, you might have a clear concept of how we can install and set up the KVM.