2017年10月4日更新:请参阅下面的答案 . 归功于DanielB,因为如果没有Daniel的帮助我就不会解决问题,所以我会接受他的答案而不是我自己的答案 .
我是libvirt和系统管理方面的新手,请原谅我,如果我问的是愚蠢的问题,尽管我已经尽力做了尽可能多的家庭作业 .
My question is :如何在使用virsh创建VM后立即从CDROM启动以安装来宾操作系统?
我正在使用Ubuntu Desktop 14.04,virsh 1.2.2 .
当我使用'virt-install'并将ISO文件路径作为'--cdrom'参数传递时,我可以成功启动virt-viewer窗口,这允许我通过客户操作系统安装 .
据我所知,我也可以使用XML定义创建VM,我使用'virt-install'转储了我创建的VM的XML定义 . 然后我预计在启动VM时会自动启动'virt-viewer'窗口,以便安装guest虚拟机操作系统 . 但事实并非如此 .
下面是我的VM的XML定义 .
如果我启用加载器行,如下面标记为"suspicious",我将收到"error: internal error: cannot load AppArmor profile 'libvirt-1092d51d-3b66-46a2-bf9b-71e13dc91799'"的错误消息 . 我这样做是因为我在尝试libvirt's document here中给出的例子 .
但是,如果我禁用"loader"行并运行 virsh create def_domain_test.xml
,则可以成功创建域,并显示为'running',但 the virt-viewer window is not brought up, so I can't install the guest OS on the VM .
Could anyone help me on that? 我不是't understand why ' virt-install ' can bring up the virt-viewer but my XML definition can' t . 我可能错误地配置了域XML定义,但我无法尽可能多地阅读文档 .
如果需要,请随时询问更多详细信息 .
<!-- Let's call this file 'def_domain_test.xml' -->
<domain type='kvm'>
<name>vm_c2</name>
<memory unit='KiB'>2097152</memory>
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
<!-- Next line is suspicious! -->
<!-- <loader readonly='yes' secure='no' type='rom'>/usr/lib/xen-4.4/boot/hvmloader</loader> -->
<boot dev='cdrom'/>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<pae/>
</features>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<!-- Here is the hard drive that doesn't have OS installed. -->
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/home/me/me/testing/vm/pool/mvs_vol_c2'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<!-- Here is the Ubuntu ISO. -->
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/home/me/me/testing/vm/ubuntu-14.04.5-server-amd64.iso'/>
<target dev='hdc' bus='ide'/>
<readonly/>
<alias name='ide0-1-0'/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<interface type='network'>
<source network='default'/>
<model type='rtl8139'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='-1' autoport='yes'/>
<video>
<model type='cirrus' vram='9216' heads='1'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</memballoon>
</devices>
</domain>
2 回答
virsh
是一个非常低级的工具,其命令直接映射到单独的libvirt API调用 . 由virt-install
完成的安装将进行许多API调用以完成其工作 . 因此,只需获取已安装的guest虚拟机的最终XML并将其传递给virsh define
就不等了 .首先,
virt-install
通常会更改XML - 它首先创建一个临时客户机,一个适用于启动CDROM的XML文档,然后完成它将改变XML以引导磁盘 .virt-install
将手动启动virt-viewer
以显示控制台,这不是virsh
的作用 .这个特定的
<loader>
行永远不应该与KVM一起使用 - 它只与Xen相关 - 通过使用你已经告诉KVM运行Xen paravirt代码作为其BIOS而不是SeaBIOS - 这肯定会崩溃和烧毁 .如果你使用'--debug' arg到
virt-install
,你会看到它在每一步的作用细节 . 如果要查看每个libvirt API调用的详细信息,还可以设置LIBVIRT_LOG_FILTERS=1:libvirt
和LIBVIRT_LOG_OUTPUTS=1:stderr
.感谢DanielB 's help! The ' --debug'
virt-install
的论点确实揭示了解决这个问题所需的信息 .首先,在XML定义中,我不需要
<loader>
行 .<os>
部分应为:两个
<boot>
标记已指定引导顺序 .其次,
virt-install
的调试输出表明了提出virt-viewer
所需的方法:运行:
virt-viewer --connect=qemu:///system --wait vm_c2
(可选)您可以将'--debug'和'--verbose'添加到
virt-viewer
以查看更多输出 .此时,应显示查看器窗口并显示一条消息:
Waiting for guest domain to be created
.运行:
virsh create --file def_domain_test.xml
.现在将激活查看器并显示VM的输出 .
这是 one caveat 导致我在开始时陷入困境:您不必在VM之前启动
virt-viewer
. 但是,如果您首先启动VM然后再启动查看器,则查看器屏幕可能是整个黑色的,这可能会使您感到困惑并让您认为没有任何事情发生在那里 . 在这种情况下,单击查看器窗口让它获得输入焦点,然后按'Enter'键,您可以刷新它,看看实际上有什么 . (调整窗口大小不会强制刷新 . )仅供参考:如果您输出virt-viewer的调试消息,您可能会看到如下消息:
这似乎并没有给我带来任何问题,但如果virt-viewer无法正常工作,也许是其他问题的暗示 .