Kernel-based Virtual Machine or KVM is a freely available and open-source kernel-based Virtual machine that gives us a complete Linux virtualization solution for x86 hardware. The main virtualization infrastructure is provided by a loadable kernel module and the Virtual machines have their own virtualized hardware, such as a disc, graphics adapter, network card, and so on. You can process many virtual machines using KVM as it gives a good, high-performance virtualization solution for everyday productive applications.
This post will explain the procedure for KVM installation and how to use it on Ubuntu 22.04.
Install KVM on Ubuntu 22.04
To install KVM on Ubuntu 22.04, follow the below-given instructions.
Step 1: Update system packages
The first thing is to update Ubuntu packages by using the command:
$ sudo apt update
Step 2: Check Virtualization status
Secondly, check whether our CPU can support virtualization or not. To do so, execute the given command. If our output is equivalent to zero, then we have to enable Virtualization:
$ egrep -c '(vmx|svm)' /proc/cpuinfo
Step 3: CPU checker installation
In the next step, install the “CPU-checker” package on Ubuntu 22.04 using the below-given command:
$ sudo apt install -y CPU-checker
Step 4: Check KVM virtualization status
To verify the status of the KVM virtualization, run the following command:
Step 5: KVM installation
For the KVM installation, execute the given command:
$ sudo apt install -y qemu-kvm virt-manager libvirt-daemon-system virtinst libvirt-clients bridge-utils
The above-given command will install the following packages:
- “qemu-kvm” for hardware emulation
- “virt manager” to manage virtual devices
- “libvirt-daemon-system” to get configuration files
Step 6: Enable and start libvirtd
In this step, enable the virtual daemon component “libvirtd” utilize the below-given command:
$ sudo systemctl enable --now libvirtd
Start thelibrary of virtual daemon:
$ sudo systemctl start libvirtd
Step 7: Check Virtualization daemon status
Run below-given command to check the status of the Virtualization demon library:
$ sudo systemctl status libvirtd
Now add the current user in KVM and libvirt group that will create and manage Virtual Machines:
$ sudo usermod -aG kvm $USER $ sudo usermod -aG libvirt $USER
As you can see, we have completed the KVM installation. Now let’s create a Virtual Machine on Ubuntu 22.04 with the help of KVM.
Creating Virtual Machine on Ubuntu 22.04 using KVM
To create a Virtual Machine on Ubuntu 22.04, we must go through the procedure mentioned below.
First, search the “Virtual Machine Manager” in the “Activities” menu and open it from the provided result:
Next, click on the “Computer” icon to create a new Virtual Machine:
New VM wizard will appear on the screen, asking to select the method to install the operating system. Select the first option, “Local install media” and click on the “Forward” button as shown below:
After clicking on the “Forward” button, a “Local ISO media volume” wizard will appear. Click on the “Browse local” button to move forward:
Now open up the “Downloads” folder to access the downloaded ISO file:
Now select the ISO file saved in your system as in our case, we will use the “debian 11.3.0” ISO file. But if you don’t find an ISO file in your system, download it from the internet:
Click on the “Forward” button to create a new Virtual Machine:
In the new Virtual Machine, allocate memory and number of processors according to your preference:
Allocate Disk space to the new Virtual Machine and move forward by clicking on the “Forward” button:
Click on the “Finish” button to complete the process and a new virtual machine will be created:
As you can see, we have successfully created our new Virtual Machine. Now set users and passwords on the created virtual machine as shown below:
After adding your Full name, provide a “Username”:
Select the password of your own choice and recheck it for confirmation and press the “Enter” key:
Choose Virtual Machine disk partitioning from the “Partition disk” window. Going with the default option would be better; however, you can select it according to your preference:
Now directly go with the option of “Finish partitioning and write changes to disk” as mentioned in the below image:
If you want any extra installation, select the “Yes” radiobutton; otherwise, go with the default selected option “No”:
The system will reboot and start the new virtual machine:
The new Debian 11 Virtual Machine is running effectively on Ubuntu 22.04.
Uninstalling KVM on Ubuntu 22.04
In Ubuntu 22.04 terminal, execute the following command to uninstall KVM and its related packages:
$ sudo apt remove --purge qemu-kvm virt-manager libvirt-daemon-system virtinst libvirt-clients bridge-utils
We have completely demonstrated the procedure to install, uninstall KVM and also how to create a new Virtual Machine on Ubuntu 22.04.
On Ubuntu 22.04 to install KVM, you must first enable virtualization and install a CPU checker. Then install KVM and other dependencies such as virtual manager, library virtualization daemon component using the “$ sudo apt install -y qemu-kvm virt-manager libvirt-daemon-system virtinst libvirt-clients bridge-utils” command. In the above post, we have completely elaborated the procedure for the KVM installation, creation of a new Virtual Machine, and how to uninstall it on Ubuntu 22.04.