1. 安装基本软件包
yum -y install openssh-clients gcc g++ make automake autoconf wget glibc-devel glibc-devel.i686 libaio rpm-build yum-utils transfig libidn-devel zlib-devel texi2html SDL-devel curl-devel libX11-devel python-devel ghostscript tetex-latex ncurses-devel gtk2-devel libaio-devel texinfo dev86 gettext gnutls-devel openssl-devel pciutils-devel libuuid-devel iasl bzip2-devel xz-devel e2fsprogs-devel PyXML kpartx bridge-utils libsysfs-devel libsysfs libnl-devel libtool nfs-utils libxml2-devel xhtml1-dtds readline-devel libudev-devel libpciaccess-devel yajl-devel libpcap-devel avahi-devel dnsmasq cyrus-sasl-devel polkit lvm2 iscsi-initiator-utils parted-devel device-mapper-devel numactl-devel libcap-ng-devel netcf-devel ebtables lzop nc cyrus-sasl-md5 python-virtinst
wget http://mirrors.ustc.edu.cn/fedora/linux/updates/13/x86_64/qemu-common-0.13.0-1.fc13.x86_64.rpm wget http://mirrors.ustc.edu.cn/fedora/linux/updates/13/x86_64/qemu-img-0.13.0-1.fc13.x86_64.rpm rpm -Uvh qemu-*.rpm
3. 通过srpm编译安装Xen
wget http://mirrors.ustc.edu.cn/fedora/linux/updates/15/SRPMS/xen-4.1.1-3.fc15.src.rpm rpm -i xen-4.1.1-3.fc15.src.rpm cd ~/rpmbuild/SPECS/ rpmbuild -bb xen.spec cd ~/rpmbuild/RPMS/x86_64/ rpm -Uvh xen-*4.1.1-*.rpm
yumdownloader --source bridge-utils rpm -i bridge-utils-1.2-9.el6.src.rpm # 版本可能不同 cd ~/rpmbuild/SPECS/ vi bridge-utils.spec # 去除两行有patch4的地方, 也即有IGMP的patch的行 rpmbuild -bb bridge-utils.spec cd ~/rpmbuild/RPMS/x86_64/ rpm -Uvh --force bridge-utils-1.2-9.el6.x86_64.rpm
提供一个patch
--- bridge-utils.spec.orig 2010-04-30 00:29:16.000000000 +0800 +++ bridge-utils.spec 2011-09-30 23:27:19.090747706 +0800 @@ -10,7 +10,6 @@ Patch1: bridge-utils-1.2-show-ports.patch Patch2: bridge-utils-1.2-foreach.patch Patch3: bridge-utils-1.2-params.patch -Patch4: bridge-utils-1.2-Add_IGMP_snooping_support.patch BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: libsysfs-devel autoconf @@ -32,7 +31,6 @@ %patch1 -p1 %patch2 -p1 %patch3 -p1 -%patch4 -p1 -b .Add_IGMP_snooping_support %build autoconf
yumdownloader --source libvirt rpm -i libvirt-0.8.1-27.el6_0.6.src.rpm # 版本可能不同 cd ~/rpmbuild/SPECS/ vi libvirt.spec # 按下面的patch修改 rpmbuild -bb libvirt.spec cd ~/rpmbuild/RPMS/x86_64/ rpm -Uvh libvirt-*0.8.1*.rpm
--- libvirt.spec.orig 2010-08-18 15:02:53.000000000 +0300 +++ libvirt.spec 2010-11-15 14:17:36.388996162 +0200 @@ -104,7 +104,7 @@ %ifnarch x86_64 %define with_qemu 0 %endif -%define with_xen 0 +%define with_xen 1 %endif # If Xen isn't turned on, we shouldn't build the xen proxy either
6. 安装python-virtinst,旧的版本不支持的参数太多了
# 从redhat网站下载srpm wget http://ftp.redhat.com/redhat/linux/enterprise/6Server/en/os/SRPMS/python-virtinst-0.500.5-3.el6.src.rpm rpm -i python-virtinst-0.500.5-3.el6.src.rpm cd ~/rpmbuild/SPECS/ rpmbuild -bb python-virtinst.spec cd ~/rpmbuild/RPMS/noarch/ rpm -Uvh --force python-virtinst-*.rpm
# 从github下载内核 wget https://github.com/jsgf/linux-xen/tarball/xen-2.6.32.46 -O kernel-xen-2.6.32.46.tar.gz # 下载config wget http://pasik.reaktio.net/xen/kernel-config/config-2.6.32.43-pvops-dom0-xen-stable-x86_64 # 可以先修改config里面的CONFIG_LOCALVERSION项, 给这个内核起个别名, 比如-dom0-xen, 以下为没有修改的情况 tar xzf kernel-xen-2.6.32.46.tar.gz cp config-2.6.32.43-pvops-dom0-xen-stable-x86_64 jsgf-linux-xen-1c3f03c/.config cd jsgf-linux-xen-1c3f03c make oldconfig make -j4 bzImage make -j4 modules make modules_install depmod -a 2.6.32.46 cp -a arch/x86/boot/bzImage /boot/vmlinuz-2.6.32.46 cp -a System.map /boot/System.map-2.6.32.46 cp -a .config /boot/config-2.6.32.46 cd /boot/ dracut --force initramfs-2.6.32.46.img 2.6.32.46 # 关闭ksm, 跟xen不兼容 chkconfig ksm off chkconfig ksmtuned off8. 编辑/boot/grub/menu.lst, 添加
title Xen 4.0 with Linux 2.6.32.46 root (hd0,0) kernel /xen.gz dom0_mem=2048M loglvl=all guest_loglvl=all module /vmlinuz-2.6.32.46 ro root=/dev/sda2 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM KEYBO ARDTYPE=pc KEYTABLE=us SYSFONT=latarcyrheb-sun16 LANG=en_US.UTF-8 nomodeset module /initramfs-2.6.32.46.img
...... (xend-http-server yes) (xend-unix-server yes) (xend-tcp-xmlrpc-server yes) ...... (xend-relocation-server yes) ...... (xend-tcp-xmlrpc-server-address '0.0.0.0') (xend-tcp-xmlrpc-server-port 8006) ...... (xend-relocation-port 8002) ...... (xend-address localhost) ...... (xend-relocation-address '0.0.0.0') ...... ...... ......
groupadd libvirt vi /etc/libvirt/libvirtd.conf unix_sock_group = "libvirt" unix_sock_ro_perms = "0777" unix_sock_rw_perms = "0770"
11. 重启, 启动Xen的内核
12. 把上面做的事情, 写成一套脚本
virsh net-destroy default virsh net-undefine default service libvirtd restart
mkdir -p images/xen cp images/pxeboot/initrd.img images/xen/ cp images/pxeboot/vmlinuz images/xen/3. 把一个http服务器指向这个目录即可
virt-install \ -p \ -n centos6 \ -r 4096 \ --vcpus=1 \ --disk path=/home/vms/centos6/sda.img,size=2,format='raw',driver_name='file' \ --graphics none \ -l http://10.100.6.48/CentOS \ -w bridge=xenbr0 \ --os-type=linux # -p: paravirt模式执行 # -n: 虚拟机名字 # -r: 内存大小, 以MB计 # --vcpus: 虚拟的CPU数 # --disk: 磁盘参数, path:路径; size:大小, 以GB计; format='raw':raw模式; driver_name='file': 默认是aio:tap, 但是CentOS6的默认内核不支持, 安装时找不到硬盘 # --graphics none: 以console模式启动 # -l http://10.100.6.48/CentOS: 上面介绍的自己的建立CentOS的网络安装环境 # -w bridge=xenbr0, xenbr0是与可访问安装环境的网卡绑定的网桥