How to Install and Configure KVM on Debian 11 Bullseye Linux

KVM”, the abbreviation for “Kernel Virtual Machine” is the hypervisor of the Linux kernel. It is quite popular and used in enterprises for easily performing the virtualization of operating systems. Here in this tutorial, we learn the steps and commands to install and enable KVM Hypervisor on Debian 10 or 11 Bullseye Server or Desktop Linux.

Since 2007, KVM is an official kernel component, however, as compared to Xen,  the other open-source hypervisor, the history of KVM is less changeful and has only been steeply upward from the start. KVM is also the preferred hypervisor in OpenStack and is therefore widely used in the cloud.

What exactly is KVM?

KVM is primarily not a bare-metal hypervisor but is based on Linux. We can install using a few commands on any Linux operating system to convert and use it as a virtualization server. Thus, KVM is formally a type 2 hypervisor, which simply means that it runs in the non-privileged ring 3. However, for years the experts have been conducting a now historical discussion about whether KVM is a Type 1 hypervisor after all.

We can use it to run multiple Virtual machines together on the same machine, however, the host system must support and has an enabled Intel VT-x (virtualization technology extension) or AMD-V (AMD64 Virtualization Extension) in its respective process.

What do we need to follow this tutorial:

• A machine supporting virtualization
• Debian 11 Linux
• A user with sudo rights
• Internet connection

Also, KnowInstall VirtualBox in Debian 11 Bullseye

 

Steps to install and enable KVM on Debian 11 Bullseye

The below-given commands will work for both Debian 10 Buster and Debian 11 Bullseye to set up Qemu KVM and run a virtual machine on it.

1. Confirm Virtualization support

As in the beginning, I said, we need a system with either Intel or AMD process having enabled Virtualization extension. Hence, to confirm that, on your Debian 11 open the command terminal and run the given commands:

egrep -c '(vmx|svm)' /proc/cpuinfo
grep -E --color '(vmx|svm)' /proc/cpuinfo

As you run the above commands to confirm virtualization is enabled or not, the output will be more than zero. And if not then first you have to reboot your system and enter system BIOS. Enable the virtualization and then boot to OS where again the run the above command to confirm the same.

The first command output will be greater than zero, this means it could be 1, 2, 6, or 8. Hence, the system supports virtualization.

Using the second command you will get information about your CPU- whether it is Intel or AMD. If the red color output text is VMX then it is Intel whereas SVM means AMD.

Output:

Confirm virtualization is supported on Debian 11

 

2. Run the system update

If you already have run the update command then skip this step, otherwise run it once before moving further to update the installed packages and rebuild the repository cache.

sudo apt update

 

3. Command to Install QEMU-KVM & Libvirt on Debian 11 Bullseye

Next is the key command of this tutorial which will download and install all the required for the installation of Qemu, KVM hypervisor, and Libvirt on Debian 11 Linux.

sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon

 

4. Virt-Manager GUI for KVM

Those who are using Graphical Debian 11 Desktop can also install Virt-Manager, a graphical user interface developed by RedHat to create, manage and run virtual machines using KVM but graphically.

sudo apt install virt-manager -y

 

5. Make Network active and auto-restart

To list the available network to use in KVM virtual machines, run the following command:

sudo virsh net-list --all

However, in the output, you will see the default network is not active and also not set to start automatically with a system reboot. Therefore, to make it active and autostart run the following commands:

sudo virsh net-start default
sudo virsh net-autostart default

You can check the network again…

Set KVM network Default

 

6. Add “vhost_net”

To improve the performance of network data transfer and reduce the load of virtio-net, we can add vhost_net” kernel module in our Debian 11 Linux using the below-given command:

vhost-net is the backend (host side) whereas virtio-net (guest side) is the frontend running in the guest kernel space. To know more about them see: Vhost-net & Virtio-networking

sudo modprobe vhost_net

To check it has been enabled: 

lsmod | grep vhost

 

—————————-This step is not Necessary Until you want it-———————————–

7. Create Bridge Network (optional)

Although the KVM comes with a bridge network interface called “virbr0″ setup out of the box, however, that won’t let us access the KVM virtual machine out of the host PC using some other computer in the network because of the IP range assigned by it. Therefore, we will create our own full-bridge interface over the physical nic of the host system that will have the IP range of our network.

Find the physical network interface attached to your host system that you want to use for the bridge.

ip a

You will see all the attached network interfaces on your host machine. Now, note down the one which you want to use for the Bridge network.

For example, here we have enps03 and the IP address is 192.168.0.109. Hence, the range is between 192.168.0.1-192.168.0.255

Find Physical network interface

Now, Edit your Debian 11 Network interface file:

sudo nano /etc/network/interfaces

Add the following lines:

Note: Change the yellow values as per your network…

#Configure bridge and give it a static ip
auto br0
iface br0 inet static
        address 192.168.0.100
        netmask 255.255.255.0
        network 192.168.0.1
        broadcast 192.168.0.255
        gateway 192.168.0.1
        bridge_ports enp0s3
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0
        dns-nameservers 8.8.8.8 4.4.2.2

Bridge Static Debian 11

Save the file by pressing Ctrl+O, hit the Enter key, and exit using Ctrl+X.

or

Note: If you want the bridge to get an IP address using DHCP:

Then instead of the above settings use this one:

## DHCP ip config file for br0 ##
auto br0
 
# Bridge setup
 iface br0 inet dhcp
    bridge_ports enp0s3

DHCP Settings for Bridge in Debian

 

Restart the Network manager to apply the changes.

sudo systemctl restart networking.service
or
sudo /etc/init.d/networking restart

Check the Ip-address

ip a

this time you will see your newly created br0 bridge interface along with others.

———————————————————————————————————————

 

8. Create Virtual Machines using Virt-Manager GUI

Those who want to use the Virt command line to create virtual machines and run using KVM just follow the link.

Whereas if you are using GUI Debian 11 Desktop can use the Virt-Manager. To give an idea here is a glimpse…

Run Virt-Manager

Go to the Application launcher and search for “Virtual machine manager”  (VVM) and run it. Before it opens, the system will ask to provide the root password. This will allow it to create and manage virtual machines.

Create Virtual Machines:

Click on the PC icon to create a new virtual machine on Virt-Manager using KVM.

Locate ISO Media Volume

Click on the Browse button and then locate the ISO file you want to use for installing an operating system on your virtual machine as guest OS.

Create new virtual machine on KVM Virt Manager

 

After that uncheck the box is given for “Automatically detect from the installation media/source” and then click on the Forward button.

Select ISO file KVM Virt Manager

Choose Memory and CPU Settings

Set the amount of virtual memory you want to assign to VM and then the number of CPU cores.

Assign RAM virtual memory

 

Create Qemu Virtual Disk Image

To install VM guest OS, we need some storage space and for that, we have to create a disk image file. Just enter the amount of hard disk space you want to assign and move forward.

Create Virtual Disk Qemu image

 

Network

Name your Virtual machine, here. Also, by default, the Virt-manager will use the NAT, however, you can select Bridge interface either the default one i.e vibr0, or the one you have created. If you don’t know about these settings let the default NAT be selected.

Virt Manager Configure NAT network

 

Qemu KVM Virtual Machine on Debian 11 Bullseye

Finally, you will have a booted virtual machine that can be controlled just like any physical computer using a keyboard and mouse.

Install KVM virtual machine Debian 11 Bullseye

 

Other Articles:

How to install VirtualBox hypervisor on Rocky Linux 8
Install Qemu/KVM and Virt-Manager GUI on Ubuntu
How to install and use Virt-Manager on Windows 10
Install Clouds Windows 10 VM on Ubuntu with SNAP command

 

 

 

3 thoughts on “How to Install and Configure KVM on Debian 11 Bullseye Linux”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.