The Linux Virtualization Stack (KVM, QEMU, libvirt)
The Linux virtualization stack divides responsibilities across several specialized architectural layers, cleanly separating low-level hardware virtualization from userspace device emulation and high-level management tools.
+-------------------------------------------------------------+
| User Interfaces: virt-manager (GUI) | virsh | virt-install |
+-------------------------------------------------------------+
| (API calls)
+-------------------------------------------------------------+
| libvirt (libvirtd daemon, XML definitions, networks, pools) |
+-------------------------------------------------------------+
|
+-------------------------------------------------------------+
| QEMU (Userspace device emulation: virtio disks, NICs, buses)|
+-------------------------------------------------------------+
|
+-------------------------------------------------------------+
| KVM (Linux Kernel Module: hardware-accelerated CPU/Memory) |
+-------------------------------------------------------------+
The Virtualization Toolchain
1. KVM (Kernel-based Virtual Machine)
- Role: The foundational hypervisor embedded directly inside the Linux kernel (
kvm.ko,kvm_intel.ko,kvm_amd.ko). - Function: Exposes
/dev/kvmto userspace. It allows an emulator (like QEMU) to execute guest virtual CPU (vCPU) instructions directly on the host processor using hardware virtualization extensions (Intel VT-x or AMD-V). - Performance: Virtual machine compute runs near bare-metal speed instead of relying on slow software simulation.
2. QEMU (Quick Emulator)
- Role: The userspace hardware emulator.
- Function: While KVM handles CPU and memory virtualization, QEMU provides the guest operating system with virtual peripherals and system devices:
- VirtIO paravirtualized devices: High-throughput paravirtualized network cards (
virtio-net) and block controllers (virtio-blk,virtio-scsi). - PCI/PCIe root complexes, USB controllers, Real-Time Clocks (RTC), and display adapters (SPICE, VNC).
- VirtIO paravirtualized devices: High-throughput paravirtualized network cards (
- Interfaces directly with KVM via standard
ioctl()calls on/dev/kvm.
3. libvirt (libvirtd / modular daemons)
- Role: The management and abstraction layer.
- Function: Invoking raw QEMU binaries directly requires brittle, hundred-character shell commands with dozens of low-level flags.
libvirtprovides:- Declarative XML configuration schemas for domain (VM) definitions.
- Virtual network bridge management (
virbr0, NAT routing, isolated host-only subnets, DNS viadnsmasq). - Storage pool abstraction (directory pools, LVM volume groups, ZFS pools, iSCSI targets).
- Consistent APIs across different hypervisors (KVM, Xen, LXC).
Management & CLI Utilities
virt-install (The Provisioner)
A specialized CLI tool designed exclusively to define, construct, and bootstrap new virtual machines without manually writing raw XML:
# Provision a VM using a cloud image and cloud-init
virt-install \
--name k8s-node-01 \
--memory 4096 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/k8s-node-01.qcow2,format=qcow2,bus=virtio \
--os-variant ubuntu22.04 \
--network network=default,model=virtio \
--cloud-init user-data=/path/to/user-data.yaml \
--import \
--noautoconsole
virsh (The Lifecycle CLI)
The administrative command-line interface for daily guest lifecycle and hardware inspection:
# Inspect all running and stopped guests
virsh list --all
# Domain power controls
virsh start <vm-name>
virsh shutdown <vm-name>
virsh reboot <vm-name>
# Guest network interface lookup
virsh domifaddr <vm-name>
# Snapshot management
virsh snapshot-create-as --domain <vm-name> --name "pre-upgrade-snap"
virsh snapshot-list <vm-name>
# Complete teardown and disk erasure
virsh destroy <vm-name>
virsh undefine <vm-name> --remove-all-storage
virt-manager (The Desktop GUI)
A rich graphical desktop application built on top of libvirt. It provides a graphical hardware configuration interface, live virtual display consoles (SPICE/VNC), performance graphs (CPU, Memory, Disk I/O, Network traffic), and removable media mounting.
Architectural Comparison
| Component | Layer | Primary Responsibility |
|---|---|---|
| KVM | Kernel Module | Hardware CPU/Memory execution via VT-x / AMD-V |
| QEMU | Userspace | Emulates I/O hardware, buses, and VirtIO devices |
| libvirt | System Daemon | Declarative XML state, network bridges, storage pools |
| virt-install | CLI Utility | High-level declarative VM creation and bootstrapper |
| virsh | CLI Utility | Daily lifecycle, state inspection, snapshot management |
| virt-manager | Desktop GUI | Graphical console and live telemetry monitoring |
See Cloud-Init & Cloud Images vs. Traditional ISOs for provisioning workflows with automated cloud images versus standard installer media.