Skip to content
Hands-on IT IT Drills

Day 0: The Training Ground

Goal: Two lab VMs that can run VMs themselves, an SSH key and the companion code. · Duration: approx. 30 min · Prerequisite: none

Briefing

  • KVM (Kernel-based Virtual Machine) is a module in the Linux kernel. It uses the virtualization features of the CPU (Intel VT-x, AMD-V) and turns Linux itself into a hypervisor. KVM alone does not start a VM, though.
  • QEMU is the program that builds the VM: virtual disks, network cards, BIOS, console. Every VM is an ordinary qemu-system-x86_64 process, and KVM runs its CPU instructions directly on the real CPU.
  • libvirt manages many such QEMU processes: with configuration in XML, networks, storage pools and the virsh tool. Proxmox, OpenNebula and OpenStack build on exactly this stack.
 Laptop ──ssh──► kvm1 (Ubuntu 24.04, 4 vCPU, 8 GB)      kvm2 (2 vCPU, 4 GB)
                  ├─ libvirtd                             ├─ libvirtd
                  ├─ qemu-system-x86_64  VM      ◄── live migration (Day 12) ──►
                  └─ qemu-system-x86_64  VM notes
                  Kernel: kvm, kvm_intel  ── /dev/kvm

Drill 1: The lab VMs

You need two Linux VMs with Ubuntu 24.04 in which KVM works:

Name vCPU RAM Disk
kvm1 4 8 GB 80 GB
kvm2 2 4 GB 60 GB

Both are on the same network and reachable via SSH. You only need kvm2 from Day 7 on. For VMs to run inside a VM, the hypervisor underneath must allow nested virtualization:

Underneath What you set
Proxmox CPU type host in the VM’s hardware settings
libvirt/virt-manager CPU model host-passthrough
VirtualBox “Enable Nested VT-x/AMD-V”
Mac with Apple Silicon does not work, use an x86 machine or a server
Physical hardware nothing, KVM runs directly there

On a Proxmox host, this file shows whether nested virtualization is enabled (on AMD the module is called kvm_amd):

# on the Proxmox host
cat /sys/module/kvm_intel/parameters/nested

Expected:

Y

On current Proxmox versions this is the default.

Save your progress? Sign up for free

Drill 2: Does the VM see the CPU features?

Log in to kvm1. From here on, everything runs there unless a chapter says otherwise.

# on kvm1
lscpu | grep -E 'Model name|Virtualization|Hypervisor'

Expected (your processor will differ):

Model name:                              Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
Virtualization:                          VT-x
Hypervisor vendor:                       KVM
Virtualization type:                     full
  • Virtualization: VT-x (on AMD AMD-V): The VM sees the feature. If the line is missing, the CPU type is set incorrectly.
  • Hypervisor vendor: KVM: kvm1 itself runs under KVM, namely under Proxmox.
grep -c vmx /proc/cpuinfo

Expected: a number greater than 0 (here 8: the flags and vmx flags lines for each CPU). On AMD you search for svm.

Save your progress? Sign up for free

Drill 3: The kernel module and /dev/kvm

lsmod | grep '^kvm'
ls -l /dev/kvm

Expected:

kvm_intel             487424  0
kvm                  1404928  1 kvm_intel
crw-rw---- 1 root kvm 10, 232 Nov 13 12:50 /dev/kvm
  • kvm is the generic part, kvm_intel (or kvm_amd) the part for your processor. Ubuntu loads both automatically.
  • /dev/kvm is the door to KVM. Whoever may open it may start accelerated VMs: root and the kvm group.

A small check tool sums this up:

sudo apt-get install -y cpu-checker
kvm-ok

Expected:

INFO: /dev/kvm exists
KVM acceleration can be used

Save your progress? Sign up for free

Drill 4: You in the kvm group

On Day 1 you start QEMU as a regular user. For that you need access to /dev/kvm:

sudo usermod -aG kvm $USER

The new group only applies after a new login. Log out and back in:

exit
# logged in again on kvm1
id -nG

Expected: kvm is in the list.

ubuntu adm cdrom sudo dip lxd kvm

Save your progress? Sign up for free

Drill 5: An SSH key

Your VMs receive your public key on first boot. You then only need a password for the console:

ssh-keygen -q -t ed25519 -N "" -f ~/.ssh/id_ed25519
cat ~/.ssh/id_ed25519.pub

Expected (your key will differ):

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKBb5JErN+8f… ubuntu@kvm1

Save your progress? Sign up for free

Drill 6: Working directory and companion code

mkdir -p ~/kvm-lab/images
git clone -q https://github.com/thomaszachmann/kvm-zum-anfassen.git ~/kvm-lab/code
ls ~/kvm-lab/code

Expected:

LICENSE  loesung  README.md  wettkampf

loesung/tagNN contains the files you write each day. You only need wettkampf/ on Day 15. The downloaded images end up in ~/kvm-lab/images.

Save your progress? Sign up for free

Checkpoint

kvm-ok

Expected: the line KVM acceleration can be used.

id -nG

Expected: kvm is in the list. If the group is missing, you did not log in again after Drill 4.

ls ~/.ssh/id_ed25519.pub ~/kvm-lab/code/README.md

Expected: both files are listed without errors.

Challenge

Find out how many CPU cores and how much RAM kvm1 has left for its own VMs if Ubuntu itself needs about 1 GB.

Hint: nproc and free -m are enough.

Solution

nproc
free -m

Expected (roughly):

4
               total        used        free      shared  buff/cache   available
Mem:            7941         528        3373           1        4347        7412
Swap:              0           0           0

Four cores and a good 6.5 GB of RAM. You can overcommit cores: three VMs with 2 vCPUs each, that is 6 vCPUs, share the four cores. With RAM this is more dangerous, because when all VMs actually use their memory, the host’s OOM killer steps in and terminates a QEMU process.

Save your progress? Sign up for free

Enterprise Note

  • No nesting in production: KVM hosts run on physical hardware. Nested virtualization costs performance and is not supported by many vendors.
  • Check the BIOS/UEFI: On new servers, VT-x/AMD-V is sometimes disabled in the BIOS. kvm-ok tells you before you start troubleshooting.
  • Who uses KVM: Proxmox VE, OpenNebula, OpenStack Nova, oVirt and the big clouds are built on KVM and QEMU. What you learn here helps when debugging all of these platforms.