|
Xen虚拟机的安装
<div class="postbody"><div id="cnblogs_post_body"> 虚拟化技术是云计算实现弹性计算的核心技术。在构建云计算平台中,虚拟机的安装是基础。常用的虚拟机工具很多,如VMware、XEN、KVM、Virtual PC等,这些工具使得用户可以在单台物理PC上(称为宿主机)虚拟出多个虚拟机VM(Virtual machine),由于在每个VM上可以安装与宿主机不同的操作系统。因而可以实现在一台物理PC上模拟出多台安装有不同操作系统的&ldquo;PC&rdquo;。在云计算中,用户可以向云平台申请租用虚拟机,虚拟机的配置,如CPU的核数、主频,内存,存储容量等可以根据需要自己设定,并可动态修改。现有虚拟机工具多支持这些功能,然而很多工具如VMware、XEN-Server等提供的免费测试工具多只提供GUI接口,用户只能通过图形界面实现虚拟机的创建和配置,无法实现动态的配置,以至于构建的云平台退化为不具有弹性的&ldquo;虚拟机平台&rdquo;。
Xen 是由剑桥大学开发的一款开放源代码虚拟机工具软件,支持虚拟机的各种配置和动态创建,最重要的是提供了丰富的用户管理接口。
本文根据马博士的安装方法,给出详细的安装流程,并对安装细节做进一步的补充说明。更多的安装方法请关注马博士的个人主页:
http://www.cse.ust.hk/~zma/
http://www.zhiqiangma.com/homepage/
http://fclose.com/zma/#
下面为安装过程。
1.1 Linux system:
Fedora 12 x86_64
测试PC:HP4321S联想笔记本电脑
SELinux is disabled. Please refer here for detail: Disabled SELinux on Fedora.
Disable SELINUX using your favorite editor to open the SELINUX configuration file. For example:
$:su 切换到root用户
vi /etc/selinux/config
Edit the configuration file so that SELINUX has the value of "disabled". It should look like the following:
SELINUX=disabled
| ext3 is recommended for the file system of disk partition for /boot.
Update the system:
# yum updateThe Xen and libvirt packages in Fedora should not be installed to avoid conflict.
# yum erase xen* libvirt【版本title Fedora (2.6.32.26-175.fc12.x86_64) 经过update后的版本title Fedora (2.6.31.5-127.fc12.x86_64) 安装光盘版本重启系统,从title Fedora (2.6.32.26-175.fc12.x86_64)登录,然后继续下面的任务】1.2 Build and install Xen hypervisor and tools
1.2.1 Download Xen3.4.3
$ wget http://bits.xensource.com/oss-xen/release/3.4.3/xen-3.4.3.tar.gz$ tar xf xen-3.4.3.tar.gz
1.2.2 Build Xen and tools
You may need to install packages depended by this. You can try this for solving the dependencies:
# yum install make gcc -y;yum groupinstall "Development Libraries" -y;yum groupinstall "Development Tools" -y;yum install transfig texi2htmldev86 glibc-devele2fsprogs-devel gitk mkinitrdiasl xz-devel bzip2-develpciutils-libs pciutils-develSDL-devel libX11-devel gtk2-develbridge-utils PyXML qemu-commonqemu-img mercurial -yThe we can make Xen and Xen tools: (xen-3.4.3目录下)
$ make xen$ make tools1.2.3 Install Xen and tools (xen-3.4.3目录下)
$ make install-xen$ make install-tools1.3 Build and install xenified Linux kernel
1.3.1 Download Linux kernel2.6.32.13
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.13.tar.bz2$ tar xf linux-2.6.32.13.tar.bz2 1.3.2 Download2.6.32Xen patches v2
$ wget http://gentoo-xen-kernel.googlecode.com/files/xen-patches-2.6.32-2.tar.bz2$ mkdir xen-patches-2.6.32-2$ tar xf xen-patches-2.6.32-2.tar.bz2 -C xen-patches-2.6.32-2 1.3.3 Apply Xen patches
Apply all the patches downloaded above following the patch number.
You may need to install patch if it isn&rsquo;t installed:
# yum install patchThis patch.sh script can be used (we assume the patch and the kernel are in the same directory):
patch.sh:
#!/bin/bashfor P in `ls ../xen-patches-2.6.32-2/6*.patch1 | sort`do patch -p1 -s -i $P if [ $? = 0 ]; then echo $P applied else echo "Error processing "$P exit 1 fidonePut this script into Linux source directory(linux-2.6.32.13目录下) and execute:
$ sh ./patch.shThe structure of these directories are as follows:

▲注:结构如上图。按照patch脚本,Linux-2.6.32.13 和xen=patches-2.6.32-2放在同一个目录。
1.3.4 Configure Xenified Linux kernel
A working configuration file that I used can be downloaded directly from here:
config-for-xenified-linux-2.6.32.13
Just download this file, put it into the kernel source code file directory(linux-2.6.32.13目录下) and rename it to .config.
Other than use my configuration file, you can also configure it by yourself by using &ldquo;make menuconfig&rdquo;.
Make sure you build the kernel with these components enabled:
Processor type and features --->
Symmetric multi-processing support
Support sparse irq numbering
Enable Xen compatible kernel Device Drivers ---> XEN --->
Privileged Guest (domain 0) <*> Backend driver support (NEW) <*> Block-device backend driver (NEW) <*> Block-device tap backend driver (NEW) < > Block-device tap backend driver 2 (NEW) <*> Network-device backend driver (NEW) (8) Maximum simultaneous transmit requests (as a power of 2) (NEW) [ ] Pipelined transmitter (DANGEROUS) (NEW) < > Network-device loopback driver (NEW) < > PCI-device backend driver (NEW) < > TPM-device backend driver (NEW) <M> SCSI backend driver (NEW) <M> USB backend driver (NEW) <M> Block-device frontend driver <M> Network-device frontend driver <M> Network-device frontend driver acceleration for Solarflare NICs (NEW) <M> SCSI frontend driver (NEW) <M> USB frontend driver (NEW)
Taking the HCD statistics (for debug) (NEW) [ ] HCD suspend/resume support (DO NOT USE) (NEW) <*> User-space granted page access driver (NEW) <*> Framebuffer-device frontend driver (NEW) <*> Keyboard-device frontend driver (NEW)
Disable serial port drivers (NEW) <*> Export Xen attributes in sysfs (NEW) (256) Number of guest devices (NEW) Xen version compatibility (no compatibility code) --->
Place shared vCPU info in per-CPU storage (NEW)1.3.5 Build kernel (linux-2.6.32.13目录下)
$ make -jXX can be two times of the number of the processor. We use this to let make invoke compilation work in X-wayparallel.
1.3.6 Install modules and kernel (linux-2.6.32.13目录下)
# make modules_install install【这一步执行时间很长,中间有停顿现象】1.4 Configure grub
Add one entry for Xen in /boot/grub/grub.conf. This is an example entry:
# vi /boot/grub/grub.conf
[table=98%][tr][td]<div class="shape">title Xen3.4.3- Xenified Linux 2.6.32.13
root (hd0,0)
kernel /xen-3.4.3.gz console=vga vga=ask noreboot
module /vmlinuz-2.6.32.13 ro root=/dev/mapper/VolGroup-LogVol_root noiswmd LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us
module /initramfs-2.6.32.13.img |
|