(KVM连载)3.4 编译qemu-kvm和安装qemu-kvm

3.4 编译和安装qemu-kvm

除了在内核空间的KVM模块之外,在用户空间需要QEMU[注6]来模拟所需要CPU和设备模型以及用于启动客户机进程,这样才有了一个完整的KVM运行环境。而qemu-kvm是为了针对KVM专门做了修改和优化的QEMU分支[注7],在本书写作的2012年,qemu-kvm分支里面的小部分特性还没有完全合并进入到qemu的主干代码之中,所以本书中采用qemu-kvm来讲解。

在编译和安装了KVM并且启动到编译的内核之后,下面来看一下qemu-kvm的编译和安装。

3.4.1 下载qemu-kvm源代码

目前的QEMU项目针对KVM的代码分支qemu-kvm也是由Redhat公司的Gleb Natapov和Marcelo Tosatti作维护者(Maintainer),代码也是托管在kernel.org上。

qemu-kvm开发代码仓库的网页连接为:http://git.kernel.org/?p=virt/kvm/qemu-kvm.git

其中,可以看到有如下3个URL连接可供下载开发中的最新qemu-kvm的代码仓库。

git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git

http://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git

https://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git

可以根据自己实际需要选择3个中任一个用git clone命令下载即可,它们是完全一样的。

另外,可以到sourceforge.net的如下链接中根据需要下载qemu-kvm各个发布版本的代码压缩包(作者建议使用最新的正式发布版本,因为它的功能更多,同时也比较稳定)。

http://sourceforge.net/projects/kvm/files/qemu-kvm/

在本节讲解编译时,以下载开发中的最新的qemu-kvm.git为例,获取其代码仓库过程如下:

[root@jay-linux kvm_demo]# git clone\ git://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git qemu-kvm.git

Initialized empty Git repository in /root/kvm_demo/qemu-kvm.git/.git/

remote: Counting objects: 145222, done.

remote: Compressing objects: 100% (35825/35825), done.

remote: Total 145222 (delta 114656), reused 137663 (delta 107444)

Receiving objects: 100% (145222/145222), 40.83 MiB | 10.33 MiB/s, done.

Resolving deltas: 100% (114656/114656), done.

[root@jay-linux kvm_demo]# cd qemu-kvm.git

[root@jay-linux kvm.git]# pwd

/root/kvm_demo/qemu-kvm.git

3.4.2 配置和编译qemu-kvm

qemu-kvm的配置并不复杂,通常情况下,可以直接运行代码仓库中configure文件进行配置即可。当然,如果对其配置并不熟悉,可以运行“./configure --help”命令查看配置的一些选项及其帮助信息。

显示配置的帮助手册信息如下:

[root@jay-linux qemu-kvm.git]# ./configure --help

Usage: configure [options]

Options: [defaults in brackets after descriptions]

 

Standard options:

--help                   print this message

--prefix=PREFIX          install in PREFIX [/usr/local]

--interp-prefix=PREFIX   where to find shared libraries, etc.

use %M for cpu name [/usr/gnemul/qemu-%M]

--target-list=LIST       set target list (default: build everything)

Available targets: i386-softmmu x86_64-softmmu

<!- 此处省略百余行帮助信息的输出 ->

--disable-guest-agent    disable building of the QEMU Guest Agent

--enable-guest-agent     enable building of the QEMU Guest Agent

--with-coroutine=BACKEND coroutine backend. Supported options:

gthread, ucontext, sigaltstack, windows

 

NOTE: The object files are built at the place where configure is launched

执行configure文件进行配置的过程如下:

[root@jay-linux qemu-kvm.git]# ./configure

Install prefix    /usr/local

BIOS directory    /usr/local/share/qemu

binary directory  /usr/local/bin

library directory /usr/local/lib

include directory /usr/local/include

config directory  /usr/local/etc

Manual directory  /usr/local/share/man

ELF interp prefix /usr/gnemul/qemu-%M

Source path       /root/kvm_demo/qemu-kvm.git

C compiler        gcc

Host C compiler   gcc

<!-- 此处省略数十行 -->

VNC support       yes     #通常需要通过VNC连接到客户机中

<!-- 此处省略十余行 -->

KVM support       yes     #这是对KVM的支持

TCG interpreter   no

KVM device assig. yes    #这是对KVM中VT-d功能的支持

<!-- 此处省略十余行 -->

OpenGL support    yes

libiscsi support  no

build guest agent yes

coroutine backend ucontext

需要注意的是,上面命令行输出的KVM相关的选项需要是配置为yes,另外,一般VNC的支持也是配置为yes的(因为通常需要用VNC连接到客户机中)。

【2013.05.13 updated】 在configure时,可能遇到“glib-2.12 required to compile QEMU”的错误,是需要安装glib2和glib2-dev软件包,在RHEL上的安装命令为“yum install glib2 glib2-devel”,在Ubuntu上安装的过程为“apt-get install libglib2.0 libglib2.0-dev”。

 

经过配置之后,进行编译就很简单了,直接执行make即可进行编译,如下所示:

[root@jay-linux qemu-kvm.git]# make -j 20

GEN   config-host.h

GEN   trace.h

GEN   qemu-options.def

GEN   qmp-commands.h

GEN   qapi-types.h

GEN   qapi-visit.h

GEN   tests/test-qapi-types.h

GEN   tests/test-qapi-visit.h

GEN   tests/test-qmp-commands.h

CC    libcacard/cac.o

CC    libcacard/event.o

<!-- 此处省略数百行的编译时输出信息 -->

CC    x86_64-softmmu/target-i386/cpu.o

CC    x86_64-softmmu/target-i386/machine.o

CC    x86_64-softmmu/target-i386/arch_memory_mapping.o

CC    x86_64-softmmu/target-i386/arch_dump.o

CC    x86_64-softmmu/target-i386/kvm.o

CC    x86_64-softmmu/target-i386/hyperv.o

LINK  x86_64-softmmu/qemu-system-x86_64

可以看到,最后有编译生成qemu-system-x86_64文件,它就是我们常用的qemu-kvm的命令行工具(在多数Linux发行版中自带的qemu-kvm软件包的命令行是qemu-kvm,只是名字不同而已)。

3.4.2 安装qemu-kvm

编译完成之后,运行“make install”命令即可安装qemu-kvm,其过程如下:

[root@jay-linux qemu-kvm.git]# make install | tee make-install.log

install -d -m 0755 "/usr/local/share/qemu"

install -d -m 0755 "/usr/local/etc/qemu"

install -c -m 0644 /root/kvm_demo/qemu-kvm.git/sysconfigs/target/target-x86_64.conf "/usr/local/etc/qemu"

install -c -m 0644 /root/kvm_demo/qemu-kvm.git/sysconfigs/target/cpus-x86_64.conf "/usr/local/share/qemu"

install -d -m 0755 "/usr/local/bin"

install -c -m 0755  vscclient qemu-ga qemu-nbd qemu-img qemu-io  "/usr/local/bin"

install -d -m 0755 "/usr/local/libexec"

<!-- 此处省略数行的安装时输出信息 -->

make[1]: Entering directory /root/kvm_demo/qemu-kvm.git/x86_64-softmmu'

install -m 755 qemu-system-x86_64 "/usr/local/bin"

strip "/usr/local/bin/qemu-system-x86_64"

make[1]: Leaving directory /root/kvm_demo/qemu-kvm.git/x86_64-softmmu'

qemu-kvm的安装过程的主要任务有这几个:创建qemu的一些目录,拷贝一些配置文件到相应的目录下,拷贝一些firmware文件(如:sgabios.bin, kvmvapic.bin)到目录下以便qemu-kvm的命令行启动时可以找到对应的固件提供给客户机使用,拷贝keymaps到相应的目录下以便在客户机中支持各种所需键盘类型,拷贝qemu-system-x86_64、qemu-img等可执行程序到对应的目录下。下面的一些命令行检查了qemu-kvm被安装了之后的系统状态。

[root@jay-linux qemu-kvm.git]# which qemu-system-x86_64

/usr/local/bin/qemu-system-x86_64

[root@jay-linux qemu-kvm.git]# which qemu-img

/usr/local/bin/qemu-img

[root@jay-linux qemu-kvm.git]# ls /usr/local/share/qemu/

bamboo.dtb        mpc8544ds.dtb     petalogix-ml605.dtb       pxe-pcnet.rom    slof.bin            vgabios-vmware.bin

bios.bin          multiboot.bin     petalogix-s3adsp1800.dtb  pxe-rtl8139.rom  spapr-rtas.bin

cpus-x86_64.conf  openbios-ppc      ppc_rom.bin               pxe-virtio.rom   vgabios.bin

keymaps           openbios-sparc32  pxe-e1000.rom             qemu-icon.bmp    vgabios-cirrus.bin

kvmvapic.bin      openbios-sparc64  pxe-eepro100.rom          s390-zipl.rom    vgabios-qxl.bin

linuxboot.bin     palcode-clipper   pxe-ne2k_pci.rom          sgabios.bin      vgabios-stdvga.bin

[root@jay-linux qemu-kvm.git]# ls /usr/local/share/qemu/keymaps/

ar    common  de     en-gb  es  fi  fr     fr-ca  hr  is  ja  lv  modifiers  nl-be  pl  pt-br  sl  th

bepo  da      de-ch  en-us  et  fo  fr-be  fr-ch  hu  it  lt  mk  nl         no     pt  ru     sv  tr

由于qemu-kvm是用户空间的程序,安装之后不用重启系统,直接用qemu-system-x86_64、qemu-img这样的命令行工具即可使用qemu-kvm了。

master

Stay hungry, stay foolish.

59 Comments

  1. 你好,我qemu-kvm 编译安装成功了,virt-manager 也是通过源码编译安装的 (Virtual Machine Manager 0.9.1),但是在我 Create a new virtual machine 的时候 显示:
    Warning:KVM is not available. This may mean the KVM package is not installed, or the KVM kernel modules are not loaded. Your virtual machines my perform poorly.
    在 bash中输入kvm 显示:The program 'kvm' is currently not installed. You can install it by typing:
    sudo apt-get install qemu-kvm
    请求解决办法,谢谢~~~~

    • virt-manager我还没源码编译过呢,平时都是用qemu-kvm命令行操作,当然我写这本书的过程中我会提及virt-manager的。。
      关于你这个错误,它提示说kvm module没有load,你查询一下:
      [root@jay-linux ~]# lsmod | grep kvm
      kvm_intel 112487 0
      kvm 206544 1 kvm_intel
      参考我的博文:http://smilejay.cn/2012/06/kvm_installation/
      另外,也有一种可能是virt-manager中有配置文件指向qemu-kvm的命令行,自己编译的qemu-kvm可能名字为qemu-system-x86_64而不是叫做qemu-kvm,或者由于目录位置不对,导致virt-manager没找到qemu,所以报错。如果是这样,你需要修改virt-manager配置文件即可。还有,好像virt-manager需要libvirt的,你安装libvirt了吗?可在libvirt配置文件中指定你要使用的qemu-kvm的命令行工具?
      麻烦你后续跟进这个问题,非常愿意与你交流KVM相关的问题。

  2. 谢谢, 你客气了~
    我把 usr/local/bin 下的 qemu-system-x86_64 改为 qemu-kvm 了~~
    faintsmiles@ubuntu:/usr/local/bin$ ls
    celtdec051 qemu-ga qemu-io qemu-nbd snappy spicy-stats
    celtenc051 qemu-img qemu-kvm qemu-spice spicy

    faintsmiles@ubuntu:~$ lsmod | grep kvm
    kvm_intel 137721 0
    kvm 415549 1 kvm_intel
    我准备重新装一下kvm kernel 模块 再试一下

  3. 请问如果在qemu-kvm配置时加上spice的参数,是不是不能成功?提示spice这个feature没有。

    • 编译qemu-kvm时,估计没有把spice支持编进去,我这里看到默认运行”./configure“时,有输出”spice support no“。
      应该运行“./configure --enable-spice” 如果正常执行则会有”spice support yes"的提示。
      BTW,我对SPICE也不熟悉。。

  4. 你好
    这个系列对初学者从操作和原理上都有很好的指导意义
    请问能赚在么?(将注明出处与作者)

    • 可以转载部分文章,别把本系列文章全都转载了哦, 哈哈 ^_^

      • 非常感谢 在文章的指导下 终于成功编译并运行之前装好XP的IMG文件了。在CONFIGURE中将VNC显示更改为SDL。
        现在尝试源码调试QEMU中

  5. 这里的VNC support yes 是不是意味着qemu-kvm就会内置VNC server?因为我的ubuntu没有之前没有装过VNC server,编译完成了只装了VNCviewer,就可以连接到客户机了。

      • 您好,这是我的编译过程,由于之前提示undefined reference to timer_gettime'等,通过查询,我在configure时加上了-lrt,./configure --extra-ldflags=-lrt,但make后仍然报同样的错,求指导:
        以下为执行make后的输出:
        GEN x86_64-softmmu/config-devices.mak
        GEN config-all-devices.mak
        ...........
        CC qemu-error.o
        LINK qemu-ga
        qemu-timer.o: In function
        dynticks_rearm_timer':
        /kvm/qemu-kvm-1.2.0/qemu-timer.c:534: undefined reference to timer_gettime'
        /kvm/qemu-kvm-1.2.0/qemu-timer.c:547: undefined reference to
        timer_settime'
        qemu-timer.o: In function dynticks_stop_timer':
        /kvm/qemu-kvm-1.2.0/qemu-timer.c:520: undefined reference to
        timer_delete'
        qemu-timer.o: In function dynticks_start_timer':
        /kvm/qemu-kvm-1.2.0/qemu-timer.c:506: undefined reference to
        timer_create'
        collect2: error: ld returned 1 exit status
        make: *** [qemu-ga] Error 1

        • 你可以先查找librt.so的位置:find /usr/ -name "librt.so" (/usr/找不到,就到 / 目录下找)
          假设你找到了,为 /A/B/C/librt.so
          则,你可以vim /etc/ld.so.conf.d/my.conf 添加 /A/B/C 路径,然后运行“ldconfig”命令,之后再重新编译QEMU(加不加lrt应该没关系,我从来就没加过)

          • 我试过了,librt.so存在的,在/usr/lib/i386-linux-gnu下,我也把这个路径加进去了,但报的错误不变的。我上次按照你的这个编译,没有问题,最近是换了ubuntu13.04,重新编译了3.8的内核,现在就不对了(在发行版的默认内核下也是一样的报错)。不知道还有什么地方可能出问题?谢谢

        • 我最近使用了14.04 ubuntu,也遇到这个问题,发现有patch,贴在这,方便大家

          Signed-off-by: Roger Pau Monne
          ---
          Makefile | 4 ++--
          Makefile.target | 2 ++
          2 files changed, 4 insertions(+), 2 deletions(-)

          diff --git a/Makefile b/Makefile
          index 301c75e..e2c3cd4 100644
          --- a/Makefile
          +++ b/Makefile
          @@ -34,7 +34,7 @@ configure: ;

          $(call set-vpath, $(SRC_PATH):$(SRC_PATH)/hw)

          -LIBS+=-lz $(LIBS_TOOLS)
          +LIBS+=-lz -lm -lrt $(LIBS_TOOLS)

          ifdef BUILD_DOCS
          DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1 qemu-nbd.8
          QMP/qmp-commands.txt
          @@ -170,7 +170,7 @@ test-coroutine: test-coroutine.o qemu-timer-common.o
          async.o $(coroutine-obj-y)
          $(qapi-obj-y): $(GENERATED_HEADERS)
          qapi-dir := $(BUILD_DIR)/qapi-generated
          test-visitor.o test-qmp-commands.o qemu-ga$(EXESUF): QEMU_CFLAGS += -I
          $(qapi-dir)
          -qemu-ga$(EXESUF): LIBS = $(LIBS_QGA)
          +qemu-ga$(EXESUF): LIBS = $(LIBS_QGA) -lm

          $(qapi-dir)/test-qapi-types.c $(qapi-dir)/test-qapi-types.h :\
          $(SRC_PATH)/qapi-schema-test.json $(SRC_PATH)/scripts/qapi-types.py
          diff --git a/Makefile.target b/Makefile.target
          index a111521..95d6bc0 100644
          --- a/Makefile.target
          +++ b/Makefile.target
          @@ -33,6 +33,8 @@ endif
          PROGS=$(QEMU_PROG)
          STPFILES=

          +LIBS+=-lrt
          +
          ifndef CONFIG_HAIKU
          LIBS+=-lm
          endif

          • 不好意思,这个patch还是有问题。没有解决问题。

          • 确认按照如下的patch修改有效。看着缺什么自己修改吧。
            验证环境:
            qemu-kvm version: 1.2.0
            compile host: ubuntu 14.04
            --------------------------------------------
            +Signed-off-by: Natanael Copa
            +Signed-off-by: Blue Swirl
            +Signed-off-by: Ting Liu
            +---
            + configure | 9 +++++++--
            + 1 file changed, 7 insertions(+), 2 deletions(-)
            +
            +diff --git a/configure b/configure
            +index 999375a..29b3e30 100755
            +--- a/configure
            ++++ b/configure
            +@@ -2444,13 +2444,18 @@ fi
            + cat > $TMPC <<EOF
            + #include
            + #include
            +-int main(void) { clockid_t id; return clock_gettime(id, NULL); }
            ++int main(void) {
            ++ timer_create(CLOCK_REALTIME, NULL, NULL);
            ++ return clock_gettime(CLOCK_REALTIME, NULL);
            ++}
            + EOF
            +
            + if compile_prog "" "" ; then
            + :
            +-elif compile_prog "" "-lrt" ; then
            ++# we need pthread for static linking. use previous pthread test result
            ++elif compile_prog "" "-lrt $pthread_lib" ; then
            + LIBS="-lrt $LIBS"
            ++ libs_qga="-lrt $libs_qga"
            + fi
            +
            + if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \
            +--
            +1.7.9.7
            +

          • 你好,你这个补丁完整的文件在哪下载的啊?

  6. to syntax:
    你的是32位系统?我偶尔也用Ubuntu 12.04 (x86_64),在上面编译QEMU也没遇到问题。我看到默认有这个文件:/etc/ld.so.conf.d/i686-linux-gnu.conf 和x86_64-linux-gnu.conf ,里面内容为:
    /lib/i386-linux-gnu
    /usr/lib/i386-linux-gnu
    /lib/i686-linux-gnu
    /usr/lib/i686-linux-gnu

    • 是32位,而且我编译的是 qemu-kvm1.2.0这个版本,我的/etc/ld.so.conf.d/i686-linux-gnu.conf内容和你的完全一样.....但还是报错。有可能是是版本问题吗?

      • 我也不确定,没用过32bit Ubuntu编译qemu-kvm;我平时都用64bit的KVM,不过也有用32bit的RHEL6.x来编译KVM,没有遇到这样的问题。如果不是必须的话,建议你试着换系统编译,绕过一下吧。。

        • 我是linux菜鸟,还不太理解patch之类的东西,刚google到这个东西,好象是提交pacth的mail list,https://lists.yoctoproject.org/pipermail/meta-freescale/2013-February/001468.html
          这个和我的是一样的问题,但我没看懂该如何解决T_T,有空看一下吗?

          • 里面是说,你把configure文件中的“if compile_prog "" "" ; then”相关的逻辑,改为如下的,然后重新configure,重新编译试试吧。我不确定是否能解决你的问题,因为我都没遇到过你那样的错误。

            if compile_prog "" "" ; then
            :
            # we need pthread for static linking. use previous pthread test result
            elif compile_prog "" "-lrt $pthread_lib" ; then
            LIBS="-lrt $LIBS"
            libs_qga="-lrt $libs_qga"
            fi

  7. 由于最近比较急着用,我先换回ubuntu12.04了,编译正常,前面报的错是在ubntu13.04下编译的问题,估计是版本升级后出了一些问题吧,希望用ubuntu13.04的朋友们能注意一下。如果编译实在不过,就先降一下版本好了...再次谢谢你

  8. [root@KVM qemu-kvm.git]# ./configure
    glib-2.12 required to compile QEMU

    出现这个问题

    • yss :
      [root@KVM qemu-kvm.git]# ./configure
      glib-2.12 required to compile QEMU
      出现这个问题

      yum install glib*

      • 嗯 很好 谢谢反馈~ 这种缺神马包的错误 容易解决的;选择了折腾Linux,就得学会如何处理这些东西~

  9. 请问,如何制作qemu-kvm的rpm包,貌似没有看到qemu-kvm.spec控制文件

  10. 你好,我订购了一本您的书,在RHEL6.5平台下进行操作,在安装kernel和initramfs时发生如下错误:make install
    sh /home/Lg/kvm_demo/kvm.git/arch/x86/boot/install.sh 3.14.0-rc3+ arch/x86/boot/bzImage \
    System.map "/boot"
    ERROR: modinfo: could not find module ipt_MASQUERADE
    ERROR: modinfo: could not find module iptable_nat
    ERROR: modinfo: could not find module nf_nat
    ERROR: modinfo: could not find module mperf
    ERROR: modinfo: could not find module snd_page_alloc

    为什么呢?该如何解决?求指导。

  11. 大侠,照您说的这个问题已经解决了,但是在重启系统后,没能找到kvm和kvm_intel这两个模块,手动加载的时候提示说找不到这两个模块是为什么?
    modprobe kvm
    FATAL: Module kvm not found.

    • 你可检查一下你的.config文件中,是否有书中33页写的那些配置项目;在编译后的目录,find . -name "kvm.ko" 看看是否编译好这个ko文件。

  12. 大神,安装完虚拟机后如果我想在启动kvm的同时自动启动虚拟机能实现吗?要在那里面进行修改?

    • 当然能实现的。看你的需求了,如果是机器重启后自动启动虚拟机,可以写成service(在/etc/init.d/下写脚本),并且在/etc/rc.local之类的地方写配置全局网络(如bridge)之类的。多尝试吧~ 我曾经写过一些脚本,让机器启动后,自动跑很多kvm测试的case(其中当然得创建虚拟机)。

  13. 大神,关于这方面的资料有推荐的吗?我是第一次接触到KVM这方面,所以对好多东西不是很清楚,因此属于小白行列的。您曾经的例程方便给我一份吗?409816157@qq.com这是我邮箱,万分感谢!

    • 没有,这个是Linux管理员如何配置自动启动的程序的问题,多看看linux管理的东西吧。这个和kvm都没啥直接关系。

  14. 您好,今天根据你书中的办法进行kvm 的安装。在安装了virt-manager后,启动virt-manager,add new connection 后出现如下错误:
    Error polling connection 'qemu+ssh://root@192.168.12.15/system': internal error Cannot find suitable emulator for x86_64
    不知道是为何,在网上查看相应错误,据说是缺少安装了qemu-kvm-tool和qemu-kvm-guest-agent。
    但是qemu-kvm我是通过您给的如下地址编译安装的。http://sourceforge.net/projects/kvm/files/qemu-kvm/
    不知道您有没有什么解决办法。谢谢了。

    • 你的libvirtd没有启动吧? 另外,libvirt默认没用到自己编译的qemu,可参考书中294页“QEMU模拟器的配置”。

  15. 您好,我用的是Centos 6.5,X86_64,系统默认的QEMU是0.12.0,我编译了好几个QEMU版本,包括0.12.0的,修改/etc/libvirt/qemu目录下libvirt域里面的emulator指向了新的qemu版本,但是用virt-manager无法启动虚拟机,启动虚拟机时报错“Error starting domain: unsupported configuration: hda-duplex not supported in this QEMU binary”,请问这是怎么回事呢?

    • 你可以看下guest配置的xml文件中,是否有“hda-duplex"之类的东西;应该就是你的qemu版本太低了,见这个bug:https://bugzilla.redhat.com/show_bug.cgi?id=885464 别人提到的时qemu1.3 。 另外,你别看centos 6.5中的Qemu时0.12,它实际上也打了一些qemu新的patch的,和你自己编译的0.12有较大差别。

      • 您好,非常感谢您的回复。
        在/etc/libvirt/qemu目录下libvirt域的xml配置文件中,没有与hda-duplex相关的内容,我编译的QEMU包括1.7.0的版本也有这个问题。

        • 哦 那我就不知道了;你可看下 hda的配置是有的吧。你自己根据错误信息Google一下吧,还是挺多人遇到的,慢慢研究 :-)

          • 嗯,好的,感谢您的耐心回复。

          • 您好,这个问题我已经解决了,把方法放在这里希望能够帮助其它遇到相同问题的人。
            在XML配置文件里有三个地方需要修改:
            1)标签处需要修改位自己升级的QEMU二进制文件;
            2)
            hvm

            Centos为了提高QEMU的最大效率,会对QEMU打很多补丁,所以它的QEMU版本里面支持的架构里有'rhel6.5.0',而我们自己编译的QEMU版本,不支持此值,具体支持的值可以通过以下命令查看:
            ”qemu-kvm -M ?“
            “qemu-system-x86_64 -M ?”
            所以此处要把machine='rhel6.5.0'改为你的qemu版本支持的选项
            3)

            其中的model=ich6会生成hda-duplex之类的参数,而我们自己编译的QEMU不会支持此参数,运行时会报错“Error starting domain: unsupported configuration: hda-duplex not supported in this QEMU binary”,所以要么把这个设备删了,要么换另外一种模式
            把这几处修改后,通过升级后的QEMU虚拟机正常运行了。

          • 您好,这个问题我已经解决了,把方法放在这里希望能够帮助其它遇到相同问题的人。
            在XML配置文件里有三个地方需要修改:
            1)”“标签处需要修改位自己升级的QEMU二进制文件;
            2)”
            hvm


            Centos为了提高QEMU的最大效率,会对QEMU打很多补丁,所以它的QEMU版本里面支持的架构里有'rhel6.5.0',而我们自己编译的QEMU版本,不支持此值,具体支持的值可以通过以下命令查看:
            ”qemu-kvm -M ?“
            “qemu-system-x86_64 -M ?”
            所以此处要把machine='rhel6.5.0'改为你的qemu版本支持的选项
            3)”


            其中的model=ich6会生成hda-duplex之类的参数,而我们自己编译的QEMU不会支持此参数,运行时会报错“Error starting domain: unsupported configuration: hda-duplex not supported in this QEMU binary”,所以要么把这个设备删了,要么换另外一种模式
            把这几处修改后,通过升级后的QEMU虚拟机正常运行了。

  16. 按照书上的步骤,配置qemu-kvm成功,但便宜的时候出错,求大侠指导
    [root@localhost qemu-kvm.git]# ./configure
    Install prefix /usr/local
    BIOS directory /usr/local/share/qemu
    binary directory /usr/local/bin
    library directory /usr/local/lib
    libexec directory /usr/local/libexec
    include directory /usr/local/include
    config directory /usr/local/etc
    Manual directory /usr/local/share/man
    ELF interp prefix /usr/gnemul/qemu-%M
    Source path /root/kvm_demo/qemu-kvm.git
    C compiler gcc
    Host C compiler gcc
    Objective-C compiler gcc
    CFLAGS -O2 -D_FORTIFY_SOURCE=2 -g
    QEMU_CFLAGS -Werror -fPIE -DPIE -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fstack-protector-all -Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits
    LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g
    make make
    install install
    python python
    smbd /usr/sbin/smbd
    host CPU x86_64
    host big endian no
    target list x86_64-softmmu
    tcg debug enabled no
    gprof enabled no
    sparse enabled no
    strip binaries yes
    profiler no
    static build no
    -Werror enabled yes
    SDL support no
    curses support yes
    curl support no
    mingw32 support no
    Audio drivers oss
    Extra audio cards ac97 es1370 sb16 hda
    Block whitelist
    Mixer emulation no
    VirtFS support no
    VNC support yes
    VNC TLS support no
    VNC SASL support no
    VNC JPEG support no
    VNC PNG support no
    xen support no
    brlapi support no
    bluez support no
    Documentation no
    NPTL support yes
    GUEST_BASE yes
    PIE yes
    vde support no
    Linux AIO support no
    ATTR/XATTR support yes
    Install blobs yes
    KVM support yes
    TCG interpreter no
    fdt support no
    preadv support yes
    fdatasync yes
    madvise yes
    posix_madvise yes
    uuid support no
    libcap-ng support no
    vhost-net support yes
    Trace backend nop
    Trace output file trace-
    spice support no (/)
    rbd support no
    xfsctl support no
    nss used no
    usb net redir no
    OpenGL support no
    libiscsi support no
    build guest agent yes
    seccomp support no
    coroutine backend ucontext
    GlusterFS support no

    --------------------就是下面这步出错-----------------------------
    [root@localhost qemu-kvm.git]#
    [root@localhost qemu-kvm.git]# make
    GEN config-host.h
    GEN trace.h
    GEN trace.c
    CC block/qcow2-snapshot.o
    In file included from ./qemu-common.h:6:0,
    from block/qcow2-snapshot.c:25:
    block/qcow2-snapshot.c: In function ‘qcow2_write_snapshots’:
    ./compiler.h:36:23: error: typedef ‘qemu_build_bug_on__250’ locally defined but not used [-Werror=unused-local-typedefs]
    typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1];
    ^
    ./compiler.h:33:18: note: in definition of macro ‘cat’
    #define cat(x,y) x ## y
    ^
    ./compiler.h:36:18: note: in expansion of macro ‘cat2’
    typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1];
    ^
    block/qcow2-snapshot.c:249:5: note: in expansion of macro ‘QEMU_BUILD_BUG_ON’
    QEMU_BUILD_BUG_ON(offsetof(QCowHeader, snapshots_offset) !=
    ^
    cc1: all warnings being treated as errors
    make: *** [block/qcow2-snapshot.o] Error 1

    • 我随便找qemu来都可以编译的。你可以换新的试试,或者换老一点的qemu。你是用的那里的qemu,其git commit是多少?

      • 谢谢Jay哥的快速回复。
        应该是我之前的版本有问题,checkout qeum-kvm-1.1.0后问题解决了

  17. 谢谢Jay哥的快速回复。
    应该是我之前的版本有问题,checkout qeum-kvm-1.1.0后问题解决了

  18. 我和kvm_newbie有相同問題
    不知詳細過程為何
    謝謝!!

  19. 我和kvm_newbie有相同問題
    求怎么解决,为什么出现这个错误
    jay哥给力,回复我啊
    我用的cent os

    • kvm_newbie同学已经说了啊,就是某个版本的qemu编译才会遇到这个问题,git checkout到另外一个tag,再编译试试。

  20. 楼主你好,请问如何给已安装的qemu打补丁,还是说打补丁一定要重新编译源码?

    • 是的 一般需要编译源码;不过,你如果能得到编译好的二进制文件,直接拿来替换相应的文件也可以,不过一般都有其他多个文件关联。。

  21. 在函数‘qcow2_write_snapshots’中:
    ./compiler.h:36:23: 错误:typedef ‘qemu_build_bug_on__250’ locally defined but not used [-Werror=unused-local-typedefs]
    这个怎么处理阿?有人说 在Makefile里最后一行下添加新的一行:
    QEMU_CFLAGS+=-w就行了。但我试了后多出了一个错误。。

    • 感觉是该你说的那样:QEMU_CFLAGS+=-w
      你有进展吗?

faintsmiles进行回复 取消回复

邮箱地址不会被公开。 必填项已用*标注

*