Foreword
Behind Proxmox, OpenStack, OpenNebula, oVirt and most clouds sits the same thing: KVM in the Linux kernel, QEMU as a process for every VM, and usually libvirt as the management layer on top. If you know these three layers, you understand the platforms built on them and you know where to look when the UI only reports “Error while starting”.
This book starts at the very bottom. On Day 1 you start a VM with a
single qemu-system-x86_64 command, without any management
at all. Then libvirt takes over, step by step: disks, pools, networks,
cloud-init, snapshots, backups, performance, remote control, live
migration and, at the end, VMs as code with OpenTofu. The common thread
is notes-api with Postgres as an application made of two VMs.
Every output in this book comes from a real run on two test VMs. Many
chapters show what went wrong during testing: the first reboot after
virt-install that powers the VM off,
blockcommit trying to write into the shared base image, or
the live migration that fails on a hostname that SSH resolves without
any trouble. These spots are marked with Tried it.
Who this book is for
For Linux admins who want to run VMs without a big platform, for everyone who wants to understand Proxmox or OpenStack under the hood, and for platform teams moving away from VMware. You should be able to use Linux on the command line and know what a VM, an IP address and SSH are. Basic knowledge of YAML and XML helps.
How the book is structured
16 training days, each with the same structure:
- Goal and Briefing: what it is about, in a few points.
- Drills: step by step, every command with its expected output.
- Checkpoint: individual commands that show whether you have reached the goal.
- Challenge: a task with a hint and a solution.
- Enterprise Note: what is different in production compared to the lab.
Days 0 to 2 lay the foundation: checking KVM, QEMU by hand, disks with qemu-img. Days 3 to 7 bring libvirt, virt-install with cloud-init, storage pools, networks and the application made of two VMs. Days 8 to 10 cover lifecycle, the guest system and performance. Days 11 to 14 cover remote control, live migration, OpenTofu and operations. Day 15 is a Competition made of five real incidents. At the end you will find a cheat sheet and a final exam.
What you need
- Two Linux VMs with Ubuntu 24.04 and nested virtualization, because they run VMs themselves: kvm1 with 4 vCPUs, 8 GB RAM and an 80 GB disk, kvm2 with 2 vCPUs, 4 GB RAM and a 60 GB disk. Both on the same network. Day 0 shows how to check this. Physical machines work just as well.
- Internet access for both.
- Access to the console of kvm1 (for example through Proxmox) for Day 6, in case the bridge cuts the SSH connection.
- About 20 hours, spread over as many days as you like.
Versions
Tested with Ubuntu 24.04.5, QEMU 8.2.2, libvirt 10.0.0, virt-install
4.1.0, cloud-init 26.1, Cockpit 314, OpenTofu 1.13.9 and the libvirt
provider 0.9.9. Newer versions usually behave the same, but the outputs
may differ. When in doubt, man virsh,
virsh help <command> and the documentation at
libvirt.org help.
Companion code
All files and solutions are on GitHub:
github.com/thomaszachmann/kvm-zum-anfassen. In
loesung/tagNN you will find the files for each day, in
wettkampf/ the hints for Day 15.
Enjoy your drills.
Thomas Zachmann