Build a Nested KVM Hypervisor Lab with libvirt
You will turn one Linux server into a hypervisor that runs guest VMs, letting you build multi-node clusters on a single machine. By the end you will boot a nested guest and manage it entirely from the command line.
Learning Objectives
- Enable nested virtualization in the KVM kernel module.
- Provision a guest VM with libvirt and virt-install.
- Manage VM lifecycle with virsh.
- Time: ~3 hours · Difficulty: Advanced · Prereqs: a Linux host with CPU virtualization extensions and 8GB+ RAM.
Architecture Overview
Environment Setup
You will need: a Linux server with KVM (kvm-ok passes), libvirt, and virtinst installed.
Before you begin: confirm CPU extensions with egrep -c '(vmx|svm)' /proc/cpuinfo (must be > 0).
Step-by-Step Execution
These packages provide the KVM hypervisor, the libvirt management API, and the virt-install provisioning tool.
sudo apt install -y qemu-kvm libvirt-daemon-system virtinstNesting exposes virtualization extensions to guests so an L1 VM can itself run VMs.
echo 'options kvm_intel nested=1' | sudo tee /etc/modprobe.d/kvm.conf && sudo modprobe -r kvm_intel; sudo modprobe kvm_intelThis creates and boots a guest from a cloud image, scripted and repeatable.
virt-install --name node1 --memory 2048 --vcpus 2 --disk size=10 --osinfo ubuntu22.04 --import --noautoconsoleProgress So Far
Testing & Validation
cat /sys/module/kvm_intel/parameters/nested && virsh domstate node1You should see Y for nesting and running for the guest. If both pass, your nested hypervisor lab works.
Troubleshooting
- nested reads N: reload the module after adding the modprobe option; persist via
/etc/modprobe.d. - Guest has no virtualization: set the L1 CPU mode to host-passthrough.
- libvirtd not running:
sudo systemctl enable --now libvirtd.
Extension Ideas
- Boot two guests and build the Kubernetes Basics lab across them.
- Compare with the Proxmox Homelab approach.
- Automate guest creation with cloud-init user-data.
Key Results
- Enabled nested KVM and booted a guest inside a VM.
- Provisioned guests reproducibly with one virt-install command.
- Built multi-node topologies on a single physical host.
- Managed full VM lifecycle through virsh.