Why choosing XEN Hypervisor for your virtualization.
Two reason, on Linux, it’s the most advanced open-source virtualization system. Even if KVM is under heavy development, many features are still missing. Second reason is that Xen has a paravirtualization.
The first part of the How-To would be to explain how to install Debian and Xen. I’ve done this many times and I will probably do a How-To someday to explain how to create this first step. Let’s assume you are hosted on OVH (European Hosting Provider) and everything is already in place.
The first step would be to prepare the LVM to allow to expand easily your partitions.
umount /dev/md2
Let’s assume we have an RAID array and you already have well partitioned your disks (like OVH does)
We create dedicated volumes for our Ubuntu Server 9.04
pvcreate /dev/md2
vgcreate /dev/md2 <GROUP_NAME>
lvcreate /dev/md2 –name <VOLUME_NAME> –size <SIZE> <GROUP_NAME>
mkfs -t ext3 /dev/<GROUP_NAME>/<VOLUME_NAME>
This will create the dedicated LVM volume for your Virtual Machine Ubuntu 9.04.
Next you will install directly without reboot your operating system from debian. Do prepare your installation you need to mount the volume group within your local file system.
mkdir /mnt
mount /dev/<GROUP_NAME>/<VOLUME_NAME> /mnt
Now, we will prepare the installation scripts :
http://ftp.us.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.15_all.deb
dpkg –install debootstrap_1.0.15_all.deb
Now, we have the scripts needed to install Ubuntu within a directory (our LVM partition).
debootstrap –arch amd64 jaunty /mnt http://archive.ubuntu.com/ubuntu
This phase will take few minutes, it will install Ubuntu 9.04. Once this done, the next steps will be used to configure the target ubuntu system.
The first operation we need to do is to create a virtual terminal to allow xen to connect to this particular VM. We will modify /mnt/etc/event.d/xvc0
# xvco – getty
#
# This service maintains a getty on xvco from the point the system is
# started until it is shut down again.start on stopped rc2
start on stopped rc3
start on stopped rc4
start on stopped rc5stop on runlevel 0
stop on runlevel 1
stop on runlevel 6respawn
exec /sbin/getty 38400 xvc0
This will allow to start getty process to allow xen console to connect to this terminal. Now we need to create the terminal itself within the /dev filesystem.
mknod /mnt/dev/xvc0 c 204 191
Next step is to allow network connectivity by modifying the file /mnt/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopbackauto eth0
iface eth0 inet static
address <IP_DOMU>
netmask 255.255.255.255
post-up /sbin/ip route add default dev eth0
We need to setup now, the minimum file system needed to make our virtual machine working, we will modify the regular file /mnt/etc/fstab
proc /proc proc defaults 0 0
/dev/hda1 / ext3 defaults,errors=remount-ro 0 1
We can now configure the password for root and umount the VM filesystem
chroot /mnt passwd
umount /mnt
We are now going to create the configuration for xen to allow our system to run. We assume the xen configuration use vif-route to manage routing between Dom0 and DomU Operating System.
kernel=”/boot/<YOUR CURRENT KERNEL>”
memory = “2048″
maxmem = “3072″
name = <DOM0_NAME>
vcpus=2
vif = [ 'ip=XXX' ] # replace with DomU’s IP
netmask = “255.255.255.0″
gateway = “XXX” # Dom0
disk = [ 'phy:/dev/<LVM_GROUP_NAME>/<LVM_VOLUME_NAME>,hda1,w' ]
root = “/dev/hda1″
extra=’console=xvc0 xencons=xvc0′
We can now create the VM with this configuration file set within /etc/xen/<VM_NAME>
xm create /etc/xen/<VM_NAME>
xm console VM_NAME
Note: You might want to make your vm starting in the same times than the Host. In some configuration you will have an /etc/xen/auto directory where you can put your configuration file.
You can now use your Ubuntu on top of Xen 3.2 / Debian 4.