QEMU KVM Logging: Enable & View VM Logs
In this article
To enable logging on a QEMU/KVM virtual machine, you add logging parameters to the QEMU command line or to the VM's libvirt XML configuration, then view the generated log files. This article explains the exact steps for both command-line QEMU and libvirt-managed VMs, how to interpret the logs, and how to troubleshoot common logging issues.
Background: Why QEMU/KVM Logging Matters
QEMU/KVM is the standard virtualization stack on Linux, combining the QEMU device emulator with the KVM kernel module for hardware-accelerated execution. Logging is essential for diagnosing guest boot failures, device passthrough problems, crashes, and performance issues. Without logs, you are left guessing why a VM stopped responding or failed to start. QEMU's logging system captures events from the emulated hardware, the virtual CPU, and the QEMU monitor, giving you a detailed trace of what the VM is doing at any moment.
How QEMU Logging Works
QEMU uses the -d option to enable logging of specific components, and -D to specify the log file path. The log output includes timestamps, CPU state, memory operations, device activity, and more, depending on which log items you enable. For example, -d cpu_reset logs CPU resets, -d in_asm logs translated instructions, and -d guest_errors logs errors reported by the guest. You can combine multiple items with commas. The log file is written in plain text and can grow quickly, so it's important to enable only what you need.
Enabling Logging on Command-Line QEMU
If you start VMs directly with the qemu-system-x86_64 command, add the following parameters:
-D /path/to/logfile.log— sets the log file location.-d item1,item2,...— enables specific log categories.
For example, to log guest errors and CPU resets to /var/log/qemu-vm.log:
qemu-system-x86_64 -m 2048 -hda vmdisk.img -D /var/log/qemu-vm.log -d guest_errors,cpu_reset
You can also use -d help to list all available log items. Common useful items include guest_errors, cpu_reset, in_asm, out_asm, int, mmu, and unimp (for unimplemented features). For a full trace of guest execution, use -d trace with a trace backend, but that is much more verbose.
Enabling Logging for libvirt-Managed VMs
Most users manage VMs through libvirt (using virsh or virt-manager). To enable logging for a libvirt-managed VM, you need to edit its XML configuration. Run:
virsh edit vm-name
Then add the following inside the <domain> element:
<qemu:commandline> <qemu:arg value='-D'/> <qemu:arg value='/var/log/libvirt/qemu/vm-name.log'/> <qemu:arg value='-d'/> <qemu:arg value='guest_errors,cpu_reset'/> </qemu:commandline>
You must also ensure the <domain> element has the QEMU namespace declared:
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
After saving, restart the VM for the changes to take effect. The log file will be created when the VM starts. Note that libvirt may also write its own logs to /var/log/libvirt/qemu/ if you enable libvirt's logging, but the QEMU-specific log is separate.
Choosing the Right Log Items
Selecting the right log items is key to getting useful output without overwhelming disk space. Here are common scenarios:
- Boot failure or hang: Use
guest_errorsandcpu_resetto see if the guest CPU resets or reports errors. - Device or PCI passthrough issues: Use
unimpto see unimplemented device features, andpcifor PCI configuration space reads/writes. - Performance analysis: Use
in_asmandout_asmto trace translated code, but be aware this produces huge logs. - Memory or MMU problems: Use
mmuto log memory management unit operations.
You can combine items with commas, e.g. -d guest_errors,unimp,cpu_reset. To see all options, run qemu-system-x86_64 -d help.
Common Problems and Solutions
Log file not created: Check that the directory exists and the user running QEMU has write permissions. For libvirt VMs, the log path must be writable by the QEMU process (usually user qemu). Use chown qemu:qemu /path/to/log or choose a directory like /var/log/libvirt/qemu/ which is already writable.
Log grows too fast: Enable only the minimal items you need. For production, avoid in_asm or out_asm unless debugging. You can also use log rotation via logrotate to manage file sizes.
Log is empty: Some items, like guest_errors, only produce output when an error occurs. If the VM runs normally, the log may remain empty. Test with -d in_asm to confirm logging works, then switch back.
VM fails to start with logging enabled: Ensure the log path is valid and the -d items are correct. A typo in the item name can cause QEMU to exit with an error. Use -d help to verify.
Viewing and Interpreting Logs
Logs are plain text. Use tail -f /path/to/logfile to watch live output. Each entry typically includes a timestamp, CPU number, and the event. For example, a guest error might look like:
2025-01-15T10:22:33.123456Z qemu-system-x86_64: Guest error: unsupported I/O port 0x80
This indicates the guest attempted an I/O operation that QEMU does not fully emulate. While often harmless, it can point to a driver issue. For CPU resets, you'll see lines like CPU Reset with the CPU state, which helps diagnose triple faults or reboot loops.
Frequently Asked Questions
How do I enable logging for a VM started with virt-manager?
Open virt-manager, select the VM, and go to Details → XML tab. Add the <qemu:commandline> block as shown above, then apply. The VM must be restarted for the change to take effect.
Can I enable logging without restarting the VM?
No, QEMU logging parameters are set at startup. You cannot change them dynamically. You can, however, use the QEMU monitor (virsh qemu-monitor-command) to send the log command, but only if the monitor is enabled and the log item is already compiled in. For most users, a restart is required.
What is the difference between QEMU logging and libvirt logging?
QEMU logging captures events inside the emulator (CPU, devices, memory). Libvirt logging captures management events (VM start/stop, configuration changes) in /var/log/libvirt/qemu/. Both are useful; QEMU logging is for guest-level issues, while libvirt logging is for management-level issues.
How do I disable logging?
Remove the -D and -d arguments from the command line, or delete the <qemu:commandline> block from the libvirt XML. Then restart the VM.
Does logging affect VM performance?
Yes, especially with verbose items like in_asm or out_asm, which can slow the VM significantly due to the overhead of writing every translated instruction. For production, stick to guest_errors and cpu_reset to minimize impact.
Where are the default QEMU logs stored?
There is no default log file. If you don't specify -D, QEMU writes logs to stderr. For libvirt VMs, if you don't set a custom path, you can find the VM's stderr output in /var/log/libvirt/qemu/ (though not always). Always specify an explicit path to be sure.