在 CentOS 7.0 上源码安装 Xen 4.5

上周 CentOS 7.0 正式版发布了,Xen4CentOS 项目还没来得及更新支持 CentOS 7.0,所以目前要在 CentOS 7.0 上玩 Xen 的唯一办法只有编译源代码了。貌似这次 CentOS 没有发布 Minimal 安装版,下面的编译安装步骤在 LiveCD 安装版(CentOS-7.0-1406-x86_64-livecd.iso)上完成。

安装需要的软件包

安装完 CentOS 7.0 后第一件事就是启动 SSH 以便能从另外一台机器访问,新版本的 CentOS 引入了有争议的 systemd 进程管理器替代了 Unix 传统的 init 系统。开启服务使用 systemctl 命令:

# systemctl start sshd# systemctl enable sshd

更新系统,并且安装编译 Xen 所需要的编译器、工具、软件库等:

# yum update# yum groupinstall "Development Tools"# yum install -y gcc gcc-c++ git patch texinfo# yum install -y python-devel acpica-tools libuuid-devel ncurses-devel glib2 glib2-devel libaio-devel openssl-devel yajl-devel glibc-devel glibc-devel.i686 pixman-devel# wget http://mirror.centos.org/centos/6/os/x86_64/Packages/dev86-0.16.17-15.1.el6.x86_64.rpm# rpm -ivh dev86-0.16.17-15.1.el6.x86_64.rpm

安装 Xen

下载最新的 xen 源代码、编译、安装,目前最新的代码是 xen 4.5-unstable:

# git clone git://xenbits.xen.org/xen.git# cd xen/# ./configure# make dist# make install

安装 dom0 内核

下载最新的 Linux 内核源代码,配置 dom0 内核、编译、安装,注意 dom0 内核需要选择下面一些内核选项:

# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.15.4.tar.xz# tar xf linux-3.15.4.tar.xz# cd linux-3.15.4/# make menuconfig# vi .config...CONFIG_X86_IO_APIC=yCONFIG_ACPI=yCONFIG_ACPI_PROCFS=y (optional)CONFIG_XEN_DOM0=yCONFIG_PCI_XEN=yCONFIG_XEN_DEV_EVTCHN=yCONFIG_XENFS=yCONFIG_XEN_COMPAT_XENFS=yCONFIG_XEN_SYS_HYPERVISOR=yCONFIG_XEN_GNTDEV=yCONFIG_XEN_BACKEND=yCONFIG_XEN_NETDEV_BACKEND=mCONFIG_XEN_BLKDEV_BACKEND=mCONFIG_XEN_PCIDEV_BACKEND=mCONFIG_XEN_BALLOON=yCONFIG_XEN_SCRUB_PAGES=y...# make# make modules# make modules_install# make install

配置 Grub

配置 grub2,加上带 Xen 的 Linux dom0 内核:

# grub2-mkconfig -o /etc/grub2.cfg# vi /etc/grub2.cfg# vi /etc/grub.d/40_custom#!/bin/shexec tail -n +3 $0# This file provides an easy way to add custom menu entries.  Simply type the# menu entries you want to add after this comment.  Be careful not to change# the 'exec tail' line above.menuentry 'CentOS Linux, with Linux 3.15.4 Xen' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.15.4-advanced-aa64a6a3-518e-4a7c-9e88-2f3f33c8c700' {        load_video        insmod gzio        insmod part_msdos        insmod xfs        set root='hd0,msdos1'        if [ x$feature_platform_search_hint = xy ]; then          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  6bc61a5c-12e3-4711-9532-61760367e0dc        else          search --no-floppy --fs-uuid --set=root 6bc61a5c-12e3-4711-9532-61760367e0dc        fi        multiboot /xen.gz        module /vmlinuz-3.15.4 root=UUID=aa64a6a3-518e-4a7c-9e88-2f3f33c8c700 ro rd.lvm.lv=cl/root vconsole.font=latarcyrheb-sun16 crashkernel=auto  vconsole.keymap=us rd.lvm.lv=cl/swap rhgb quiet        module /initramfs-3.15.4.img}# grub2-mkconfig -o /etc/grub2.cfg

可能出现的错误和解决办法

重启后,选择 CentOS Linux, with Linux 3.15.4 Xen 进入 Xen 系统,使用 xl info 命令发现有错,这是因为 Xen 相关的软件库被安装到了 /usr/local/lib 目录,系统找不到。所以做一些链接就可以了:

# xl infoxl: error while loading shared libraries: libxlutil.so.4.3: cannot open shared object file: No such file or directory# cd /usr/lib/# ln -s /usr/local/lib/libxlutil.so.4.3.0 libxlutil.so.4.3# ln -s /usr/local/lib/libxlutil.so.4.3.0 libxlutil.so# ln -s /usr/local/lib/libxenlight.so.4.5.0 libxenlight.so.4.5# ln -s /usr/local/lib/libxenlight.so.4.5.0 libxenlight.so# ln -s /usr/local/lib/libxenctrl.so.4.5.0 libxenctrl.so.4.5# ln -s /usr/local/lib/libxenguest.so.4.5.0 libxenguest.so.4.5# ln -s /usr/local/lib/libxenguest.so.4.5.0 libxenguest.so# ln -s /usr/local/lib/libxenstat.so.0.0 libxenstat.so.0# ln -s /usr/local/lib/libxenstat.so.0.0 libxenstat.so# ln -s /usr/local/lib/libxenstore.so.3.0.3 libxenstore.so.3.0# ln -s /usr/local/lib/libxenstore.so.3.0.3 libxenstore.so# ln -s /usr/local/lib/libxenvchan.so.1.0.0 libxenvchan.so.1.0# ln -s /usr/local/lib/libxenvchan.so.1.0.0 libxenvchan.so# ln -s /usr/local/lib/libblktapctl.so.1.0.0 libblktapctl.so.1.0# ln -s /usr/local/lib/libblktapctl.so.1.0.0 libblktapctl.so# ldconfig

再次运行 xl info 发现如下问题:

# xl infoxc: error: Could not obtain handle on privileged command interface (2 = No such file or directory): Internal errorlibxl: error: libxl.c:99:libxl_ctx_alloc: cannot open libxc handle: No such file or directorycannot init xl context

是因为没有挂载 xenfs 的缘故,挂载一下就可以了:

# modprobe xenfs# mount -t xenfs xenfs /proc/xen# ls /proc/xen/capabilities  privcmd  xenbus  xsd_kva  xsd_port# xl infohost                   : localhost.localdomainrelease                : 3.15.4version                : #1 SMP Fri Jul 11 09:37:12 SAST 2014machine                : x86_64nr_cpus                : 4max_cpu_id             : 3nr_nodes               : 1cores_per_socket       : 2threads_per_core       : 2cpu_mhz                : 2195hw_caps                : bfebfbff:28100800:00000000:00003f00:15bae3bf:00000000:00000001:00000000virt_caps              : hvmtotal_memory           : 3959free_memory            : 127sharing_freed_memory   : 0sharing_used_memory    : 0outstanding_claims     : 0free_cpus              : 0xen_major              : 4xen_minor              : 5xen_extra              : -unstablexen_version            : 4.5-unstablexen_caps               : xen-3.0-x86_64 xen-3.0-x86_32p hvm-3.0-x86_32 hvm-3.0-x86_32p hvm-3.0-x86_64xen_scheduler          : creditxen_pagesize           : 4096platform_params        : virt_start=0xffff800000000000xen_changeset          : Wed Jul 9 13:30:54 2014 +0100 git:7579169-dirtyxen_commandline        :cc_compiler            : gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)cc_compile_by          : rootcc_compile_domain      : localdomaincc_compile_date        : Fri Jul 11 08:49:06 SAST 2014xend_config_format     : 4

记得启动 xencommons 哦,以前旧版本的 xend 已经被 xencommons 替代了:

# /etc/init.d/xencommons startStarting C xenstored...Setting domain 0 name and domid...Starting xenconsoled...Starting QEMU as disk backend for dom0# xl listName                                        ID   Mem VCPUsStateTime(s)Domain-0                                     0  3779     4     r-----     105.5

Xen 从 4.1 版本开始引入了新版工具集 xl/libxl,并在后续的版本中逐步替代旧的 xm/xend,在 4.5 版本中已经完全删除了 xm/xend.

以前的版本可参考:

在 CentOS 6.x 上安装和配置 Xen在 CentOS 5.x 上安装和配置 Xen在 CentOS 5.x 上源码安装 Xen

在 CentOS 7.0 上源码安装 Xen 4.5

相关文章:

你感兴趣的文章:

标签云: