How to Install KVM and QEMU on Debian 12 Bookworm

This article provides a step-by-step guide on how to install KVM and QEMU on a Debian 12 Bookworm system.

Virtualization has become a critical part of modern computing, enabling users to run multiple operating systems simultaneously on a single physical machine. Among the leading open-source virtualization technologies, KVM (Kernel-based Virtual Machine) and QEMU (Quick Emulator) stand out for their performance, flexibility, and integration with Linux systems.

If you’re running Debian 12 “Bookworm”, you’re in luck. Debian offers solid support for KVM and QEMU, making it relatively easy to set up a virtualized environment for development, testing, or even production workloads.

This guide will walk you through every step required to install and configure KVM and QEMU on a Debian 12 system.


What are KVM and QEMU?

Before diving into the installation process, let’s briefly clarify what these tools are:

  • KVM (Kernel-based Virtual Machine) is a Linux kernel module that turns your Linux system into a type-1 (bare-metal) hypervisor. It provides the core virtualization support using hardware extensions like Intel VT-x or AMD-V.

  • QEMU (Quick Emulator) is a generic and open-source emulator that performs hardware virtualization. When used with KVM, it can run VMs nearly at native speeds by taking advantage of hardware acceleration.

Together, KVM and QEMU allow you to create and manage virtual machines that behave like real physical systems.


System Requirements

Before installing KVM and QEMU, ensure your system meets the following requirements:

  • Debian 12 Bookworm installed and updated
  • 64-bit processor with virtualization extensions (Intel VT-x or AMD-V)
  • Sufficient RAM and disk space for hosting VMs

Step 1: Verify Virtualization Support

To ensure that your CPU supports hardware virtualization, run the following command:

egrep -c '(vmx|svm)' /proc/cpuinfo
  • If the output is 1 or greater, your CPU supports virtualization.
  • If it returns 0, virtualization is either not supported or not enabled in the BIOS/UEFI.

You can also confirm using lscpu:

lscpu | grep Virtualization

Look for VT-x (Intel) or AMD-V (AMD) in the output.

If virtualization is disabled, you’ll need to enable it from your system’s BIOS/UEFI settings.


Step 2: Install KVM and QEMU Packages

Debian provides all necessary packages in its default repositories. Update your system and install the required tools with the following commands:

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

Package Breakdown

  • qemu-kvm: Provides the KVM emulator binaries.
  • libvirt-daemon-system: Manages libvirt services on the system.
  • libvirt-clients: Provides command-line tools to manage VMs.
  • bridge-utils: For configuring network bridging (useful for VM networking).
  • virtinst: Includes virt-install, a command-line tool to create VMs.

These packages install the KVM kernel modules and necessary libraries to begin using virtualization on your Debian system.


Step 3: Add User to libvirt Group

To manage virtual machines without using sudo, add your user to the libvirt group:

sudo usermod -aG libvirt $(whoami)

Then, log out and log back in (or reboot) to apply group changes.

You can verify your group membership using:

groups

You should see libvirt listed in the output.


Step 4: Enable and Start Required Services

Make sure the libvirt service is enabled and running:

sudo systemctl enable --now libvirtd

Check the status:

sudo systemctl status libvirtd

You should see something like:

libvirtd.service - Virtualization daemon
   Active: active (running)

If it’s not running, inspect the logs with:

journalctl -xeu libvirtd

Step 5: Verify the Installation

To check if KVM is successfully installed and accessible:

kvm-ok

If you see:

KVM acceleration can be used

Then everything is working correctly.

If kvm-ok is not found, install the cpu-checker package:

sudo apt install cpu-checker

Also, check that /dev/kvm exists:

ls -l /dev/kvm

If the file exists and has the correct permissions, KVM is ready.

To list the virtualization capabilities:

virsh list --all

An empty list will appear initially, which is normal.


Step 6: Install a Virtual Machine Manager (Optional GUI)

If you prefer a graphical interface to manage virtual machines, install Virt-Manager:

sudo apt install virt-manager

Once installed, you can launch it from your application menu or by typing:

virt-manager

Virt-Manager provides an intuitive GUI to create, configure, and monitor VMs. It’s a great tool for those who prefer point-and-click management over CLI.


Creating Your First VM

You can create a VM either using Virt-Manager or via command line using virt-install.

Using virt-install

Here’s an example to create a VM from an ISO image:

virt-install \
  --name debian-vm \
  --memory 2048 \
  --vcpus 2 \
  --disk size=20 \
  --cdrom /path/to/debian-12.iso \
  --os-variant debian12 \
  --network network=default \
  --graphics spice

This command will start the VM installation process in a virtual display window.

Using Virt-Manager

  1. Launch Virt-Manager.
  2. Click “Create a new virtual machine”.
  3. Choose the installation method (e.g., ISO image).
  4. Set RAM, CPU, disk, and other settings.
  5. Begin the installation.

Final Thoughts

Installing KVM and QEMU on Debian 12 Bookworm is a straightforward process, and once set up, the system becomes a powerful virtualization host. Whether you’re running VMs for testing software, learning networking, or managing development environments, this setup is both lightweight and efficient.

Key benefits of KVM/QEMU on Debian include:

  • Native performance with hardware acceleration.
  • Seamless integration with tools like libvirt and virt-manager.
  • Strong community support and frequent security updates.
  • Flexibility to run almost any operating system inside a VM.

For advanced users, you can explore topics such as:

  • Setting up bridged networking for external VM access.
  • Creating snapshots and VM cloning.
  • Automating VM deployments with cloud-init or Ansible.
  • Managing VMs remotely using virsh and SSH.

With this guide, you now have a solid foundation to explore everything virtualization has to offer on Debian 12.