首先最小化安装 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
到 http://www.xen.org/products/xen_source.html 下载最新的 Xen 源代码,然后解开、编译、安装,标准的 Linux 软件源码安装动作:
- $ tar zxvf xen-4.0.0.tar.gz
- $ cd xen-4.0.0/
- $ make xen tools stubdom
- # make install-xen install-tools install-stubdom
加入到启动脚本:
- # /sbin/chkconfig --add xend
- # /sbin/chkconfig --add xendomains
- # /sbin/chkconfig xend on
- # /sbin/chkconfig xendomains on
下载 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/list
- 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
配置带 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
配置好内核参数以后,保存并退出,开始编译 Linux 内核:
- $ make
- $ make modules
- # make modules_install
- # make install
- # /sbin/depmod 2.6.31.8
更新 grub:
- # vi /boot/grub/menu.lst
- ...
- title CentOS (2.6.31.8-xen)
- root (hd0,0)
- kernel /boot/xen-4.0.0.gz
- module /boot/vmlinuz-2.6.31.8 ro root=/dev/VolGroup00/LogVol00
- module /boot/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
1、insmod: error inserting '/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.ko module"
insmod /lib/dm-region-hash.ko
echo "Loading dm-region-hash.ko module"
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:could not find filesystem ‘/dev/root’ 的解决方法
RedHat nash Version 5.1.19.6 startingrver(2.6.33.3)
mount: could not find filesystem ‘/dev/root’
setuproot: moving /dev failed: No such file or directory
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
switchroot: mount failed: No such file or directory
Kernel panic – not syncing: Attempted to kill init!
[Linux-initrd @ 0x1fc37000,0x228585 bytes]
于是在网上找了很多,也尝试了很多加模块、重编译了N次、改fstab等方法,都不行。最后在一个网站上找到解决方法。
方法:编译时修改.config文件中的“CONFIG_SYSFS_DEPRECATED_V2”,默认该选项为not set,被注释掉的,将其改为y。即修改为“CONFIG_SYSFS_DEPRECATED_V2=y”,修改后,再编译,重启即正常了。
3、在安装libvirt的时候,由于libcurl版本过低,使得service libvirtd status 的结果是未能识别到服务