从源里安装内核支持及文件
sudo apt-get install xen-hypervisor-3.0-i386 xen-image-xen0-2.6.17-6-generic-xen0 xen-utils-3.0 xen-ioemu-3.0
如果运行的是server内核,那么
sudo apt-get install xen-hypervisor-3.0-i386-pae xen-image-xen0-2.6.17-6-server-xen0 xen-utils-3.0 xen-ioemu-3.0
如果是AMD64位处理器,那么使用 xen-hypervisor-3.0-amd64替换 of xen-hypervisor-3.0-i386
生成initrd image,使用如下命令
sudo mkinitramfs -o /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img 2.6.17-6-generic-xen0
添加Xen启动段到 /boot/grub/menu.lst:
title XEN/2.6.17
root (hd0,2)
kernel /boot/xen-3.0-i386.gz
module /boot/xen0-linux-2.6.17-6-generic-xen0 root=/dev/xxx ro
module /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img
"xxx"为你的启动分区,我的为hda3,故上为(hd0,2) root=/dev/hda3
PS: 1,on amd64, use xen-3.0-amd64.gz instead of xen-3.0-i386.gz
2,kernel and modules may need to have the /boot removed From them to get this to work. ie
kernel /xen-3.0-i386.gz
修改Xen的网络配置文件/etc/xen/xend-config.sxp,添加如下段
(network-script network-bridge)
If you are going to use the network-bridge, you must have the bridge-utils package installed (else your bridge won't be created by the network-bridge script and you will get an error like 'Error: Device 0 (vif) could not be connected. Hotplug scripts not working.' when attempting to start your DomU). To install it, run the following command:
sudo apt-get install bridge-utils
The later domU examples assume that you use a bridged networking using device xenbr0. If installing bridge-utils doesn't fix this, try moving the file /etc/udev/xen-backend.rules to /etc/udev/rules.d/10-xen-backend.rules
ok,重启系统
关于建立虚拟机以及启动
提到了三种方式来创建,分别是use loopback-mounted-file,和磁盘分区,以及vmware虚拟磁盘和qemu.这里说明我用的方法,也就是第一中方法。本来打算用第二种方法的,主要是我磁盘空间并不富裕了,从新分区会比较麻烦。如下创建了一个基本的edgy的guest系统
创建虚拟磁盘文件:
sudo dd if=/dev/zero of=/usr/local/diskimage-guest.ext3 bs=1024k seek=4096 count=0
格式化磁盘文件
sudo mkfs.ext3 /usr/local/diskimage-guest.ext3
note:会提示说不是一个设备文件,不用管他,选择y继续。
挂载该虚拟磁盘
sudo mount /usr/local/diskimage-guest.ext3 /mnt -o loop
安装debootstrap
sudo apt-get install debootstrap
安装edgy基本文件到虚拟磁盘
sudo debootstrap edgy /mnt
拷贝内核模块
sudo cp -a /lib/modules/2.6.17-6-generic-xen0/ /mnt/lib/modules
卸载虚拟磁盘
sudo umount /mnt
Configure the guest, create /etc/xen/edgy-guest.cfg
kernel = "/boot/xen0-linux-2.6.17-6-generic-xen0"
ramdisk = "/boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img"
builder='linux'
memory = 128
name = "edgy-guest"
vcpus = 1
vif = [ 'bridge=xenbr0' ]
disk = [ 'file:/usr/local/diskimage-guest.ext3,ioemu:hda1,w' ]
root = "/dev/hda1 ro"
First start xend if it is not already started:
xend start
Now you can create your xen domain
sudo xm create edgy-guest.cfg
You can connect to the guest using
sudo xm console edgy-guest