今天在linux服务器上编译安装升级了下qemu,升级命令如下:
root@ubuntu:/opt/qemu-2.0.# ./configure --prefix=/usr/local/ --target-list=x86_64-softmmu
root@ubuntu:/opt/qemu-2.0.# make
root@ubuntu:/opt/qemu-2.0.# make install
顺利编译安装后,去define了一个虚拟机,结果报了如下错误:
root@ubuntu:~# virsh define test.xml
error: Failed to define domain from test.xml
error: unknown OS type hvm
好奇怪,便查看了下domain capabilities,命令:
root@ubuntu:~# virsh capabilities
<capabilities> <host>
<uuid>44454c4c-4e00---b2c04f5a3258</uuid>
<cpu>
<arch>x86_64</arch>
<model>Nehalem</model>
<vendor>Intel</vendor>
<topology sockets='' cores='' threads=''/>
<feature name='rdtscp'/>
<feature name='dca'/>
<feature name='xtpr'/>
<feature name='tm2'/>
<feature name='est'/>
<feature name='vmx'/>
<feature name='ds_cpl'/>
<feature name='monitor'/>
<feature name='pbe'/>
<feature name='tm'/>
<feature name='ht'/>
<feature name='ss'/>
<feature name='acpi'/>
<feature name='ds'/>
<feature name='vme'/>
</cpu>
<power_management/>
<migration_features>
<live/>
<uri_transports>
<uri_transport>tcp</uri_transport>
</uri_transports>
</migration_features>
<topology>
<cells num=''>
<cell id=''>
<cpus num=''>
<cpu id=''/>
<cpu id=''/>
<cpu id=''/>
<cpu id=''/>
</cpus>
</cell>
<cell id=''>
<cpus num=''>
<cpu id=''/>
<cpu id=''/>
<cpu id=''/>
<cpu id=''/>
</cpus>
</cell>
</cells>
</topology>
</host> </capabilities>
跟正常情况下相比,发现少了<guest> 段落,下面贴下正常情况下的domain capabilities的情况:
<capabilities> <host>
<uuid>01192eea--cb11-a16c-f9dcbe14b1ee</uuid>
<cpu>
<arch>x86_64</arch>
<model>Westmere</model>
<vendor>Intel</vendor>
<topology sockets='' cores='' threads=''/>
<feature name='invpcid'/>
<feature name='erms'/>
<feature name='bmi2'/>
<feature name='smep'/>
<feature name='avx2'/>
<feature name='bmi1'/>
<feature name='fsgsbase'/>
<feature name='abm'/>
<feature name='rdtscp'/>
<feature name='pdpe1gb'/>
<feature name='rdrand'/>
<feature name='f16c'/>
<feature name='avx'/>
<feature name='osxsave'/>
<feature name='xsave'/>
<feature name='tsc-deadline'/>
<feature name='movbe'/>
<feature name='pcid'/>
<feature name='pdcm'/>
<feature name='xtpr'/>
<feature name='fma'/>
<feature name='tm2'/>
<feature name='est'/>
<feature name='vmx'/>
<feature name='ds_cpl'/>
<feature name='monitor'/>
<feature name='dtes64'/>
<feature name='pclmuldq'/>
<feature name='pbe'/>
<feature name='tm'/>
<feature name='ht'/>
<feature name='ss'/>
<feature name='acpi'/>
<feature name='ds'/>
<feature name='vme'/>
</cpu>
<power_management>
<suspend_mem/>
<suspend_disk/>
<suspend_hybrid/>
</power_management>
<migration_features>
<live/>
<uri_transports>
<uri_transport>tcp</uri_transport>
</uri_transports>
</migration_features>
<topology>
<cells num=''>
<cell id=''>
<memory unit='KiB'></memory>
<cpus num=''>
<cpu id='' socket_id='' core_id='' siblings='0-1'/>
<cpu id='' socket_id='' core_id='' siblings='0-1'/>
<cpu id='' socket_id='' core_id='' siblings='2-3'/>
<cpu id='' socket_id='' core_id='' siblings='2-3'/>
</cpus>
</cell>
</cells>
</topology>
<secmodel>
<model>none</model>
<doi></doi>
</secmodel>
<secmodel>
<model>dac</model>
<doi></doi>
<baselabel type='kvm'>+:+</baselabel>
<baselabel type='qemu'>+:+</baselabel>
</secmodel>
</host> <guest>
<os_type>hvm</os_type>
<arch name='i686'>
<wordsize>32</wordsize>
<emulator>/usr/bin/qemu-system-i386</emulator>
<machine canonical='pc-i440fx-trusty' maxCpus='255'>pc</machine>
<machine maxCpus='255'>pc-0.12</machine>
<machine maxCpus='255'>pc-1.3</machine>
<machine maxCpus='255'>pc-q35-1.6</machine>
<machine canonical='pc-1.0-qemu-kvm' maxCpus='255'>pc-1.0-precise</machine>
<machine maxCpus='255'>pc-q35-1.5</machine>
<machine maxCpus='1'>xenpv</machine>
<machine maxCpus='255'>pc-i440fx-1.6</machine>
<machine maxCpus='255'>pc-i440fx-1.7</machine>
<machine maxCpus='255'>pc-0.11</machine>
<machine maxCpus='255'>pc-0.10</machine>
<machine maxCpus='255'>pc-1.2</machine>
<machine maxCpus='1'>isapc</machine>
<machine maxCpus='255'>pc-q35-1.4</machine>
<machine maxCpus='128'>xenfv</machine>
<machine maxCpus='255'>pc-0.15</machine>
<machine maxCpus='255'>pc-0.14</machine>
<machine maxCpus='255'>pc-i440fx-1.5</machine>
<machine canonical='pc-q35-2.0' maxCpus='255'>q35</machine>
<machine maxCpus='255'>pc-i440fx-1.4</machine>
<machine maxCpus='255'>pc-1.1</machine>
<machine maxCpus='255'>pc-q35-1.7</machine>
<machine canonical='pc-1.0' maxCpus='255'>pc-1.0-qemu-kvm</machine>
<machine maxCpus='255'>pc-i440fx-2.0</machine>
<machine maxCpus='255'>pc-0.13</machine>
<domain type='qemu'>
</domain>
<domain type='kvm'>
<emulator>/usr/bin/qemu-system-i386</emulator>
</domain>
</arch>
<features>
<cpuselection/>
<deviceboot/>
<acpi default='on' toggle='yes'/>
<apic default='on' toggle='no'/>
<pae/>
<nonpae/>
</features>
</guest> <guest>
<os_type>hvm</os_type>
<arch name='x86_64'>
<wordsize>64</wordsize>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<machine canonical='pc-i440fx-trusty' maxCpus='255'>pc</machine>
<machine maxCpus='255'>pc-1.3</machine>
<machine maxCpus='255'>pc-0.12</machine>
<machine maxCpus='255'>pc-q35-1.6</machine>
<machine canonical='pc-1.0-qemu-kvm' maxCpus='255'>pc-1.0-precise</machine>
<machine maxCpus='255'>pc-q35-1.5</machine>
<machine maxCpus='1'>xenpv</machine>
<machine maxCpus='255'>pc-i440fx-1.6</machine>
<machine maxCpus='255'>pc-i440fx-1.7</machine>
<machine maxCpus='255'>pc-0.11</machine>
<machine maxCpus='255'>pc-1.2</machine>
<machine maxCpus='255'>pc-0.10</machine>
<machine maxCpus='1'>isapc</machine>
<machine maxCpus='255'>pc-q35-1.4</machine>
<machine maxCpus='128'>xenfv</machine>
<machine maxCpus='255'>pc-0.15</machine>
<machine maxCpus='255'>pc-0.14</machine>
<machine maxCpus='255'>pc-i440fx-1.5</machine>
<machine maxCpus='255'>pc-i440fx-1.4</machine>
<machine canonical='pc-q35-2.0' maxCpus='255'>q35</machine>
<machine maxCpus='255'>pc-1.1</machine>
<machine maxCpus='255'>pc-q35-1.7</machine>
<machine canonical='pc-1.0' maxCpus='255'>pc-1.0-qemu-kvm</machine>
<machine maxCpus='255'>pc-i440fx-2.0</machine>
<machine maxCpus='255'>pc-0.13</machine>
<domain type='qemu'>
</domain>
<domain type='kvm'>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
</domain>
</arch>
<features>
<cpuselection/>
<deviceboot/>
<acpi default='on' toggle='yes'/>
<apic default='on' toggle='no'/>
</features>
</guest> </capabilities>
这时问题就很明显了,肯定是升级qemu时哪里出现了问题,经过多次尝试,终于发现了原因:我们需要将 qemu-system-x86_64 安装在 /usr/bin/ 目录下才能正常define虚拟机。
然后再次重新编译升级qemu,指定 prefix=/usr/即可,命令如下:
root@ubuntu:/opt/qemu-2.0.# ./configure --prefix=/usr/ --target-list=x86_64-softmmu
root@ubuntu:/opt/qemu-2.0.# make
root@ubuntu:/opt/qemu-2.0.# make install
然后删除原来/usr/local/bin/目录下残留的qemu-*文件即可。