How to Install and Configure KVM on Debian 10 (Buster)

KVM stands for Kernel based Virtual Machine, KVM is a free and open source type 2 hypervisor which is installed on top of Linux like distributions. Once the KVM is installed on your system then it becomes the virtualization server which allows us to run multiple virtual machines at same time. KVM requires either Intel processor with VT-x (virtualization technology extension) or AMD processor with AMD-V (AMD64 Virtualization Extension).

In this article we will learn how to install and configure KVM on Debian 10 system, I am assuming Debian 10 is already installed on system / server.  Let’s jump into installation steps.

Step:1) Check Whether Virtualization Extension is enabled or not

Login to your Debian 10 system, open the terminal and run the below command,

[email protected]:~$  egrep -c '(vmx|svm)' /proc/cpuinfo
2
[email protected]:~$

If output of above command is more than zero then we can say Virtualization technology enabled on your system. If the output is zero then we must restart the system, go to bios settings and then enable VT-x (Virtualization Technology Extension) for Intel processor and AMD-V for AMD processor.

Run the below command to verify whether your processor is Intel / AMD and support hardware virtualization,

[email protected]:~$ grep -E --color '(vmx|svm)' /proc/cpuinfo

if the output contains vmx then you have a Intel based processor and svm confirms that it is AMD processor.

Step:2) Install QEMU-KVM & Libvirt packages along with virt-manager

kvm, qemu, libvirt and virt-manager packages are available in the default repositories of Debian 10, run the beneath apt command to install these packages,

[email protected]:~$ sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virtinst libvirt-daemon virt-manager -y

Once above packages are installed successfully then libvirtd service will be started automatically, run the below systemctl command to verify the status

[email protected]:~$ sudo systemctl status libvirtd.service

libvirtd-service-status-debian10

Step:3) Start default network and add vhost_net module

Run the below virsh command to list available networks for kvm VMs

[email protected]:~$ sudo virsh net-list --all
 Name      State      Autostart   Persistent
----------------------------------------------
 default   inactive   no          yes
[email protected]:~$

As we can see in above output, default network is inactive so to make it active and auto-restart across the reboot by running the following commands,

[email protected]:~$ sudo virsh net-start default
Network default started
[email protected]:~$ sudo virsh net-autostart default
Network default marked as autostarted
[email protected]:~$

If you want to offload the mechanism of “virtio-net” and want to improve the performance of KVM VMs then add “vhost_net” kernel module on your system using the beneath command,

[email protected]:~$ sudo modprobe vhost_net
[email protected]:~$ echo "vhost_net" | sudo  tee -a /etc/modules
vhost_net
[email protected]:~$
[email protected]:~$ lsmod | grep vhost
vhost_net              24576  0
vhost                  49152  1 vhost_net
tap                    28672  1 vhost_net
tun                    49152  2 vhost_net
[email protected]:~$

Note: If you want a normal user to use virsh commands then add that user to libvirt and libvirt-qemu group using the following commands

[email protected]:~$ sudo adduser pkumar libvirt
[email protected]:~$ sudo adduser pkumar libvirt-qemu

To refresh or reload group membership run the followings,

[email protected]:~$ newgrp libvirt
[email protected]:~$ newgrp libvirt-qemu

Step:4) Create Linux Bridge(br0) for KVM VMs

When we install KVM then it automatically creates a bridge with name “virbr0“, this is generally used for all  test environments but if you wish to access your KVM VMs over the network then create Linux bridge which will be attached to physical nic ( or lan card) of your system.

To create a bridge in Debian 10 , edit the network configuration file “/etc/network/interfaces” and add the following contents,

In my case ens33 is the physical nic and br0 is the Linux bridge and have assigned same ip address of ens33 to bridge br0. ( Also make sure to remove IP address from ens33). Replace the interface name, bridge name and IP details as per your setup.

[email protected]:~$ sudo vi /etc/network/interfaces
..............
#Primary network interface(ens33)
auto ens33
iface ens33 inet manual
#Configure bridge and give it a static ip
auto br0
iface br0 inet static
        address 192.168.29.150
        netmask 255.255.255.0
        network 192.168.29.1
        broadcast 192.168.29.255
        gateway 192.168.29.1
        bridge_ports ens33
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0
        dns-nameservers 8.8.8.8
...............

save and exit the file

To make the above network changes into the effect we have to reboot the system , so run the below reboot command,

[email protected]:~$ sudo reboot

Once the system is back online after reboot, we will see that bridge br0 will come up, run the following command to confirm,

[email protected]:~$ ip a s br0

linux-bridge-debian10

Step:5) Create Virtual Machines either via Virt-Manager (GUI) or virt-install (command line)

There are two ways to create virtual machines in KVM , first one is via virt-manager GUI tool and 2nd way is via command line using virt-install utility.

Creating Virtual Machines using Virt-Manager (GUI)

Access the virt-manager GUI tool from Desktop environment

search-virt-manager-debian10-desktop

Click on Virtual Machine Manager icon

Virt-Manager-GUI-Debian10

Click on monitor icon to create a new VM

rhl8-iso-kvm-gui-debian10

Browse and choose the ISO file and then click on forward, in my case i have already uploaded RHEL 8 iso on Debian 10 system, so i will be using the same iso for installing operating system,

In the next window, specify the RAM and CPU for the VM

RAM-CPU-VM-Virt-Manager-GUI-Debian10

click on Forward to proceed further,

disk-for-vm-virt-manager-debian10

Click on Forward and in next screen specify the VM name and its network

VM-Name-Network-Virt-Manager-Debain10

Click on Finish to proceed with operating system installation,

OS-Installation-KVM-VM-Debian10

Follow the screen instructions and complete the installation.

Creating VM via command line using virt-install

We can also create vms from command line using virt-install utility. Example is shown below,

[email protected]:~$ sudo virt-install --name ubuntu-vm --os-type linux --os-variant ubuntu18.04 --ram 1024 --vcpu 1 --disk path=/var/lib/libvirt/images/ubuntu-vm.qcow2,size=10 --graphics vnc,listen=0.0.0.0 --noautoconsole --hvm --cdrom /home/pkumar/ubuntu-18.04-live-server-amd64.iso --boot cdrom,hd
Starting install...
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[email protected]:~$

As we can see in above output, we can connect to console of ubuntu vm either via VNC console or virt-manager to finish the OS installation.

Run the following commands to find VNC display port for ubuntu-vm,

[email protected]:~$ sudo virsh list --all
 Id   Name        State
---------------------------
 3    ubuntu-vm   running
 4    rhel8-vm    running
[email protected]:~$
[email protected]:~$ sudo virsh vncdisplay ubuntu-vm
:0
[email protected]:~$

Now access remote desktop viewer on your Debian 10 system and connect to VM console using IP address of your system and vnc port as “0”, example is demonstrated below,

connect-vnc-console-kvm-vm-debian10

Click on Connect,

Console-VM-Remote-Desktop-Viewer-Debian10

Follow the screen instructions and complete Ubuntu 18.04 server Installations. That’s all from this article, please do share your feedback and comments in case these steps help you to setup KVM on your Debian 10 system.

5 Responses

  1. praveen says:

    This is very technical information on Debian 10 buster

  2. Seven Wang says:

    Thank for so detailed steps for KVM set up. 🙂

  3. Chici says:

    after
    sudo virsh net-start default
    i got this error:
    error: Cannot check dnsmasq binary /usr/sbin/dnsmasq: file or directory not found

    I canno instal dnsmasq. systemd-resolved ist blocking port 53. so what can i do?

  4. John McWade says:

    Thanks Pradeep! This is just what I was looking for.

  5. Satyendra Chandan says:

    I followed your step i only see LXC in virt-manager. I am using debian buster

    ‘https://ibb.co/FzLYXYM’

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest