当前位置: > 虚拟化 Virtualization > KVM >

CentOS 6.0 下编译qemu-1.2.0-23.fc18.src.rpm

时间:2017-06-10 13:48来源:linux.it.net.cn 作者:IT
1、准备的镜像以及RPM包
(1)需要准备的ISO
CentOS-6.0-x86_64-bin-DVD1.iso
CentOS-6.0-x86_64-bin-DVD2.iso

(2)需要额外到CentOS 6.4或CentOS 6.3下载的如下安装包:
libjpeg-turbo-1.2.1-1.el6.x86_64.rpm
libjpeg-turbo-devel-1.2.1-1.el6.x86_64.rpm
libusb1-1.0.9-1.1.x86_64.rpm
libusb1-devel-1.0.9-1.1.x86_64.rpm
pixman-0.18.4-1.el6_0.1.x86_64.rpm
pixman-devel-0.18.4-1.el6_0.1.x86_64.rpm
spice-protocol-0.12.2-1.el6.noarch.rpm
spice-server-0.12.0-12.el6.x86_64.rpm
spice-server-devel-0.12.0-12.el6.x86_64.rpm

(3)下载qemu-1.2.0-23.fc18.src.rpm相关的SRPM包
需要到http://mirrors.ustc.edu.cn/fedora/linux/releases/18/Fedora/source/SRPMS/目录下载如下SRPM包
usbredir-0.5.2-1.fc18.src.rpm
libseccomp-1.0.1-0.fc18.src.rpm
qemu-1.2.0-23.fc18.src.rpm
如果rpm-build-4.8已经升级到rpm-build-4.9,那么systemtap也必须升级,需要额外下载如下包
systemtap-2.0-4.fc18.src.rpm
编译后安装如下包
rpm -ivh systemtap-2.0-4.el6.x86_64.rpm systemtap-client-2.0-4.el6.x86_64.rpm systemtap-devel-2.0-4.el6.x86_64.rpm systemtap-sdt-devel-2.0-4.el6.x86_64.rpm systemtap-runtime-2.0-4.el6.x86_64.rpm

2、制作本地YUM安装源
vi /etc/yum.repos.d/iso.repo
添加如下内容:
[CentOS6.0]
name = CentOS6.0
baseurl = file:///iso
          file:///iso2
enabled = 1
gpgcheck = 0

挂载ISO镜像
mount -o loop  CentOS-6.0-x86_64-bin-DVD1.iso /iso
mount -o loop  CentOS-6.0-x86_64-bin-DVD2.iso /iso2

3、使用rpmbuild重新编译qemu-1.2.0-23.fc18.src.rpm
rpmbuild --rebuild qemu-1.2.0-23.fc18.src.rpm

注意:这个过程中会提示缺少很多依赖的安装包,解决办法:
(1)用yum install从本地源中安装,注意提示的版本号得符合要求
(2)用rpm -ivh(或是升级安装rpm -Uvh)来安装额外从CentOS 6.4或CentOS 6.3中下载的RPM包
(3)用rpmbuild --rebuild来编译如下两个包
     usbredir-0.5.2-1.fc18.src.rpm
     libseccomp-1.0.1-0.fc18.src.rpm
     编译完成后生成的包如下:
     /root/rpmbuild/RPMS/x86_64/usbredir-server-0.5.2-1.el6.x86_64.rpm
     /root/rpmbuild/RPMS/x86_64/usbredir-devel-0.5.2-1.el6.x86_64.rpm
     /root/rpmbuild/RPMS/x86_64/usbredir-debuginfo-0.5.2-1.el6.x86_64.rpm
     /root/rpmbuild/RPMS/x86_64/usbredir-0.5.2-1.el6.x86_64.rpm
     /root/rpmbuild/RPMS/x86_64/libseccomp-1.0.1-0.el6.x86_64.rpm
     /root/rpmbuild/RPMS/x86_64/libseccomp-devel-1.0.1-0.el6.x86_64.rpm
     /root/rpmbuild/RPMS/x86_64/libseccomp-debuginfo-1.0.1-0.el6.x86_64.rpm
     根据需要用rpm -ivh(或rpm -Uvh)安装这些二进制包。


出现一些问题的处理:
(1)安装libseccomp-1.0.1-0.el6.x86_64.rpm出错
     rpm -ivh libseccomp-1.0.1-0.el6.x86_64.rpm
     error: Failed dependencies:
            kernel >= 3.5 is needed by libseccomp-1.0.1-0.el6.x86_64
     原因:因为CentOS 6.0内核版本为2.6.32-71.el6.x86_64,不符合其依赖的内核版本>= 3.5,测试过忽略这个依赖对编译qemu-kvm没有影响,编译出来的qemu-kvm可以在CentOS 6.0下正常运行。
     解决方法:
         rpm -ivh libseccomp-1.0.1-0.el6.x86_64.rpm --nodeps

(2)File not found: /root/rpmbuild/BUILDROOT/qemu-1.2.0-23.fc18.x86_64/usr/bin/vscclient
     原因:因为CentOS 6.0内核版本为2.6.32-71.el6.x86_64,这个涉及到smartcard nss 的支持,对于内核版本小于3.12.8的则不支持,所以就不编译vscclient,到最后打qemu-img这个包就找不到该文件。对于CentOS 6.0而言这个不是必须的,所以可以删除。
     /root/rpmbuild/SPECS/qemu.spec里部分关于smartcard nss 的说明:
     "  --disable-smartcard-nss  disable smartcard nss support"
     "  --enable-smartcard-nss   enable smartcard nss support"
     解决方法:
         vi /root/rpmbuild/SPECS/qemu.spec
         删除如下红色行:
         %files img
         �fattr(-,root,root)
         %{_bindir}/qemu-img
         %{_bindir}/qemu-io
         %{_bindir}/vscclient
         %{_mandir}/man1/qemu-img.1*
         然后执行:rpmbuild -ba /root/rpmbuild/SPECS/qemu.spec

(3)File must begin with "/": %{_unitdir}/qemu-guest-agent.service 
     原因: %{_unitdir}这个宏定义在Fedora release 18的rpmbuild 的宏定义配置文件中才有,对于CentOS 6.0而言是不存在的,再加上qemu-guest-agent.service  这个服务启动配置文件是针对Fedora release 18,对CentOS 6.0没有意义,所以可以删除掉。
     解决方法:
         vi /root/rpmbuild/SPECS/qemu.spec
         删除如下红色行:
         %files guest-agent
         �fattr(-,root,root,-)
         %doc COPYING README
         %{_bindir}/qemu-ga
         %{_unitdir}/qemu-guest-agent.service
         %{_udevdir}/99-qemu-guest-agent.rules
         然后执行:rpmbuild -ba /root/rpmbuild/SPECS/qemu.spec
  
(4)安装qemu-kvm-1.2.0-23.el6.x86_64.rpm报错
rpm -ivh qemu-kvm-1.2.0-23.el6.x86_64.rpm
error: Failed dependencies:
        ipxe-roms-qemu is needed by qemu-kvm-2:1.2.0-23.el6.x86_64
        qemu-common = 2:1.2.0-23.el6 is needed by qemu-kvm-2:1.2.0-23.el6.x86_64
        seabios-bin >= 0.6.0-2 is needed by qemu-kvm-2:1.2.0-23.el6.x86_64
        sgabios-bin is needed by qemu-kvm-2:1.2.0-23.el6.x86_64
        vgabios >= 0.6c-2 is needed by qemu-kvm-2:1.2.0-23.el6.x86_64
      原因:缺少这些依赖包
      解决办法:与步骤3一样,将这些依赖的包安装上即可。
          需要额外下载的RPM包:
          ipxe-roms-qemu-20120328-1.1.noarch.rpm        #可以直接安装
          sgabios-bin-0-0.3.20110621svn.el6.noarch.rpm  #可以直接安装
          vgabios-0.6c-2.fc14.noarch.rpm  #可以直接安装
          seabios-0.6.2-3.fc16.src.rpm    # 编译成 seabios-bin-0.6.2-3.el6.noarch.rpm 后再安装
          seabios-0.6.2-3.fc16.src.rpm 的下载地址:
          http://mirrors.ustc.edu.cn/fedora/linux/releases/16/Everything/source/SRPMS/
        
(5)安装qemu-common-1.2.0-23.el6.x86_64.rpm 报错
rpm -ivh qemu-common-1.2.0-23.el6.x86_64.rpm
error: Failed dependencies:
        systemd-units is needed by qemu-common-2:1.2.0-23.el6.x86_64
原因:systemd-units 只有Fedora release 18才有这个服务,对于CentOS 6.0不需要,可以去除该依赖关系
解决办法<1>:
     rpm -ivh qemu-common-1.2.0-23.el6.x86_64.rpm --nodeps
解决办法<2>:
     vi /root/rpmbuild/SPECS/qemu.spec
     将红色行删除
     %package  common
     Summary: QEMU common files needed by all QEMU targets
     Group: Development/Tools
     Requires(post): /usr/bin/getent
     Requires(post): /usr/sbin/groupadd
     Requires(post): /usr/sbin/useradd
     Requires(post): systemd-units
     Requires(preun): systemd-units
     Requires(postun): systemd-units
     按照CentOS 6.0的qemu-kvm-0.12.1.2-2.113.el6.x86_64.rpm的SPEC修改如下红色行:
     %post common
     if [ $1 -eq 1 ] ; then
         # Initial installation
         /bin/systemctl enable ksm.service >/dev/null 2>&1 || :
         /bin/systemctl enable ksmtuned.service >/dev/null 2>&1 || :
     fi

     getent group kvm >/dev/null || groupadd -g 36 -r kvm
     getent group qemu >/dev/null || groupadd -g 107 -r qemu
     getent passwd qemu >/dev/null || \
     useradd -r -u 107 -g qemu -G kvm -d / -s /sbin/nologin \
     -c "qemu user" qemu

     %preun common
     if [ $1 -eq 0 ] ; then
         # Package removal, not upgrade
         /bin/systemctl --no-reload disable ksmtuned.service > /dev/null 2>&1 || :
         /bin/systemctl --no-reload disable ksm.service > /dev/null 2>&1 || :
         /bin/systemctl stop ksmtuned.service > /dev/null 2>&1 || :
         /bin/systemctl stop ksm.service > /dev/null 2>&1 || :
     fi

     %postun common
     /bin/systemctl daemon-reload >/dev/null 2>&1 || :
     if [ $1 -ge 1 ] ; then
         # Package upgrade, not uninstall
         /bin/systemctl try-restart ksmtuned.service >/dev/null 2>&1 || :
         /bin/systemctl try-restart ksm.service >/dev/null 2>&1 || :
     fi
     然后执行:rpmbuild -ba /root/rpmbuild/SPECS/qemu.spec

(责任编辑:IT)
------分隔线----------------------------