Running KVM on Debian Buster

Home, Bangkok, Thailand, 2020-02-08

#infrastructure

 
Photo by Markus Spiske

I’ve been wanting to move from ESXi to KVM for a while for a few reasons and finally this weekend I’ve started trialing the migration process.

My homelab is mostly Debian and I’m using Debian Buster (10.2.0) for the hypervisor. The docs for KVM are ok and there are plenty of setup posts around already (the most useful of which I’ve linked below), but even so I found a few challenges mostly around the network bridge which I’ve also explained below.

Now that I have a stable KVM host, the next step will be migrating VMWare virtual machines onto it which I’ll cover in a subsequent post.

OK so here’s a super short version of the procedure to install KVM on Debian Buster that worked for me in February 2020:

OS Setup

  • Grab the netinst ISO from the Debian downloads page
  • Use Balena Etcher to make a bootable USB flash drive from the ISO
  • Boot the server from the USB drive and do a minimal install of Debian - selecting only SSH Server in the last tasksel window
  • Install KVM and required dependencies (this is taken directly from this post):
sudo apt install -y --no-install-recommends qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils libguestfs-tools genisoimage virtinst libosinfo-bin

Create Bridge Network

To create the bridge we just need to declare it in /etc/network/interfaces as follows:

auto br0
iface br0 inet dhcp
  bridge_ports enp1s0

The bridge_ports directive adds the default NIC which is /dev/enp1s0 to the bridge. Later when VM’s are launched they will be dynamically connected to this bridge.

We also ensure that enp1s0 does not separately have a static IP address bound or obtain one from DHCP:

auto enp1s0
iface enp1s0 inet manual

My router’s DHCP server has a static assignment for 10.80.2.40 for the physical MAC address of my new KVM server. Therefore when networking is restart or the host is rebooted, it will obtain that IP address and be available on the network. Even though the bridge enp1s0 has not been assigned an address, networking still works as normal because the host can connect through the bridge.

References:

  • Bridging Network Connections - https://wiki.debian.org/BridgeNetworkConnections
  • How to enable DHCP for “br0” device for qemu? - https://serverfault.com/questions/811295/how-to-enable-dhcp-for-br0-device-for-qemu
  • Why assign MAC and IP addresses on Bridge interface - https://unix.stackexchange.com/questions/319979/why-assign-mac-and-ip-addresses-on-bridge-interface

VM Creation

You can now create VM’s using the command-line or the VMM GUI and set them to use the network bridge so that they can communicate directly with the outside world.