准备好两个源码文件:linux-2.6.18-xen-3.4.0.tar.gz以及xen-3.4.3.tar.gz
(一下内容主要参照网上两个资料:
http://www.myhack58.com/Article/sort099/sort0102/2012/33102.htm
http://www.cnblogs.com/feisky/archive/2012/01/18/2325952.html
)
tar zxf xen-3.4.2.tar.gz
tar zxf linux-2.6.18-xen-3.4.2.tar.gz
mv linux-2.6.18-xen-3.4.2 xen-3.4.2/linux-2.6.18-xen.hg
cd xen-3.4.2
修改buildconfigs/src.hg-clone
# Mercurial
HG ?= hg
LINUX_SRCDIR ?= linux-$(LINUX_VER)-xen.hg
# Repository to clone.
XEN_LINUX_HGREPO ?= $$(sh buildconfigs/select-repository $(LINUX_SRCDIR) $(LINUX_SRC_PATH))
# Set XEN_LINUX_HGREV to update to a particlar revision.
XEN_LINUX_HGREV ?= tip
$(LINUX_SRCDIR)/.valid-src: $(__XEN_LINUX_UPDATE)
set -e ; \
touch $@
监测依赖工具是否都安装了
cd tools/check/
./chk build
Xen CHECK-BUILD Mon Feb 20 09:27:15 CST 2012
Checking check_crypto_lib: OK
Checking check_curl: unused, OK
Checking check_openssl_devel: OK
Checking check_python: OK
Checking check_python_devel: OK
Checking check_x11_devel: OK
Checking check_xgettext: OK
Checking check_xml2: unused, OK
Checking check_zlib_devel: OK
Checking check_zlib_lib: OK
./chk install
Xen CHECK-INSTALL Mon Feb 20 09:32:05 CST 2012
Checking check_brctl: which: no brctl in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/sbin:/usr/sbin)
*** check_brctl FAILED: can't find brctl
Checking check_crypto_lib: OK
Checking check_curl: unused, OK
Checking check_iproute: OK
Checking check_python: OK
Checking check_python_xml: OK
Checking check_udev: which: no udevadm in (/sbin)
OK
Checking check_xml2: unused, OK
Checking check_zlib_lib: OK
尝试修改:
从网上http://sourceforge.net/projects/bridge/files/下载bridge-utils-1.5.tar.gz,
然后参照http://book.51cto.com/art/201106/267574.htm进行安装,进好了
准备studom补丁集
studom是xen中的一个补丁集,可以增加性能,是从xen3.3引入的,并不是必需的。网上有说可以把这块去掉(具体步骤可以到网上去找),如果不想去掉的话,可以自己上网下载对应的工具包,放到xen源码目录下的studom目录下。准备的工具包有:
grub-0.97.tar.gz newlib-1.16.0.tar.gz pciutils-2.2.9.tar.gz
lwip-1.3.0.tar.gz zlib-1.2.3.tar.gz
编译安装
Make dist
(没有使用make dist –j 4,因为第一次编译,怕出错,听乾龙说可以使用make dist –j 4 2>/error.txt来重定向错误信息)
生成initrd镜像
mkinitrd –without-dmraid –v –f /boot/initrd-2.6.18.8-xen.img 2.6.18.8-xen
修改grub配置文件
Vi /boot/grub/grub.conf,修改结果如下:
default=1
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.el5.img
title CentOS-Xen3.4.3 (2.6.18-8)
root (hd0,0)
kernel /xen-3.4.3.gz
module /vmlinuz-2.6.18.8-xen ro root=LABEL=/ rhgb quiet
module /initrd-2.6.18.8-xen.img
重启机器后使用xen内核进行启动,启动后发现没有eth0,所以重新回到centos,查找网卡型号,装好驱动以后,使用命令 /etc/init.d/xend start 将dom0启动起来就行了。
(剩下的内容参考http://code.google.com/p/cloudxy/wiki/HowTo_Build_PV_domU)
制作一个32M的镜像系统
dd if=/dev/zero of=domU-32bit-FS.img bs=1M count=32
mkfs.ext3 domU-32bit-FS.img
制作文件系统,使用的是http://code.google.com/p/cloudxy/wiki/HowTo_Build_PV_domU提供的ttylinux-i486-8.0.img
sudo mount -o loop /mnt ttylinux-i486-8.0.img
mkdir domUdisk
sudo mount -o loop domU-32bit-FS.img domUdisk
cp -a mnt/ domUdisk/ -rf
将pv kernel 加入到domU-32bit-FS.img当中,使用的是http://stacklet.com/download/kernel/list?architecture=x86提供的linux-2.6.35.8-xenU.x86.tar.bz2
Tar xvf linux-2.6.35.8-xenU.x86.tar.bz2
Cp –rf ./boot/ domUdisk/
Cp –rf ./lib/ domUdisk/
(注:下面的操作都是在img里面做的!)
创建/boot/grub/grub.conf
title vmlinuz-2.6.35.8
root (hd0,0)
kernel /boot/vmlinuz-2.6.35.8.stk.x86 console=hvc0 root=/dev/xvda1 ro
修改/etc/fstab
在首行加入:
/dev/xvda1 / ext3 defaults,errors=remount-ro 0 0
修改/etc/inittab
加入:
hvc0:2345:respawn:/sbin/getty 38400 hvc0
修改/etc/securetty
加入hvc0
umount domUdisk
创建虚拟机启动配置pygrub.conf
memory=512
name="ttylinux"
bootloader="/usr/bin/pygrub"
disk=['tap:aio:/srv/xen/domU-32bit-FS.img,xvda1,w']
注:其中/srv/xen/是我放置img的位置