CentOS 源码编译安装 Xen 的过程
1、版本说明
操作系统centos5.4 内核:linux2.6.18
xen操作系统内核:linux-2.6.38.2
xen版本:xen-4.1.2.tar.gz
xen-patches版本:xen-patches-2.6.38-2
2、安装需要的软件包
(以下操作目录在/root目录下,理论上目录应该没有影响)
首先最小化安装 CentOS,然后安装编译 Xen 和 Linux xen kernel 所需要的软件包:
# yum groupinstall "Development Tools"
# yum install hmaccalc ncurses-devel zlib-devel openssl-devel python-devel \
bridge-utils libtool-ltdl iasl xorg-x11-drv-evdev xorg-x11-drv-fbdev \
xorg-x11-drv-i810-devel xorg-x11-drv-via-devel xorg-x11-proto-devel \
xorg-x11-server-sdk xorg-x11-xtrans-devel
3、安装 Xen hypervisor 和 tools
到 http://www.xen.org/products/xen_source.html 下载最新的 Xen 源代码,然后解开、编译、安装,标准的 Linux 软件源码安装动作:
$ tar zxvf xen-4.1.2.tar.gz
$ cd xen-4.1.2/
$ make xen tools stubdom
# make install-xen install-tools install-stubdom
上面 make stubdom 的时候会从网上自动下载一些东西,所以如果是用代理上网的话需要在自己根目录下的 .wgetrc 里加上代理服务器,以便 wget 能通过代理正常下载:
$ vi .wgetrc
http_proxy = http://proxy.vpsee.com:3128/
use_proxy = on
加入到启动脚本:
# /sbin/chkconfig --add xend
# /sbin/chkconfig --add xendomains
# /sbin/chkconfig xend on
# /sbin/chkconfig xendomains on
4、安装 Xen 内核
下载 Linux 内核(linux-2.6.38.2.tar.bz2)放到/root目录下
下载相应 Linux 内核xen补丁(xen-patches-2.6.38-2.tar.bz2)放到/root目录下
给 Linux 内核打 xen 补丁:
$ tar -xjf linux-2.6.38.2.tar.bz2
$ mkdir xen-patches-2.6.38-2
$ cd xen-patches-2.6.38-2
$ tar -xjf ../xen-patches-2.6.38-2.tar.bz2
$ cd ..
$ cd linux-2.6.38.2
$ for i in `ls ../xen-patches-2.6.38-2/`; \
do patch -p1 < ../xen-patches-2.6.38-2/"$i"; done
5、配置带 xen 的 Linux 内核(此步骤最为关键):
$ make menuconfig
General setup --->
[*] enable deprecated sysfs features to support old userspace tools
[*] enabled deprecated sysfs features by default
(上面的项目必须选中,(作用是修改".config"配置文件中的“#CONFIG_SYSFS_DEPRECATED_V2 is not set”项一行修改为“CONFIG_SYSFS_DEPRECATED_V2=y”),否则编译完成后启动时会出现以下错误,导致启动失败:
Mounting root filesystem.
mount: could not find filesystem ‘/dev/root’
Setting up other filesystems.
Setting up new root fs
setuproot: moving /dev failed: No such file or directory
no fstab.sys, mounting internal defaults
setuproot: error mounting /proc: No such file or directory
Switching to new root and running init.
unmounting old /dev
unmounting old /proc
unmounting old /sys
switchroot: mount failed: No such file or directory
Kernel panic – not syncing: Attempted to kill init!
)
Processor type and features ---> [*] Enable Xen compatible kernel Networking support ---> Networking options ---> <M> 802.1d Ethernet Bridging(该版本中只能有M选项,而无*选项) Device Drivers ---> XEN ---> [*] Privileged Guest (domain 0) <*> Backend driver support <*> Block-device backend driver <*> Block-device tap backend driver < > Block-device tap backend driver 2 (编译内核时发现Block-device tap backend driver 2项不可选择,否则在make阶段会出现以下错误,原因还未知 drivers/xen/blktap2/built-in.o:(.text+0x3bc3): first defined here make[2]: *** [drivers/xen/built-in.o] Error 1 make[1]: *** [drivers/xen] Error 2 make: *** [drivers] Error 2) <*> Network-device backend driver <*> PCI-device backend driver <M> SCSI backend driver(该版本中只能有M选项,而无*选项) <*> USB backend driver <*> Block-device frontend driver <*> Network-device frontend driver <M> SCSI frontend driver(该版本中只能有M选项,而无*选项) <*> USB frontend driver <*> Framebuffer-device frontend driver <*> Keyboard-device frontend driver [*] Disable serial port drivers <*> Export Xen attributes in sysfs Xen version compatibility (3.3.0 and later) ---> 3.3.0 and later
注意:如果使用32位系统,则务必将PAE功能开启,将内存支持选择为64GB,否则会重启后内核将会报错。
Processor type and features --->
High Memory Support (4GB) --->
64GB
6、配置好内核参数以后,保存并退出,开始编译 Linux 内核:
$ make
$ make modules
# make modules_install
# make install
# /sbin/depmod 2.6.38.2
7、更新 grub,改为如下代码:
# vi /boot/grub/menu.lst
...
title CentOS (2.6.38.2-xen)
root (hd0,0)
kernel /xen-4.1.2.gz
module /vmlinuz-2.6.38.2 ro root=/dev/VolGroup00/LogVol00
module /initrd-2.6.38.2.img
...
8、重启系统,确认 Xen 安装成功:
# reboot
# uname -a
Linux centos-test74 2.6.38.2 #1 SMP Fri Nov 4 22:05:17 CST 2011 x86_64 x86_64 x86_64 GNU/Linuxx86_64 GNU/Linux
# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 3713 4 r----- 36.0