KVM (Kernel-based Virtual Machine) is a virtualization solution built for Linux. When installed, it allows you to create a guest or virtual machines
Today we will learn how to install KVM on your system and how to configure virtual machines using ‘Virtual Machine Manager’ in just a few simple steps. Note that the following tutorial is tested on Kali Linux.
KVM installation
For having KVM installed on your Linux system, you should perform all the steps listed below:
Step 1: Pre-Installation Checks
Before diving into the installation, you must ensure that your CPU supports virtualization. For that, you must fetch cpuinfo by running the following command in the terminal.
egrep -c '(vmx|svm)' /proc/cpuinfo
If the output of the above command is greater than 1, it means your processor supports hardware virtualization. But you still need to make sure that your virtualization option is enabled in the BIOS setup. (search for VT-x, AMD-V or virtualization, etc)
Run the following command to ensure that your KVM acceleration can be used. Don’t fret if you see an output saying KVM acceleration cannot be used. You can still run your virtual machines, but it’ll be much slower without the KVM extensions.
kvm-ok
Step 2: Install Necessary Package
Run the following command to install the qemu-kvm, libvirt-clients, libvirt-daemon-system and bridge-utils packages which are essential packages to run KVM. libvirt-clients and libvirt-daemon-system provide libvirtd, which you need to administer qemu and KVM instances using libvirt. qemu-kvm is the backend of KVM.
sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils
You will be prompted for continuation, enter y or yes for completing the installation.
Step 3: Add Users to Groups
Now, you need to make sure that your user is added to the libvirt and KVM user group. Run the following commands to add your specific username to respective groups.
sudo adduser username libvirt sudo adduser username kvm
Step 4: Install Virtual Machine Manager
The virt-manager application is a GUI tool to manage virtual machines through libvirt. It presents a summary view of running domains, their live performance, and resource utilization statistics. Wizard enables the creation of new domains. It also configures and adjusts the domain’s resource allocation and virtual hardware. This tool can be installed using the following command.
sudo apt install virt-manager
You will be prompted for continuation, enter y or yes for completing the installation.
You can now open the Virtual Machine Manager through the command line by ‘virt-manager’ command or go to activities and search for virt-manager and click open.
Virtual Machine Configuration using virt-manager
Upon opening, Your Virtual Machine Manager will be connected to QEMU/KVM.
You can start a new virtual machine setup by either opening the file tab and choosing ‘New Virtual Machine’ from the options or by clicking the plus icon on the left side of the 2nd row.
You will be prompted to select an installation medium, choose from any given option. If you have already downloaded the iso file of the desired virtual system, you can select importing that disk image and continue by clicking on ‘Forward’. If you do not have the downloaded iso file then you can proceed with network install or you could use the CD/DVD option.
Now, You will be prompted to browse or enter the path of your disk image. When you enter the path, the wizard will most probably detect the given operating system. If it doesn’t happen, you will be required to input/select the operating system from the given list. Press ‘Forward’ to continue.
In the next step, you can customize the memory and CPU settings for the virtual machine. CPU indicates how many cores the new machine can utilize and memory indicates the memory that the new machine can allocate. Press ‘Forward’ to continue.
In the last step, you can customize the name and network of your virtual machine. For Network customization click on network selection and choose either the default setting ‘NAT’ which will prompt the creation of a virtual network or you can choose to bridge your original/host machine network Ethernet or WLAN. Press ‘Finish’ to continue.
As soon as you press ‘Finish’, the virtual machine will start running and finally start installing the system from the image disk that you provided earlier.
Complete installation of your system and enjoy your isolated Virtual machine!
Conclusion
In this article, we briefly explained the KVM virtualization, necessary prerequisites, important packages, and user permissions needed for smooth installation and use of KVM. We also briefly explained how Virt-Manager can provide a fast and easy configuration of virtual machines.