Creating a Xen Virtual Machine (DomU):

-> 1. Introduction
-> 2. Steps Involved
2a. Create Virtual Disk
2b. Create Configuration File
2c. Installing
2d. Post Install
2e. Activating Domains at Boot
-> 3. Management Of DomU

=====================================

-> 1. Introduction

Xen is an open-source virtual machine layer which runs on the bare hardware, allowing multiple operating systems to run on the same hardware at the same time. Xen is optimized for servers – running many instances of Linux or other operating systems, each with their own kernel, securely and cleanly partitioned from each other, on one piece of server hardware.

-> 2. Steps Involved

A Xen Virtual Machine can be build by following the steps described in this guide. We will be creating a Virtual Disk image in the next step to store the data of the VM, and then create its configuration file followed by installation of its OS. Let us start!

2a. Create Virtual Disk

Use ‘dd’ command to create a disk image. This new disk image will be used by the VM to save data. The below command creates a 50GB file, so basically our new VM will be having 50GB of disk space.

# dd if=/dev/zero of=/var/lib/xen/images/mailserver.img bs=1024M count=50

2b. Create Configuration File

Xen uses a configuration file per domain. The configuration for the domain will be slightly different during the installation, because we have to provide installation kernels, and possibly some boot parameters. You will need a domU installation initrd image and kernel. Depending on the machine architecture, both can be downloaded from either URLs:

* http://mirror.centos.org/centos/5/os/i386/images/xen/
* http://mirror.centos.org/centos/5/os/x86_64/images/xen/

You can put them in some sensible directory, and rename them appropriately. In this example, the kernel and initrd image will be named /boot/vmlinuz-xen-install and /boot/initrd-xen-install respectively.

With the images in place, create the installation configuration file, named /etc/xen/mailserver here:

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

As you can see, we have a kickstart file in place (http://localserver/minimal-ks.cfg) to automate installation. An example kickstart file is given below that can be used:

#####################
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
#####################

A complete list of kickstart options that can be used is available for reference here:

* http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/s1-kickstart2-options.html

2c. Installing

With the installation configuration set up, you can launch the domU instance:

# xm create mailserver

If you configured this domU correctly, the installation will happily start. If you chose to do a manual installation, or would like to see kickstart in action, you can attach a console to the domU:

# xm console mailserver

After the installation, the domU will be rebooted and destroyed (since that is the default action for reboots, we will change that later).

2d. Post Install

The installation configuration should now be modified for non-install use. This is the modified configuration (/etc/xen/mailserver):

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

As you can see, this new configuration is not using the kernel and initrd images anymore. Instead, it is using pygrub as a bootloader. pygrub will try to look for a partition holding a filesystem that contains the GRUB configuration in the virtual disk image.

2e. Activating Domains at Boot

Domains can be configured to start when the main node boots:

# chkconfig xendomains on
# ln -s /etc/xen/mailserver /etc/xen/auto/mailserver

-> 3. Management Of DomU

Command ‘xm’ is used to manage Xen VMs. The below commands are based on the newly created VM (‘mailserver’):

Starting ‘mailserver’:

# xm create mailserver

Entering console of ‘mailserver’:

# xm console mailserver

Stopping ‘mailserver’:

# xm shutdown mailserver

Rebooting ‘mailserver’:

# xm reboot mailserver

List all VMs:

# xm list

Reference: CentOS and Red Hat Wiki/Docs. This doc is created for my private reference (so that I do not have to go about and search for the info again πŸ™‚ )