Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Set Up Debian 10 KVM Server

This tutorial will show you how to set your Debian 9 server up as a KVM host, rather than for setting up KVM on Ubuntu 16.04.

Version Info

  • libvirtd (libvirt) 5.0.0
  • QEMU emulator version 3.1.0 (Debian 1:3.1+dfsg-8+deb10u5)

Steps

Run the command below to check if system supports KVM. You should see a number greater than 0.

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

Install most of the necessary packages.

sudo apt-get install \
  --no-install-recommends \
  qemu-kvm qemu-utils libvirt-clients libvirt-daemon-system virtinst

Because I am likely to run a bridge from the host, I also make sure to install the bridge-utils package

sudo apt-get install bridge-utils -y

Virtinst Package

We now wish to install the virtinst package so that we can install guests with the virtinstall command.
Unfortunately, this comes with the recommendation of the virt-viewer package which would require a lot of the GUI based packages. Thus, depending on whether you are runnning a headless or a Desktop KVM host, pick one of the following two options:

Headless KVM Hosts:

sudo apt-get install --no-install-recommends virtinst -y

# Now install its recommendations, except virt-viewer
sudo apt-get install \
  libosinfo-l10n python-gi-cairo python-setuptools python-cryptography \
  python-idna python-openssl python-socks python-ntlm \
  python-cryptography python-idna python-ipaddress python-openssl -y

Desktop KVM Hosts: If you'r KVM host already has the GUI, then you probably want to just go ahead and install all the recommendations, which will include virt-viewer.

sudo apt-get install virtinst -y

Add User to Libvirt

Add your user to the libvirtd group so that you can run management commands without sudo.

sudo adduser $USER libvirt

Export Qemu Path

Without this, you will always end up having to run your virsh commands with sudo in order to see/manage your guests.

echo 'export LIBVIRT_DEFAULT_URI=qemu:///system' >> $HOME/.bashrc

Test

Check that everything is fine by running:

sudo virsh -c qemu:///system list

You should see the following output:

 Id    Name                           State
----------------------------------------------------

Setting Up Default Network

I'm pretty sure Debian 10 wont automatically install, or perhaps not autostart a default network. You may wish to create one.

Last updated: 10th July 2023
First published: 8th May 2020