14.5.21. 将 QEMU 参数转换为域 XML
virsh domxml-from-native 提供了使用 libvirt 域 XML 将现有 QEMU 参数集转换为客户机描述的方法,然后由 libvirt 使用。请注意,这个命令仅用于转换之前从命令行启动的现有 qemu 虚拟机,以便它们可以通过 libvirt 进行管理。此处描述的方法不应用于从头开始创建新虚拟机。使用 virsh 或 virt-manager 创建新 guest。有关其他信息,请点击此处。
假设您有带有以下 args 文件的 QEMU 客户机:
$ cat demo.args
LC_ALL=C
PATH=/bin
HOME=/home/test
USER=test
LOGNAME=test /usr/bin/qemu -S -M pc -m 214 -smp 1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb
要将它转换为域 XML 文件,以便客户端可由 libvirt 管理,请运行:
$ virsh domxml-from-native qemu-argv demo.args
这个命令会将以上 args 文件转换为这个域 XML 文件:
<domain type='qemu'>
<uuid>00000000-0000-0000-0000-000000000000</uuid>
<memory>219136</memory>
<currentMemory>219136</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
</disk>
</devices>
</domain>