QEMU/KVM/Virsh Tips

Basic concepts:  【虚拟化】KVM、Qemu、Virsh的区别与联系_Captain_zw的博客-CSDN博客

1. libvirt xml to QEMU command line:

virsh domxml-to-native qemu-argv my-virtual-machine.xml

As: 

QEMU/KVM/Virsh Tips_第1张图片

2. QEMU command line to libvirt XML

3. Virtual machine boot error of libvirt unable to set AppArmor profile:

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:

QEMU/KVM/Virsh Tips_第2张图片

4. enable libvirt log file

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:

QEMU/KVM/Virsh Tips_第3张图片

QEMU/KVM/Virsh Tips_第4张图片

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.

5. Add QEMU parameters by libvirt

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:

QEMU/KVM/Virsh Tips_第5张图片

Then we can start the virtual machine and we can found the trace on the log as:QEMU/KVM/Virsh Tips_第6张图片

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:

QEMU/KVM/Virsh Tips_第7张图片

 

 6. Libvirt XML format

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

你可能感兴趣的:(qemu,KVM,html)