QEMU/KVM/Virsh Tips

8 篇文章 2 订阅
本文介绍了KVM、QEMU和Virsh在虚拟化环境中的区别与联系,包括libvirt命令转换、AppArmor配置错误的解决方案、启用libvirt日志以及通过libvirt添加QEMU参数的方法。同时,展示了如何理解和编辑Libvirt的XML格式,为虚拟机设备配置提供指导。
摘要由CSDN通过智能技术生成

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: 

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:

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:

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:

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:

<qemu:arg value='-trace'/>
<qemu:arg value='traced_function_name'/>

as:

 

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值