貌似这次 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=y
CONFIG_ACPI=y
CONFIG_ACPI_PROCFS=y (optional)
CONFIG_XEN_DOM0=y
CONFIG_PCI_XEN=y
CONFIG_XEN_DEV_EVTCHN=y
CONFIG_XENFS=y
CONFIG_XEN_COMPAT_XENFS=y
CONFIG_XEN_SYS_HYPERVISOR=y
CONFIG_XEN_GNTDEV=y
CONFIG_XEN_BACKEND=y
CONFIG_XEN_NETDEV_BACKEND=m
CONFIG_XEN_BLKDEV_BACKEND=m
CONFIG_XEN_PCIDEV_BACKEND=m
CONFIG_XEN_BALLOON=y
CONFIG_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/sh
exec 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 info
xl: 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 info
xc: error: Could not obtain handle on privileged command interface (2 = No such file or directory): Internal error
libxl: error: libxl.c:99:libxl_ctx_alloc: cannot open libxc handle: No such file or directory
cannot init xl context
是因为没有挂载 xenfs 的缘故,挂载一下就可以了:
# modprobe xenfs
# mount -t xenfs xenfs /proc/xen
# ls /proc/xen/
capabilities privcmd xenbus xsd_kva xsd_port
# xl info
host : localhost.localdomain
release : 3.15.4
version : #1 SMP Fri Jul 11 09:37:12 SAST 2014
machine : x86_64
nr_cpus : 4
max_cpu_id : 3
nr_nodes : 1
cores_per_socket : 2
threads_per_core : 2
cpu_mhz : 2195
hw_caps : bfebfbff:28100800:00000000:00003f00:15bae3bf:00000000:00000001:00000000
virt_caps : hvm
total_memory : 3959
free_memory : 127
sharing_freed_memory : 0
sharing_used_memory : 0
outstanding_claims : 0
free_cpus : 0
xen_major : 4
xen_minor : 5
xen_extra : -unstable
xen_version : 4.5-unstable
xen_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_64
xen_scheduler : credit
xen_pagesize : 4096
platform_params : virt_start=0xffff800000000000
xen_changeset : Wed Jul 9 13:30:54 2014 +0100 git:7579169-dirty
xen_commandline :
cc_compiler : gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)
cc_compile_by : root
cc_compile_domain : localdomain
cc_compile_date : Fri Jul 11 08:49:06 SAST 2014
xend_config_format : 4
记得启动 xencommons 哦,以前旧版本的 xend 已经被 xencommons 替代了:
# /etc/init.d/xencommons start
Starting C xenstored...
Setting domain 0 name and domid...
Starting xenconsoled...
Starting QEMU as disk backend for dom0
# xl list
Name ID Mem VCPUs State Time(s)
Domain-0 0 3779 4 r----- 105.5
Xen 从 4.1 版本开始引入了新版工具集 xl/libxl,并在后续的版本中逐步替代旧的 xm/xend,在 4.5 版本中已经完全删除了 xm/xend.