从官网下载到 xen-3.4.4.tar.gz ,解压缩后, 直接make ;

发生如下错误:

  1. select-repository: Searching `.:..' for linux-2.6.18-xen.hg
  2. select-repository: Ignoring `.'
  3. Unable to determine path to Linux source tree.
  4. Falling back to linux-2.6.18-xen Mercurial repository.
  5. Cloning http://xenbits.xensource.com/linux-2.6.18-xen.hg to linux-2.6.18-xen.hg.
  6.  
  7. /bin/sh: line 8: hg: command not found

原因是没有安装mercurial, 用 yum  install mercurial  , 发现没有软件包可以使用,只能从源码来安装了。

下载了 mercurial 后, 解压, 由于mercurial 是python 写的,

执行安装命令  python  setup.py  install      , 安装成功!

进入 xen目录,继续 make   xen   tools  stubdom, 又出现如下错误 :

  1. + test -d http://xenbits.xensource.com/git-http/qemu-xen-3.4-testing.git
  2. + '[' '!' -d ioemu-remote ']'
  3. + rm -rf ioemu-remote ioemu-remote.tmp
  4. + mkdir ioemu-remote.tmp
  5. + rmdir ioemu-remote.tmp
  6. + git clone http://xenbits.xensource.com/git-http/qemu-xen-3.4-testing.git ioemu-remote.tmp
  7. /bin/sh: line 8: git: command not found

是 git 软件包没有找到, 用 yum  install  git  ,  提示没有git软件包,如下

  1. [root@localhost xen-3.4.4]# yum install git
  2. Loaded plugins: fastestmirror, security
  3. Loading mirror speeds from cached hostfile
  4.  * base: CentOS.tt.co.kr
  5.  * extras: mirror.averse.net
  6.  * updates: mirror.averse.net
  7. Setting up Install Process
  8. No package git available.
  9. Nothing to do

后来在网上找到解决办法 ,说是缺少 epel 软件包:

  1. [root@localhost opt]# wget http://dl.Fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
  2.  
  3. [root@localhost opt]# rpm -ivh epel-release-5-4.noarch.rpm

然后再 yum  install  git , 这下就可以安装 git 软件包了。

再次进入 xen目录,继续 make   xen   tools  stubdom

------------------------------------------------------------------------------------------

安装需要的软件包

首先最小化安装 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
2.
virt-manager virt-install

安装 Xen hypervisor 和 tools

到 http://www.xen.org/products/xen_source.html 下载最新的 Xen 源代码,然后解开、编译、安装,标准的 Linux 软件源码安装动作:

$ wget http://bits.xensource.com/oss-xen/release/4.0.0/xen-4.0.0.tar.gz

$ tar zxvf xen-4.0.0.tar.gz
$ cd xen-4.0.0/
$ make xen tools stubdom
# make install-xen install-tools install-stubdom

3.

加入到启动脚本:

# /sbin/chkconfig --add xend
# /sbin/chkconfig --add xendomains
# /sbin/chkconfig xend on
# /sbin/chkconfig xendomains on

4.

安装 Xen 内核

下载 Linux 内核后给内核打 xen 补丁:

$ cd ..
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.8.tar.bz2
$ tar -xjf linux-2.6.31.8.tar.bz2

$ wget http://gentoo-xen-kernel.googlecode.com/files/xen-patches-2.6.31-10.tar.bz2
$ mkdir xenpatch-2.6.31.8
$ cd xenpatch-2.6.31.8
$ tar -xjf ../xen-patches-2.6.31-10.tar.bz2
$ cd ..

$ cd linux-2.6.31.8
$ for i in `ls ../xenpatch-2.6.31.8/`; \
do patch -p1 < ../xenpatch-2.6.31.8/"$i"; done

5.

配置带 xen 的 Linux 内核:

$ make menuconfig

Processor type and features --->
  [*] Enable Xen compatible kernel
Networking support --->
  Networking options --->
    <*> 802.1d Ethernet Bridging
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
       Network-device backend driver
       PCI-device backend driver
       SCSI backend driver
       USB backend driver
    <*> Block-device frontend driver
    <*> Network-device frontend driver
     SCSI frontend driver
     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

编译时修改.config文件中的“CONFIG_SYSFS_DEPRECATED_V2”,默认该选项为not set,被注释掉的,
将其改为y。即修改为“CONFIG_SYSFS_DEPRECATED_V2=y”
6.

配置好内核参数以后,保存并退出,开始编译 Linux 内核:

$ make -j4
$ make -j4 modules
# make -j4 modules_install
# make -j4 install
# /sbin/depmod 2.6.31.8

更新 grub:

#  vi /boot/grub/menu.lst
...
title CentOS (2.6.31.8-xen)
        root (hd0,0)
        kernel /xen-4.0.0.gz
        module /vmlinuz-2.6.31.8 ro root=/dev/VolGroup00/LogVol00
        module /initrd-2.6.31.8.img
...

重启系统,确认 Xen 安装成功:

# reboot

# uname -a
Linux localhost.localdomain 2.6.31.8 #2 SMP Tue Apr 20 11:19:19 SAST 2010 x86_64 GNU/Linux

# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  3713     4     r-----     36.0

重启后,选择CentOS(2.6.31.8-xen) ,可能出现问题

1、insmod: errorinserting '/lib/dm-region-hash.ko' : -1 File exists

编译2.6.31内核后重启出现

insmod: error inserting '/lib/dm-region-hash.ko': -1 File exists

解决方法:

1,解压initrd文件

[root@bogon ~]# cp/boot/initrd-2.6.30.4.img /tmp

[root@bogon ~]# cd /tmp/

[root@bogon tmp]# ls

initrd-2.6.30.4.img

[root@bogon tmp]# mkdir newinitrd

[root@bogon tmp]# cd newinitrd/

[root@bogon newinitrd]# zcat../initrd-2.6.30.4.img |cpio -i

11537 blocks

释放之后看到如下内容

[root@bogon newinitrd]# ls

bin  dev   etc   init  lib   proc   sbin  sys   sysroot

2下边就是编辑init,删掉其中重复的四行中的两行

echo "Loading dm-region-hash.komodule"

insmod /lib/dm-region-hash.ko

echo "Loading dm-region-hash.komodule"

insmod /lib/dm-region-hash.ko

3,重新打包initrd

[root@bogon newinitrd]# find .|cpio -c -o> ../initrd

11538 blocks

[root@bogon newinitrd]# cd ..

[root@bogon tmp]# gzip -9 < initrd >initrd.img

[root@bogon tmp]# ls

initrd-2.6.30.4.img    initrd   initrd.img          newinitrd

好了,initrd.img就是重新打包的initrd了,然后把initrd.img拷贝到/boot,更改grub.conf里边的initrd-2.6.30.4.img为initrd.img就可以了,

这样“insmod: error inserting '/lib/dm-region-hash.ko' : -1 File exists”就不会有了

其实将init文件的第二行“setquiet”去掉,你就知道initrd文件到底在做什么了

2、编译内核提示 mount:couldnot find filesystem ‘/dev/root’的解决方法

RedHat nash Version 5.1.19.6startingrver(2.6.33.3)

mount: could not find filesystem‘/dev/root’

setuproot: moving /dev failed: No such fileor directory

setuproot: error mounting /proc: No suchfile or directory

setuproot: error mounting /sys: No suchfile or directory

switchroot: mount failed: No such file ordirectory

Kernel panic – not syncing: Attempted tokill init!

[Linux-initrd @ 0x1fc37000,0x228585 bytes]

于是在网上找了很多,也尝试了很多加模块、重编译了N次、改fstab等方法,都不行。最后在一个网站上找到解决方法。

方法:编译时修改.config文件中的“CONFIG_SYSFS_DEPRECATED_V2”,默认该选项为not set,被注释掉的,

将其改为y。即修改为“CONFIG_SYSFS_DEPRECATED_V2=y”,修改后,再编译,重启即正常了。

CONFIG_XEN_NETDEV_LOOPBACK=y

----------------------------------------------------------------------------------------------------------------------------------------------

通过基于libvirt库的工具(如virt-manager&&virt-install&&virsh)连接XEN时,出现

error:unable to connect to 'localhost:8000':connection refused
error:failed to connect to the hypervisor!
通过查看XEN的配置文件/etc/xen/xend-config.sxp,发现如下两行:
# Port xend should use for the HTTP interface, if xend-http-server is set.
#(xend-port            8000)
原来8000端口对应的xend-http-server没有开启。
解决方案:将/etc/xen/xend-config.sxp中的“#(xend-http-server no)”改为“(xend-http-server yes)”并重启xend服务,搞定~
 
 
xencommons 无法启动
 
/etc/ld.so.conf 添加xen 路径 /usr/lib/ /usr/lib64