Xen installation and basic configuration

Xen

This page lists the procedure to be followed to create a CentOS 5 domU in Xen, without using virt-manager, or and other GUI tool.

The first step is to install Xen on your host. This could be done with the two steps listed below, rebooting the host and selecting the new xen kernel at bootup from grub menu:

# yum install kernel-xen
# yum install xen

The first step is to create an image.

This image will be the portion on your hard disk that will reserve and hold data related to your particular domU. This will be your domU’s virtual disk.

# dd if=/dev/zero of=/srv/xen/newserver.img oflag=direct bs=1M seek=2047 count=1

This will create a small image file that can grow. If you want to build the while image / reserve the full space of 2048MB now itself, the command to be used is:

# dd if=/dev/zero of=/srv/xen/newserver.img oflag=direct bs=1M count=2048

Make sure root has read-write permission. The group and others should have only read rights.

Xen uses a form of virtualization known as paravirtualization on most CPUs. Here the guest operating system must be modified to use a special hypercall ABI instead of certain architectural features.

Kernel and initrd.img

You can download the kernel and the initrd.img from:
http://mirror.centos.org/centos/5/os/i386/images/xen/
or
http://mirror.centos.org/centos/5/os/x86_64/images/xen/

Put the files in “/boot” folder after renaming them to “/boot/vmlinuz-xen-install” and “/boot/initrd-xen-install” respectively.

When we try to boot up a virtual host these will be the files that will be used.

The next step is to create a configuration file this will be the file user to start the domU. It will have information about the files we discussed above.

# cat /etc/xen/newserver.cfg

kernel = “/boot/vmlinuz-xen-install”
ramdisk = “/boot/initrd-xen-install”
extra = “text ks=http://localhost/minimal-ks.cfg”
name = “newserver”
memory = “256”
disk = [ ‘tap:aio:/srv/xen/newserver.img,xvda,w’, ]
vif = [ ‘bridge=xenbr0’, ]
vcpus=1
on_reboot = ‘destroy’
on_crash = ‘destroy’

This file pulls the minimal-ks.cfg from the local web server. To make sure everything is fine, access the url http://localhost/minimal-ks.cfg.

Listed below is a simple kickstart file.

# cat /var/www/html/minimal-ks.cfg.

install
url --url http://mirror.centos.org/centos/5/os/i386
lang en_US.UTF-8
network --device eth0 --bootproto dhcp

# Bogus password, change to something sensible!

rootpw bogus
firewall --enabled --port=
authconfig --enableshadow --enablemd5
selinux --enforcing --port=22:tcp
timezone --utc Europe/Amsterdam
bootloader --location=mbr --driveorder=xvda --append=”console=xvc0″
reboot

# Partitioning

clearpart --all --initlabel --drives=xvda
part /boot --fstype ext3 --size=100 --ondisk=xvda
part pv.2 --size=0 --grow --ondisk=xvda
volgroup VolGroup00 --pesize=32768 pv.2
logvol / --fstype ext3 --name=LogVol00 --vgname=VolGroup00 --size=1024 --grow
logvol swap --fstype swap --name=LogVol01 --vgname=VolGroup00 --size=256 --grow --maxsize=512

%packages

@core

We can start the installation now.

# cd /etc/xen/
# xm create newserver
# xm console newserver.cfg

Post-install configuration

Now you have a fully functional virtual host with base configuration, and its all stored in the image file “newserver.img”. Copy that to an other image file that can be used as a template.

# cp /srv/xen/newserver.img /srv/xen/cenos_template.img

Now as the os is installed the configuration file needs to be changed so that installation will not happen again.

The previous configuration file was to install the OS. Since its already done now we need to change the file to start the host.

# cat /etc/xen/newserver.cfg

name = “nameserver”
memory = “256”
disk = [ ‘tap:aio:/srv/xen/nameserver.img,xvda,w’, ]
vif = [ ‘bridge=xenbr0’, ]
bootloader=”/usr/bin/pygrub”
vcpus=1
on_reboot = ‘restart’
on_crash = ‘restart’

Now we should be set to start the virtual host.

# cd /etc/xen/
# xm create newserver
# xm console newserver.cfg

We can verify if the host is up by using the command

# xm list
The command to shutdown the host is:

# xm shutdown mailserver

 

Ref: http://wiki.centos.org/HowTos/Xen/InstallingCentOSDomU