关于 ubuntu:将 QEMU 命令行参数转换为 libvirt 域 xml

Converting QEMU command line args to libvirt domain xml

我很难将这个 QEMU 命令转换为 libvirt 域 XML:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
qemu-system-x86_64 -enable-kvm \\
-m 3072 \\
-cpu core2duo \\
-machine q35 \\
-smp 2 \\
-usbdevice keyboard \\
-usbdevice mouse \\
-vga std \\
-device isa-applesmc,osk="${osx_osk_key}" \\
-kernel"${chameleon_file_path}" \\
-device ide-drive,bus=ide.2,drive=MacHDD \\
-drive id=MacHDD,if=none,cache=none,file="${vm_hdd_img_file_path}"
-netdev user,id=hub0port0 \\
-device virtio-net,netdev=hub0port0,id=eth0

如果我从终端 (Ubuntu 14.10) 调用它,它可以完美运行,但是 virsh domxml-from-native qemu-argv 对于 MacHDD 设备失败并出现以下错误:

1
error: internal error: missing index/unit/bus parameter in drive 'id=MacHDD,if=none,cache=none,file="${vm_hdd_img_file_path}"'

(注意:当然,我尝试用实际路径代替变量,同样的错误 - 如果我删除最后两个参数,即使包含变量,它也会将其转换为域 XML)

我该如何解决这个问题?或者域 xml 中最后两个参数的等价物是什么? (尝试了很多不同的组合,但无法使用 libvirt/virsh)

编辑

为了记录,这是我在没有 -device -drive

的情况下运行 virsh\\'s domain-from-native 命令的结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
  <name>unnamed</name>
  <uuid>38cafecb-4774-4590-83eb-e576a79aab93</uuid>
  <memory unit='KiB'>3145728</memory>
  <currentMemory unit='KiB'>3145728</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='q35'>hvm</type>
    <kernel>${chameleon_file_path}</kernel>
  </os>
  <features>
   
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>core2duo</model>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    /usr/bin/qemu-system-x86_64</emulator>
    <controller type='sata' index='0'/>
    <controller type='pci' index='0' model='pcie-root'/>
    <controller type='pci' index='1' model='dmi-to-pci-bridge'/>
    <controller type='pci' index='2' model='pci-bridge'/>
    <input type='keyboard' bus='usb'/>
    <input type='mouse' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='sdl'/>
    <video>
      <model type='vga' vram='9216' heads='1'/>
    </video>
    <memballoon model='none'/>
  </devices>
  <qemu:commandline>
    <qemu:arg value='-device'/>
    <qemu:arg value='isa-applesmc,osk="${osx_osk_key}"'/>
    <qemu:arg value='-netdev'/>
    <qemu:arg value='user,id=hub0port0'/>
    <qemu:arg value='-device'/>
    <qemu:arg value='virtio-net,netdev=hub0port0,id=eth0'/>
  </qemu:commandline>
</domain>

但我无法弄清楚在这种情况下什么是 -device -drive 的等效项,并且我无法从该域 xml 创建 VM。

即使没有 MacHDD -device 和 -drive,当我尝试使用 $ virsh create

创建 VM 时也会出现此错误

1
2
error: Failed to create domain from libvirt.xml
error: internal error: cannot load AppArmor profile 'libvirt-38cafecb-4774-4590-83eb-e576a79aab93'


这对我有用。

更改:

1
-drive id=MacHDD,if=none,cache=none,file="${vm_hdd_img_file_path}"

对于

1
-drive id=MacHDD,if=ide,index=2,file="${vm_hdd_img_file_path}"

TBH 我对 libvirt 不太熟悉,但它不会是这样的:

1
2
3
4
   <disk type='file' device='disk'>
     <source file='/path/to/image.img'/>
     <target dev='hda' bus='ide'/>
   </disk>


这个怎么样?

1
2
3
4
5
6
7
8
<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2'/>
  <source file='/home/vbox/mac_hdd_10.10Chimera410R1280x1024x32TV.img'/>
  <target dev='hda' bus='ide'/>
  <boot order='1'/>
 
</disk>
<seclabel type='dynamic' model='apparmor' relabel='yes'/>

这就是泡菜所做的,当我使用 virt-manager 创建 VM 时。并感谢 <qemu:commandline> 的事情。我正在寻找它。如果可能,您能否指出有关使用 Mac OS X KVM 的声音的任何信息?