KVM virtualization: virt-install, virsh, and nested virtualization, measured
Fedora is both KVM’s upstream and one of its best hosts. Every command here was measured inside a Fedora 45 virtual machine — including nested virtualization.
Install
Section titled “Install”sudo dnf install -y qemu-kvm libvirt virt-install guestfs-tools edk2-ovmfsudo systemctl enable --now libvirtdMeasured versions: qemu-kvm 11.1.2, libvirt 12.6.0, virt-install 5.1.0, OVMF (UEFI firmware) 20260812.
Package roles:
| Package | Purpose |
|---|---|
qemu-kvm | the VM engine (CPU/memory/device emulation) |
libvirt | management layer: API, daemons, XML definitions |
virt-install | create VMs from the CLI |
guestfs-tools | offline image editing (virt-customize etc.) |
edk2-ovmf | UEFI firmware (Windows 11 / modern guests) |
Validate the host
Section titled “Validate the host”sudo virt-host-validate qemuMeasured on this machine — itself a VM on PVE, i.e. nested:
QEMU: Checking for hardware virtualization : PASS QEMU: Checking if device '/dev/kvm' exists : PASS QEMU: Checking if device '/dev/kvm' is accessible : PASS QEMU: Checking for cgroup 'cpu' controller support: PASSHardware virtualization PASS means nested virtualization is enabled (the PVE host passes AMD-V through with cpu host). Physical machines likewise PASS. Fix any FAIL per its hint (BIOS SVM/VT-x, kernel module).
Create a VM from the CLI
Section titled “Create a VM from the CLI”sudo virt-install --name=vmtest --memory=512 --vcpus=1 \ --disk size=1 --os-variant=generic --noautoconsoleMeasured: starts successfully even nested (state running). Key flags:
| Flag | Meaning |
|---|---|
--disk size=1 | 1G qcow2 in the default pool |
--cdrom=xxx.iso | attach an install ISO |
--os-variant=win11 | precise variant improves virtio/firmware choices (osinfo-query os lists all) |
--network network=default | NAT network (the default) |
--graphics spice | graphical console |
The default storage pool is /var/lib/libvirt/images/. Undefining a VM does not delete its disk:
sudo virsh undefine vmtest --nvramsudo rm /var/lib/libvirt/images/vmtest.qcow2virsh everyday
Section titled “virsh everyday”sudo virsh list --all # all VMs and statessudo virsh start vmtest # power onsudo virsh shutdown vmtest # graceful (ACPI)sudo virsh destroy vmtest # pull the plug (forced)sudo virsh autostart vmtest # start with the hostsudo virsh console vmtest # serial console (guest needs serial enabled)sudo virsh dominfo vmtest # detailsNetworking: default NAT vs bridged
Section titled “Networking: default NAT vs bridged”- default network (NAT): guest reaches out, host reaches in (
virsh net-dhcp-leasesfor IPs), outside cannot reach in — the common case - bridged (br0): the VM appears directly on the physical network with a same-segment IP — for servers offering services
sudo virsh net-list --all # default is usually active + autostartsudo virsh net-dhcp-leases defaultGuest agent: let the host see inside
Section titled “Guest agent: let the host see inside”# in the guest:sudo dnf install -y qemu-guest-agent# on the host (VM config needs the qemu-ga channel):sudo virsh qemu-agent-command vmtest '{"execute":"guest-ping"}'With the agent, virsh shutdown is reliable and the host can read IPs, freeze filesystems, and more — PVE’s qm guest exec depends on it too.
Performance notes
Section titled “Performance notes”- disks on virtio-scsi (
--disk bus=scsi,controller=virtio-scsi), several times faster than IDE - NICs on virtio (
--network model=virtio) - pass CPU topology through with
--cpu host(nested/migration trade-offs in the libvirt docs) - Windows guests need the virtio-win driver ISO (
dnf install virtio-winon the host)
Common traps
Section titled “Common traps”| Symptom | Cause |
|---|---|
| validate reports hardware virtualization FAIL | BIOS SVM/VT-x off, or host not passing through |
| VM runs but is very slow | disk/NIC not on virtio |
| shutdown hangs | no qemu-guest-agent in the guest; use destroy |
| console connects but prints nothing | guest kernel lacks serial console parameters |
| UEFI guest won’t install | edk2-ovmf missing, or --boot uefi not set |
| default pool full | /var/lib/libvirt/images sits on root; virsh vol-delete |
Related pages
Section titled “Related pages”- cloud-init customization — pairs with virt-install for instant usable systems
- systemd services and timers — libvirtd’s service model
- Upstream: libvirt docs