Basic concepts: 【虚拟化】KVM、Qemu、Virsh的区别与联系_Captain_zw的博客-CSDN博客
virsh domxml-to-native qemu-argv my-virtual-machine.xml
As:
error: internal error: Process exited prior to exec: libvirt: error : unable to set AppArmor profile 'libvirt-b51176bb-04c2-4a99-b248-15e51cb2429b' for '/usr/bin/qemu-system-x86_64': No such file or directory
Soultion:
Unable to start KVM virtual machines with libvirt and AppArmor - Estada.ch
Example on my machine:
Then start the virtual machine again:
If you check the libvirt configs, you will find:
We can see a virtlogd.conf. If your libvirt has no this file, I guess you can use libvirtd.conf.
Open virtlogd.conf and add following configure:
log_level = 1
log_outputs = "1:file:/your_path/your_file"
And here is my example:
And there are some other configures you can add in this file.
Then you'd better to restart libvirtd or reboot.
Then you can find the log file as:
And you can see virtual machine's log file here too. And in the virtual machine's log, you can see the qemu command line which matches libvirt virtual machine XML.
if you don't start your virtual machine by pure QEMU command line, you need to find a way to add QEMU paramters to libvirt XML.
Here is what I found a way by virt-xml:
virt-xml ubuntu18.04-2 --edit --confirm --qemu-commandline="-trace qemu_mutex_lock"
After this command, we can see libvirt XML add this parameter as:
Then we can start the virtual machine and we can found the trace on the log as:
And we can directly add more trace in the XML file by 'virsh edit ubuntu18.04-2'. We just need follow the format of:
as:
For example, if we hope to add some device to the virtual machine by libvirt XML file, we need to know how to write the XML file.
Here is Libvirt's official gudie:
libvirt: Domain XML format