QEMU修改及安裝包編譯
轉載自 靈躍雲 :原文鏈接
1. 前言
上一篇文章《虛擬化環境搭建及虛擬機創建》中,我們簡單介紹了虛擬化環境的搭建和虛擬機創建過程,本文我們將繼續介紹虛擬化環境中重要組件QEMU的修改和安裝包編譯。
我們使用上一篇文章中安裝的CentOS 7 X86_64位版本系統作為編譯環境。
2. QEMU修改及安裝包編譯
2.1源碼包下載
CentOS官方會跟隨Red Hat官方的節奏發布各個組件的新版本源碼(CentOS發布的源碼相比於Red Hat發布的源碼,其中最主要的改變其實是將源碼中的Red Hat替換為CentOS,避免侵權問題),讀者可以從http://vault.centos.org上下載,本文以當前最新的qemu-kvm-1.5.3-141.el7_4.4.src.rpm源碼包為例進行修改和編譯。
2.2源碼包直接編譯安裝包
下載得到源碼包之後,使用rpmbuild命令直接就可對其進行編譯生成安裝包,由於前文我們安裝的系統中,並沒有rpmbuild工具,這裏需要手動先安裝:
[lingyuecloud@lingyuecloud qemu-kvm]$ sudo yum install rpm-build |
然後,使用“--rebuild”參數直接編譯QEMU源碼包:
[lingyuecloud@lingyuecloud qemu-kvm]$ rpmbuild --rebuild qemu-kvm-1.5.3-141.el7_4.4.src.rpm Installing qemu-kvm-1.5.3-141.el7_4.4.src.rpm warning: user mockbuild does not exist - using root warning: group mockbuild does not exist - using root …… …… warning: user mockbuild does not exist - using root warning: group mockbuild does not exist - using root error: Failed build dependencies: zlib-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 SDL-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 gnutls-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 cyrus-sasl-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libtool is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libaio-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 pciutils-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 pulseaudio-libs-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libiscsi-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 ncurses-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libattr-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libusbx-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 usbredir-devel >= 0.6 is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 texinfo is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 spice-protocol >= 0.12.2 is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 spice-server-devel >= 0.12.0 is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libseccomp-devel >= 1.0.0 is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 gperftools-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libcurl-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 librados2-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 librbd1-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 glusterfs-api-devel >= 3.6.0 is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 glusterfs-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 systemtap is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 systemtap-sdt-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 nss-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libjpeg-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libpng-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libuuid-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 bluez-libs-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 brlapi-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 check-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libcap-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 pixman-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 rdma-core-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 cpp is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 lzo-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 snappy-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 libssh2-devel is needed by qemu-kvm-10:1.5.3-141.el7.centos.4.x86_64 |
命令輸出了很多warning(這裏省略了部分)。在編譯安裝包之前,首先會先安裝源碼rpm包(也就是解壓源碼包,通常解壓到~/rpmbuild/SOURCES/目錄下),這裏的warning的意思是說,我們下載的源碼包是以mockbuild用戶和mockbuild用戶組打包的(mock軟件、mockbuild用戶以及mockbuild組用來在chroot環境下編譯rpm包),而本地環境沒有mockbuild用戶和mockbuild用戶組來安裝源碼包,將會使用root用戶和root用戶組,這個warning並不影響編譯成功與否。為消除上述warning,執行下述命令。
[lingyuecloud@lingyuecloud qemu-kvm]$ sudo groupadd mockbuild [lingyuecloud@lingyuecloud qemu-kvm]$ sudo useradd -s /sbin/nologin -g mockbuild mockbuild |
接下來我們看後面的error,這些error指出編譯QEMU安裝包依賴指出的軟件,而他們並沒有被安裝。後面我們還將介紹到,rpmbuild命令之所以知道編譯QEMU需要這些軟件包,是因為這些依賴軟件被寫在了spec文件中。需要註意的是,編譯QEMU安裝包需要的這些依賴包,與運行QEMU需要的依賴包(安裝QEMU的時候會自動檢查)並不相同,雖然有些軟件包既在編譯QEMU的時候需要,也在運行QEMU的時候需要。
使用以下命令安裝所有依賴包:
[lingyuecloud@lingyuecloud qemu-kvm]$ sudo yum install zlib-devel SDL-devel gnutls-devel cyrus-sasl-devel libtool libaio-devel pciutils-devel pulseaudio-libs-devel libiscsi-devel ncurses-devel libattr-devel libusbx-devel usbredir-devel texinfo spice-protocol spice-server-devel libseccomp-devel gperftools-devel libcurl-devel librados2-devel librbd1-devel glusterfs-api-devel glusterfs-devel systemtap systemtap-sdt-devel nss-devel libjpeg-devel libpng-devel libuuid-devel bluez-libs-devel brlapi-devel check-devel libcap-devel pixman-devel rdma-core-devel cpp lzo-devel snappy-devel libssh2-devel |
然後再運行rpmbuild命令即可編譯成功:
[lingyuecloud@lingyuecloud qemu-kvm]$ rpmbuild --rebuild qemu-kvm-1.5.3-141.el7_4.4.src.rpm Installing qemu-kvm-1.5.3-141.el7_4.4.src.rpm Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.wu0DxD + umask 022 + cd /home/lingyuecloud/rpmbuild/BUILD + cd /home/lingyuecloud/rpmbuild/BUILD + rm -rf qemu-1.5.3 + /usr/bin/tar -xf - + /usr/bin/bzip2 -dc /home/lingyuecloud/rpmbuild/SOURCES/qemu-1.5.3.tar.bz2 + STATUS=0 + ‘[‘ 0 -ne 0 ‘]‘ + cd qemu-1.5.3 + /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w . + cp /home/lingyuecloud/rpmbuild/SOURCES/bios-256k.bin pc-bios + tar -xf /home/lingyuecloud/rpmbuild/SOURCES/sample_images.tar + echo ‘Patch #1 (0000-libcacard-fix-missing-symbols-in-libcacard.so.patch):‘ Patch #1 (0000-libcacard-fix-missing-symbols-in-libcacard.so.patch): + /usr/bin/patch -p1 --fuzz=0 + /usr/bin/cat /home/lingyuecloud/rpmbuild/SOURCES/0000-libcacard-fix-missing-symbols-in-libcacard.so.patch patching file libcacard/Makefile …… …… Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.x6IUsO + umask 022 + cd /home/lingyuecloud/rpmbuild/BUILD + cd qemu-1.5.3 + buildarch=x86_64-softmmu + extraldflags=-Wl,--build-id + buildldflags=VL_LDFLAGS=-Wl,--build-id + dobuild --target-list=x86_64-softmmu +./configure --prefix=/usr --libdir=/usr/lib64 --sysconfdir=/etc --interp-prefix=/usr/qemu-%M --audio-drv-list=pa,alsa --with-confsuffix=/qemu-kvm --localstatedir=/var --libexecdir=/usr/libexec --with-pkgversion=qemu-kvm-1.5.3-141.el7.centos.4 --disable-strip --disable-qom-cast-debug ‘--extra-ldflags=-Wl,--build-id -pie -Wl,-z,relro -Wl,-z,now‘ ‘--extra-cflags=-O2 -g -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIE -DPIE‘ --enable-trace-backend=dtrace --enable-werror --disable-xen --disable-virtfs --enable-kvm --enable-libusb --enable-spice --enable-seccomp --disable-fdt --enable-docs --disable-sdl --disable-debug-tcg --disable-sparse --disable-brlapi --disable-bluez --disable-vde --disable-curses --enable-curl --enable-libssh2 --enable-vnc-tls --enable-vnc-sasl --enable-linux-aio --enable-smartcard-nss --enable-lzo --enable-snappy --enable-usb-redir --enable-vnc-png --disable-vnc-jpeg --enable-vnc-ws --enable-uuid --disable-vhost-scsi --disable-guest-agent --disable-live-block-ops --disable-live-block-migration --enable-rbd --enable-glusterfs --enable-tcmalloc --block-drv-rw-whitelist=qcow2,raw,file,host_device,blkdebug,nbd,iscsi,gluster,rbd --block-drv-ro-whitelist=vmdk,vhdx,vpc,ssh,https --iasl=/bin/false --target-list=x86_64-softmmu Install prefix /usr BIOS directory /usr/share/qemu-kvm binary directory /usr/bin library directory /usr/lib64 libexec directory /usr/libexec include directory /usr/include config directory /etc local state directory /var Manual directory /usr/share/man ELF interp prefix /usr/qemu-%M Source path /home/lingyuecloud/rpmbuild/BUILD/qemu-1.5.3 C compiler cc Host C compiler cc Objective-C compiler cc CFLAGS -O2 -D_FORTIFY_SOURCE=2 -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -g QEMU_CFLAGS -Werror -DHAS_LIBSSH2_SFTP_FSYNC -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 -O2 -g -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIE -DPIE -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 -fstack-protector-strong -I/usr/include/p11-kit-1 -I/usr/include/libpng15 -I/usr/include/spice-server -I/usr/include/cacard -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/nss3 -I/usr/include/nspr4 -I/usr/include/spice-1 -I/usr/include/nss3 -I/usr/include/nspr4 -pthread -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libusb-1.0 -I/usr/include/pixman-1 LDFLAGS -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g -Wl,--build-id -pie -Wl,-z,relro -Wl,-z,now make make install install python python smbd /usr/sbin/smbd host CPU x86_64 host big endian no target list x86_64-softmmu …… …… Processing files: qemu-kvm-debuginfo-1.5.3-141.el7.centos.4.x86_64 Provides: qemu-kvm-debuginfo = 10:1.5.3-141.el7.centos.4 qemu-kvm-debuginfo(x86-64) = 10:1.5.3-141.el7.centos.4 Requires(rpmlib): rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1 Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/lingyuecloud/rpmbuild/BUILDROOT/qemu-kvm-1.5.3-141.el7_4.4.x86_64 Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-1.5.3-141.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-img-1.5.3-141.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-common-1.5.3-141.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-tools-1.5.3-141.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-debuginfo-1.5.3-141.el7.centos.4.x86_64.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.5aHHpJ + umask 022 + cd /home/lingyuecloud/rpmbuild/BUILD + cd qemu-1.5.3 + /usr/bin/rm -rf /home/lingyuecloud/rpmbuild/BUILDROOT/qemu-kvm-1.5.3-141.el7_4.4.x86_64 + exit 0 Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.qutzZw + umask 022 + cd /home/lingyuecloud/rpmbuild/BUILD + rm -rf qemu-1.5.3 + exit 0 |
整個編譯過程中輸出的日誌非常長,我們這裏只截取了部分。從輸出日誌的開始可以看到,編譯過程中首先是打Patch(後面我們會將源碼rpm包解開,可以看到裏面有很多Patch),然後spec文件會根據當前環境選擇configure參數進行configure,然後執行編譯。最後,“Wrote:/home/lingyuecloud/rpmbuild/RPMS/x86_64/******.rpm”是編譯完成後輸出的rpm安裝包,可使用“rpm -ivh ******.rpm”命令來安裝即可。
使用源碼包直接編譯是最簡單的編譯方法,但是其缺點是我們沒有對源碼或者編譯過程進行修改,接下來我們將介紹如何修改源碼並編譯。
2.3源碼包解壓編譯安裝包
2.3.1 源碼包文件分析
首先使用命令對源碼包進行解壓,看看其中包含的文件:
[lingyuecloud@lingyuecloud qemu]$ rpm2cpio qemu-kvm-1.5.3-141.el7_4.4.src.rpm | cpio -di 64177 blocks [lingyuecloud@lingyuecloud qemu]$ ls 0000-libcacard-fix-missing-symbols-in-libcacard.so.patch 80-kvm.rules 99-qemu-guest-agent.rules bios-256k.bin block-add-block-driver-read-only-whitelist.patch bridge.conf change-path-from-qemu-to-qemu-kvm.patch disable-hpet-device.patch …… …… e1000-Keep-capabilities-list-bit-on-for-older-RHEL-machine-types.patch ksmctl.c ksm.service ksm.sysconfig ksmtuned ksmtuned.conf ksmtuned.service kvm-ac97-register-reset-via-qom.patch …… …… qemu-1.5.3.tar.bz2 qemu.binfmt qemu-ga.sysconfig qemu-guest-agent.service qemu-kvm-1.5.3-141.el7_4.4.src.rpm qemu-kvm-Fix-migration-from-older-version-due-to-i8254-changes.patch qemu-kvm.spec qxl-set-revision-to-1-for-rhel6-0-0.patch README.rhel6-gpxe-source rename-man-page-to-qemu-kvm.patch rhel6-e1000.rom rhel6-ne2k_pci.rom rhel6-pcnet.rom rhel6-rtl8139.rom rhel6-virtio.rom sample_images.tar target-i386-set-level-4-on-conroe-penryn-nehalem.patch target-i386-update-model-values-on-conroe-penryn-nehalem-cpu-models.patch use-kvm-by-default.patch vga-Default-vram_size_mb-to-16-like-prior-versions-of-RHEL.patch vmdk-Allow-reading-variable-size-descriptor-files.patch vmdk-refuse-to-open-higher-version-than-supported.patch …… |
其中包含了幾部分,主要包括:patch文件(1746個,此處省略了部分)、QEMU官方release的源碼包(qemu-1.5.3.tar.bz2)、編譯QEMU的時候用到的其他源碼及資源文件,以及控制編譯的spec文件(qemu-kvm.spec)。
spec文件內容非常多,關於spec文件的語法等知識,有興趣的讀者可以參閱Fedora官方文檔Creating RPM Packages with Fedora。這裏,我們簡單看下spec文件中的部分內容:
[lingyuecloud@lingyuecloud qemu]$ cat qemu-kvm.spec …… %define pkgname qemu-kvm %define rhel_suffix -rhel %define rhev_suffix -rhev …… Summary: QEMU is a machine emulator and virtualizer Name: %{pkgname}%{?pkgsuffix} Version: 1.5.3 Release: 141%{?dist}.4 # Epoch because we pushed a qemu-1.0 package. AIUI this can‘t ever be dropped Epoch: 10 License: GPLv2+ and LGPLv2+ and BSD Group: Development/Tools URL: http://www.qemu.org/ ExclusiveArch: x86_64 %{power64} aarch64 s390x Requires: seabios-bin >= 1.7.2.2-5 Requires: sgabios-bin Requires: seavgabios-bin Requires: ipxe-roms-qemu …… …… Source0: http://wiki.qemu-project.org/download/qemu-%{version}.tar.bz2
Source1: qemu.binfmt …… BuildRequires: zlib-devel BuildRequires: SDL-devel BuildRequires: which BuildRequires: gnutls-devel BuildRequires: cyrus-sasl-devel BuildRequires: libtool BuildRequires: libaio-devel BuildRequires: rsync BuildRequires: python BuildRequires: pciutils-devel BuildRequires: pulseaudio-libs-devel BuildRequires: libiscsi-devel BuildRequires: ncurses-devel BuildRequires: libattr-devel BuildRequires: libusbx-devel …… …… |
其中,“Version和Release”控制了最終輸出rpm包的版本號,其中的dist變量在我們環境中值為.el7.centos。“Source0”值指定了源碼包的下載路徑,本地編譯的時候,不會從這個url去下載源碼,只會根據這個url末尾的文件名從本地尋找源碼包(本例中為qemu-1.5.3.tar.bz2),若用戶希望將修改後的源碼打包為.tar.gz格式或其他格式,修改此處url中的後綴名即可。“Requires”字段指定了編譯生成的QEMU安裝包在安裝時所需要的依賴軟件,“BuildRequires”指定了在編譯時依賴的軟件包。
2.3.2 編譯安裝包
要編譯rpm包,只需將前文解壓出來的所有文件復制到編譯目錄“~/rpmbuild/SOURCES/”(執行安裝命令“rpm -ivh qemu-kvm-1.5.3-141.el7_4.4.src.rpm”也會將所需文件解壓到編譯目錄),然後執行編譯命令即可編譯成功。
[lingyuecloud@lingyuecloud SOURCES]$ rpmbuild -bb qemu-kvm.spec |
接下來,我們修改qemu-1.5.3.tar.bz2中的源碼。需要特別註意的是,因為spec文件中有打Patch的過程,對qemu-1.5.3.tar.bz2源碼的修改很可能導致後續的打Patch過程失敗,所以,實際進行項目開發時,通常是首先將Patch打完,之後註釋掉spec文件中打Patch的過程,最後在此基礎上進行開發。
由於Patch較多,本文演示的改動較小,因此暫時先不打Patch,直接修改源碼進行編譯。
首先解壓qemu-1.5.3.tar.bz2:
[lingyuecloud@lingyuecloud SOURCES]$ tar -jxf qemu-1.5.3.tar.bz2 [lingyuecloud@lingyuecloud SOURCES]$ cd qemu-1.5.3 |
編輯vl.c文件,在QEMU的main_loop函數中增加一行日誌:
…… …… static void main_loop(void) { bool nonblocking; int last_io = 0; #ifdef CONFIG_PROFILER int64_t ti; #endif fprintf(stderr, "Hello, welcome to lingyuecloud.com\n"); do { nonblocking = !kvm_enabled() && !xen_enabled() && last_io > 0; #ifdef CONFIG_PROFILER ti = profile_getclock(); #endif last_io = main_loop_wait(nonblocking); #ifdef CONFIG_PROFILER dev_time += profile_getclock() - ti; #endif } while (!main_loop_should_exit()); } …… …… |
然後修改spec文件,更新release版本號以示區別:
…… Summary: QEMU is a machine emulator and virtualizer Name: %{pkgname}%{?pkgsuffix} Version: 1.5.3 Release: 141.20171220.lingyuecloud%{?dist}.4 # Epoch because we pushed a qemu-1.0 package. AIUI this can‘t ever be dropped Epoch: 10 License: GPLv2+ and LGPLv2+ and BSD …… …… |
將修改後的源碼打包並編譯:
[lingyuecloud@lingyuecloud SOURCES]$ mv qemu-1.5.3.tar.bz2 qemu-1.5.3.tar.gz.bak [lingyuecloud@lingyuecloud SOURCES]$ tar -jcf qemu-1.5.3.tar.bz2 qemu-1.5.3 [lingyuecloud@lingyuecloud SOURCES]$ rpmbuild -bb qemu-kvm.spec …… …… Processing files: qemu-kvm-debuginfo-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64 Provides: qemu-kvm-debuginfo = 10:1.5.3-141.20171220.lingyuecloud.el7.centos.4 qemu-kvm-debuginfo(x86-64) = 10:1.5.3-141.20171220.lingyuecloud.el7.centos.4 Requires(rpmlib): rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(CompressedFileNames) <= 3.0.4-1 Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/lingyuecloud/rpmbuild/BUILDROOT/qemu-kvm-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64 Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-img-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-common-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-tools-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm Wrote: /home/lingyuecloud/rpmbuild/RPMS/x86_64/qemu-kvm-debuginfo-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.0ckghW + umask 022 + cd /home/lingyuecloud/rpmbuild/BUILD + cd qemu-1.5.3 + /usr/bin/rm -rf /home/lingyuecloud/rpmbuild/BUILDROOT/qemu-kvm-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64 + exit 0 |
可以看到,輸出的rpm包版本號已經更新為我們設置的版本號。
接下來,我們更新安裝編譯好的rpm包,以檢查我們的源碼修改是否生效:
[lingyuecloud@lingyuecloud SOURCES]$ cd /home/lingyuecloud/rpmbuild/RPMS/x86_64/ [lingyuecloud@lingyuecloud x86_64]$ sudo rpm -Uvh qemu-kvm-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm qemu-img-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm qemu-kvm-common-1.5.3-141.20171220.lingyuecloud.el7.centos.4.x86_64.rpm [sudo] password for lingyuecloud: Preparing... ################################# [100%] Updating / installing... 1:qemu-kvm-common-10:1.5.3-141.2017################################# [ 17%] 2:qemu-img-10:1.5.3-141.20171220.li################################# [ 33%] 3:qemu-kvm-10:1.5.3-141.20171220.li################################# [ 50%] Cleaning up / removing... 4:qemu-kvm-10:1.5.3-141.el7 ################################# [ 67%] 5:qemu-img-10:1.5.3-141.el7 ################################# [ 83%] 6:qemu-kvm-common-10:1.5.3-141.el7 ################################# [100%] |
然後,按照《虛擬化環境搭建及虛擬機創建》文章所述,使用libvirt啟動虛擬機,查看虛擬機日誌(在目錄“~/.cache/libvirt/qemu/log/”下面,文件名為虛擬機名),即可看到我們加入的日誌,如圖所示:
圖1 虛擬機的QEMU日誌
2.4 Configure & Make
除了使用spec文件來編譯完整的安裝包之外,還可以在源碼目錄中直接使用configure和make命令進行編譯。這種方式的好處是編譯過一次之後,只要沒有清除編譯結果(執行“make clean”命令),下次編譯將只會編譯修改了源碼的部分文件,大大節省了時間。當然,該方式也存在缺點:首先是編譯過程依賴的軟件包不清晰,如果遇到依賴的軟件不存在,出錯提示信息也並不直觀;其次,使用rpmbuild方式編譯安裝包時,可以在spec文件中加入測試過程,對編譯完成的文件進行一些測試,確保生成的安裝包功能正常,而采用Configure & Make方式編譯,測試過程需要手動執行;再次,編譯生成的文件並沒有很好的組織起來,不便於安裝到其他環境運行。Configure & Make編譯方式通常在開發過程中使用,軟件發布時一般不會使用該編譯方式。
在前文解壓qemu-1.5.3源碼目錄中,執行./configure(configure後面可加參數,如果沒有加參數,configure過程將會自動進行。讀者可參考前文rpmbuild日誌中的configure參數,或者執行“./configure --help”命令查看各個參數的含義),然後執行make命令即可進行編譯。由於前文已經將編譯需要的依賴軟件安裝完成,此處的編譯將會很順利的完成,讀者可自行嘗試。
3. 總結
本文簡要介紹了虛擬化組件QEMU的安裝包編譯過程,簡單修改了QEMU源碼,並驗證了修改的有效性。由於篇幅所限,控制rpm編譯過程的spec文件,以及QEMU的源碼分析等,都並沒有深入展開敘述,後續的文章中,我們將陸續介紹,敬請期待。
QEMU修改及安裝包編譯