Monday, February 15, 2016

XEN on Debian Etch

--
This document describes in detail the process of setting up XEN on Debian ETCH. Once properly done, one
should be able to install all kinds of guys in xen virtual machines (or DomUs).

The primary Xen Host, which runs provides the abstraction layer (xen-hypervisor) for hardware device access to
DomU (unprivilged domains / virtual servers) is called the dom0.

Right, that sorted, let's prepare the dom0.

Things to note:
--
If you have a fresh install, use LVM2! Leave enough space (as you feel will be required) to create and maintain your
virtual servers and their swap files.
--
apt-get update
apt-get dist-upgrade
reboot

apt-get install xen-hypervisor-3.0-i386 xen-utils-3.0 iproute bridge-utils libc6-xen xen-tools
Copy over the file 'xen-3.0.2-install-x86_32.tgz' from /afs/software/xen to your local system
The file should be placed in /usr/local/src (or where ever you want really)
tar zxvf xen-3.0.2-install-x86_32.tgz
cd xen-3.0.2-install
sh ./install.sh

Now it so happens that if you're using sata and raid-1, you need to ensure that an initrd image has
been created. For this:

apt-get install initrd-tools
cd /boot/
mkinitrd -o initrd.img-2.6.16-xen 2.6.16-xen

For some reason, when I installed it, etch didn't generate required files for the kernel. Just to be sure,
run:
depmod -v 2.6.16-xen

Now edit /boot/grub/menu.1st and add this as your default kernel (adding it as the first kernel is easiest):

title           Xen 3.0 / XenLinux 2.6
root            (hd0,0)
kernel          /xen-3.0.gz console=vga
module          /vmlinuz-2.6-xen root=/dev/md3 ro console=tty0
module          /initrd.img-2.6.16-xen

Don't blindly add the above .. you need to set root=/dev/md3 to your actual boot partition or grub won't find your
kernel. You also need to set root (hd0,0) accordingly.

Reboot the system, if it panics, something is obviously wrong. Try and go over the steps and see if you missed something

If all boots up okay, you're in a xen enabled kernel. Time to create a virtual server.

--

Edit /etc/xen-tools/xen-tools.conf

Go over the options carefully -- especially the kernel and initrd options. Secondly, ensure that you are setting the base image
dir for xen as well as the default distribution correctly -- although anything can be changed at runtime.

I ran the following command to create the first virtual server:

xen-create-image --hostname=krb2.emergen.biz --ip=192.168.0.180 --dir /home/xen-servers --dist=etch --debootstrap

Note: debootstrap does not install a kernel into your new virtual server ...

Mount the file system, chroot to it and install a kernel as required.

This didn't work for some reason, so here is what I did the second time around -- note, the above script method is preferred and
we'll figure out exactly why this didn't work -- however, for now, we'll use the manual approach.

--
mkdir -p /home/xen-servers/domains/domu1
cd /home/xen-servers/domains/domu1
dd if=/dev/zero of=disk.img bs=1M count=2000
dd if=/dev/zero of=swap.img bs=1m count 512

mkfs.ext3 disk.img
mkswap swap.img

mount -o loop disk.img /mnt
debootstrap etch /mnt http://apt-proxy.emergen.biz:1010/debian

cp -pR /boot /mnt/
cp -pR /lib/modules/`uname -r` /mnt/lib/modules/

chroot /mnt /bin/bash

set
/etc/network/interfaces
/etc/resolv.conf
/etc/hosts
/etc/host.conf
/etc/apt/sources.list

exit out and use the following sample for your xen vhost:

# xen config
name ="domu1"
kernel ="/boot/vmlinuz-2.6.16-xen"
ramdisk="/boot/initrd.img-2.6.16-xen"
root ="/dev/sda1 ro"
memory =128
disk = ['file:/home/xen-servers/domains/domu1/disk.img,sda1,w','file:/home/xen-servers/domains/domu1/swap.img,sda2,w']

# network config
vif = [' ip=192.168.0.181 ' ]
ip="192.168.0.181"
netmask="255.255.255.0"
gateway="192.168.0.1"
hostname="web-services.emergen.biz"
extra="4"

--
save file (domu1.cfg) in /etc/xen

start domu with
xm create -c domu1.cfg

The -c attaches a console. Control + ] will detact it. Use xm help for a listing of help commands here.

Configure locales, etc. /etc/mtab errors means you need to remove /etc/mtab (dir) in vserver before booting it again. You may
get similar errors in /var/log/ directories -- just recreate.

No comments:

AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...