Most of the time libvirt is the right interface — it stores the config, manages the lifecycle, and integrates with virsh and virt-manager. But every operator who works with KVM long enough hits a problem where the answer is “look at the qemu command line libvirt is actually running, and run it directly.” This article is the field guide for that moment: the flag families, the ones you change, and the ones you leave alone.
How to verify
Confirm QEMU is present, check the version, and inspect what machine types and CPUs your build supports. The build determines which devices are even available.
qemu-system-x86_64 --version
qemu-system-x86_64 -machine help | head
qemu-system-x86_64 -cpu help | head
qemu-system-x86_64 -device help 2>&1 | head -30
ps -ef | grep '[q]emu-system' | head -3
The ps line shows what libvirt is invoking for live domains — copy one of those into a file and you have a starting point you know works on your host.
What’s happening
qemu-system-x86_64 is the userspace emulator for x86_64 guests. With KVM, it asks the kernel to execute guest instructions at near-native speed; without it, it falls back to TCG software emulation. Every aspect of a guest — virtual hardware, memory layout, boot order, I/O paths — is set on the command line. There is no config file. libvirt’s job is to take XML and translate it into one of these enormous command lines.
Flags fall into rough families. The “what kind of machine” set (-M, -cpu, -smp, -m) defines the platform. The “what’s plugged in” set (-drive, -netdev + -device, -chardev, -display) defines the peripherals. The “how it boots” set (-bios, -kernel, -initrd, -boot) controls firmware and boot media. The “how it talks to us” set (-monitor, -qmp, -vnc, -serial) sets up control channels.
The procedure
-
Define the machine.
-machine q35,accel=kvmis the modern PCIe-based chipset for new guests;-machine pc,accel=kvmis the legacy i440FX. Always pin a machine version (q35-7.2) for production so guest hardware doesn’t shift under you when QEMU is upgraded:qemu-system-x86_64 \ -machine type=q35,accel=kvm,vmport=off \ -cpu host -smp cores=2,threads=1,sockets=1 \ -m 2048 -
CPU model — host vs named.
-cpu hostexposes every feature the physical CPU has. Fine for a non-clustered host; on a cluster where guests live-migrate, pin a named CPU model that all hosts share (-cpu Haswell-noTSX) so guest features don’t disappear after a migration. -
Disks — the slow way and the fast way. Two flag styles exist: the legacy
-driveand the modern-blockdev+-device.-driveis concise but conflates the backend (the file) with the frontend (the virtual device). For production, use the split form:-blockdev driver=qcow2,node-name=disk0,file.driver=file,file.filename=/var/lib/libvirt/images/web01.qcow2 \ -device virtio-blk-pci,drive=disk0,id=virtio-disk0 -
Network — netdev + device. Same backend/frontend split. The backend (
-netdev) is the host side (tap into a bridge, user-mode, vhost); the device (-device) is what the guest sees:-netdev tap,id=net0,ifname=tap0,script=no,downscript=no,vhost=on \ -device virtio-net-pci,netdev=net0,mac=52:54:00:11:22:33,id=net0devscript=nomeans QEMU does not bring up or down the tap interface — your host script (or libvirt) does.vhost=onoffloads the data path to a kernel module for a meaningful throughput boost. -
Console and monitor — how you control the guest. QMP (the JSON monitor) is what tools speak; the HMP text monitor is what humans use to poke at a running guest. Always set both:
-qmp unix:/tmp/web01.qmp,server,nowait \ -monitor unix:/tmp/web01.mon,server,nowait \ -serial mon:stdiomon:stdiomuxes the serial console and monitor onto stdin/stdout — useful for one-shot tests; production wants separate Unix sockets. -
Display — VNC or none. Headless cloud images don’t need a display; Windows installers do. SPICE has nicer remote-desktop semantics but VNC is universally available:
-display none -vga none # truly headless -vnc unix:/tmp/web01.vnc -vga virtio # VNC over Unix socket -
Inspect what libvirt actually runs. When a libvirt XML produces a guest that misbehaves, dump the QEMU args:
sudo cat /var/log/libvirt/qemu/web01.log | head -50 # Or: ps -ef | grep '[q]emu-system' | tr ' ' '\n' | lessCopy the line, simplify it (drop
-name guest=..., drop unused chardev sockets), and run it by hand. You can now twiddle one flag at a time.
Operational notes
-cpu hostis great for one-host setups and a footgun on clusters — pick a baseline CPU model that survives live migration across the whole fleet.- Mixing
-driveand-blockdevstyles in the same invocation works but is confusing; pick one and stay there. vhost=onon tap netdevs requires thevhost_netkernel module loaded on the host; without it you get poor network performance and no error.- The QEMU monitor (
-monitor) over TCP is dangerous unless bound to localhost — anyone who reaches the port canquitthe guest ormigrateit elsewhere. - Machine type aliases (
q35without a version) follow the QEMU upgrade — a live-migrated guest can land on a different QEMU and end up on a different machine version. Pin versions for stable VM identities.
Stack Harbor keeps the raw QEMU command line in mind even when libvirt is the daily driver — when a guest behaves weirdly, the answer is often in the underlying -machine or -cpu flag, not in the libvirt XML. The clients who run KVM at scale get that diagnostic literacy as part of how we operate; the lifecycle is covered in Managed Operations.