KVM

How To Install KVM Hypervisor on Debian 12/11/10

Install KVM / QEMU on Debian

Follow the steps below to install KVM Virtualization on Debian Linux system. All KVM packages for Debian are available on upstream repositories. The apt package manager is used for all packages installation.

Original content from computingforgeeks.com - post 21285
sudo apt update
sudo apt -y install qemu-kvm libvirt-daemon  bridge-utils virtinst libvirt-daemon-system

Load and enable the vhost_net module.

$ sudo modprobe vhost_net 
$ lsmod | grep vhost
vhost_net              24576  0
tun                    49152  1 vhost_net
vhost                  49152  1 vhost_net
tap                    28672  1 vhost_net

$ echo vhost_net | sudo tee -a /etc/modules 

Let’s also install useful Virtual Machine management tools.

sudo apt -y install vim libguestfs-tools libosinfo-bin  qemu-system virt-manager

This will give you tools similar to Linux ls, cat, top command for use with Virtual Machines.

Create KVM Bridge on Debian (Optional)

For your Virtual Machines to talk to the outside world, a Linux bridge is required. Installation of KVM on Debian creates a Linux bridge called virbr0. This can be used for all test environments.

But if you want to your VMs to be accessible over the network, you’ll need to create a bridge on physical network interface attached to your machine.

Create one on your Debian server/workstation like below.

sudo vim /etc/network/interfaces

My bridge configuration uses a network interface (ens33) to create a Linux bridge called br1. Replace the values provided with yours.

# Primary network interface
auto eno1
iface eno1 inet manual

# Bridge definitions
auto br0
iface br0 inet static
bridge_ports eno1
bridge_stp off
address 192.168.1.2
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 172.20.30.252 172.20.30.251

Reboot your machine for the network configuration changes to take effect.

sudo reboot

Confirm ip network details.

$ ip ad
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 1c:69:7a:61:da:e9 brd ff:ff:ff:ff:ff:ff
    altname enp0s31f6
3: wlp0s20f3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 08:71:90:27:5b:be brd ff:ff:ff:ff:ff:ff
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 26:8f:ab:9f:8b:85 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.2/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::248f:abff:fe9f:8b85/64 scope link
       valid_lft forever preferred_lft forever

Create Virtual Machine on KVM

You can use Virtual Machine Manager GUI to create an instance on KVM or via virt-install command line tool.

For virt-install, installation snippet is shared below.

sudo virt-install \
--name deb12 \
--ram 2048 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/deb12-vm.qcow2,size=20 \
--os-type linux \
--os-variant debian12 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location 'http://ftp.debian.org/debian/dists/bookworm/main/installer-amd64/' \
--extra-args 'console=ttyS0,115200n8 serial'

This will download kernel and initrd image before starting installation.

deb installer kvm

The installation process will start shortly. Follow installation prompts for Debian system on KVM.

deb installer kvm 02
deb installer kvm 03

Using Cockpit Web Console

Cockpit enables you to manage your instances and Podman containers from a web console. Install it by running the following commands:

sudo apt install cockpit cockpit-machines cockpit-podman

Then start and enable the service.

sudo systemctl enable cockpit.socket && sudo systemctl start cockpit.socket

Confirm service status:

$ systemctl status cockpit.socket
 cockpit.socket - Cockpit Web Service Socket
     Loaded: loaded (/lib/systemd/system/cockpit.socket; enabled; preset: enabled)
     Active: active (running) since Wed 2024-07-23 05:48:48 EDT; 11min ago
   Triggers:  cockpit.service
       Docs: man:cockpit-ws(8)
     Listen: [::]:9090 (Stream)
      Tasks: 0 (limit: 28431)
     Memory: 84.0K
        CPU: 9ms
     CGroup: /system.slice/cockpit.socket

July 23 05:48:48 osp01.home.cloudlabske.io systemd[1]: Starting cockpit.socket - Cockpit Web Service Socket...
July 23 05:48:48 osp01.home.cloudlabske.io systemd[1]: Listening on cockpit.socket - Cockpit Web Service Socket.

Access cockpit web interface on https://server-ip-address:9090

cockpit debian

We also have a guide on Virtual Machine’s installation on KVM with Terraform.

Also check related KVM articles:

Related Articles

Debian Install GNS3 Network Simulator on Debian 13/12 Containers Install CRI-O Container Runtime on Debian 12/11/10 Virtualization VMware vSphere and vCenter Central Logs Management with Rsyslog Automation Install Jenkins on Ubuntu 24.04 / Debian 13 with Nginx Reverse Proxy

1 thought on “How To Install KVM Hypervisor on Debian 12/11/10”

  1. Would’ve been nice to see some more explanation about the options given in the virt-install command, or at least a pointer to a reference. I can well imagine people don’t all want to use your preferences.

    Reply

Leave a Comment

Press ESC to close