Xen 4.0 Hypervisor with LVM on Debian 6 Squeeze


这篇用不用中文都是差不多了, 索性用英文了. Xen 是VM(虚拟机)的一种, 现在很多商用 VPS 服务商就是使用基于 Xen, 或者 OpenVZ 技术在一台物理上的服务器上同时运行多个VM的.

1, Install Debian 6 Squeeze

This step will be the easiest. Just to remember to use LVM when partitioning and leave enough unused(un-partitioned) disk space for later use. If your system has >= 4GB of memory, choose AMD64 architecture.

Reference to LVM: http://www.debian-administration.org/articles/410

2, Install Xen

Guess all commands below require root privilege, so don’t bother using “sudo” but log in with root or “su”.

 apt-get install xen-linux-system xen-qemu-dm xen-tools

“xen-linux-system” is not a actual package, it will match something like “xen-linux-system-2.6.32-5-xen-686”, which is a meta package.

3, Modify grub to boot Xen by default

Open and edit “/etc/default/grub”, change

GRUB_DEFAULT = 0

to

GRUB_DEFAULT = 4

Number 4 means the 5th item in grub boot menu.

To prevent further change to the boot menu, also add the following to “/etc/default/grub”:

GRUB_DISABLE_OS_PROBER = true

And then update grub with

update-grub

Reference: http://wiki.debian.org/Xen

4, Build your own Debian network bridge. First, take down your eth0:

ifdown eth0

Open and edit “/etc/network/interfaces”, change TO

auto lo
iface lo inet loopback

auto br0
iface br0 inet static
address x.x.x.x
netmask x.x.x.x
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x
bridge_ports eth0
bridge_stp on
bridge_maxwait 0

Then “br0” will be your new network bridge, and eth0 is your physical Ethernet interface.You can now try bring your bridge online:

ifup br0

Now load some settings to “/etc/sysctl.conf”

net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

To make these effective, run the command:

sysctl -p /etc/sysctl.conf

Reference: http://wiki.libvirt.org/page/Networking

5, Default settings for new VM images, to change, open and edit “/etc/xen-tools/xen-tools.conf” and revise the following lines:

lvm = VOLUME GROUP NAME
size = 8GB #disk size
memory = 512MB
swap = 512MB

gateway = x.x.x.x
netmask = x.x.x.x

passwd = 1

pygrub = 1

6, Create VM images with xen-create-image

xen-create-image –hostname HOSTNAME –ip IP –vcpus 2 –pygrub –dist squeeze

Note, by default, debootstrap method, an Internet connection is required to download from Debian mirrors. After success, 2 new logical volume2(LV 🙂 ) will be created along with a configuration file called /etc/xen/HOSTNAME.cfg

7, Run VM images

xm create /etc/xen/HOSTNAME.cfg

8, Make VM images auto-start when system boots

mkdir /etc/xen/auto
ln -s /etc/xen/HOSTNAME.cfg /etc/xen/auto

Reference: http://www.howtoforge.com/using-xen-with-lvm-based-vms-instead-of-image-based-vms-debian-etch

At this point, you should be able to log in to VM via 2 ways:

xm console HOSTNAME

or

ssh root@IP

,