Nested Virtual Machines with KVM, libvirt, and virsh
I enabled nested virtualization on KVM and provisioned guest VMs inside a VM with libvirt, virt-install, and virsh. Nesting let me build multi-node clustering and hypervisor labs on a single physical host with no additional hardware.
Objective & Context
Nested KVM exposes the CPU virtualization extensions to a guest so it can itself run VMs. This lab turns on nesting, scripts guest creation with virt-install, and manages lifecycle with virsh, the technique behind the Proxmox and Kubernetes cluster labs.
Environment & Prerequisites
- Linux host with KVM, libvirt, and CPU virtualization extensions.
- Sufficient RAM/CPU for nested guests.
- A cloud or ISO image for the inner guest.
flowchart TB
H[Physical host KVM] --> L1[L1 VM nested enabled]
L1 --> G1[Inner guest A]
L1 --> G2[Inner guest B]
Step-by-Step Execution
1. Enable nested virtualization [ROOT REQUIRED]
modprobe -r kvm_intel; modprobe kvm_intel nested=1; cat /sys/module/kvm_intel/parameters/nested2. Provision an inner guest with virt-install
virt-install --name inner1 --memory 2048 --vcpus 2 --disk size=10 --osinfo debian12 --import3. Manage with virsh
virsh list --all && virsh start inner1Y # nested enabled
Id Name State
3 inner1 running
Validation & Testing
Confirm nested reads Y, then boot an inner guest and verify it sees virtualization extensions (egrep -c '(vmx|svm)' /proc/cpuinfo > 0). Pass criteria: nesting enabled, inner guest boots, and it can itself run a container or VM.
Advanced: Troubleshooting
- nested = N: the module must be reloaded with
nested=1; persist via modprobe.d. - Inner guest no VT: set the L1 VM CPU mode to host-passthrough.
- Poor performance: nesting adds overhead; allocate generous host resources.
Key Results
- Enabled nested KVM and booted guests inside a VM.
- Built multi-node lab topologies on a single physical host.
- Scripted reproducible guest creation with virt-install.
- Managed full VM lifecycle through virsh.