Manage XEN

From T2B Wiki
Jump to navigation Jump to search


Introduction

This howto describes how you can create a Scientific Linux 5 Xen domU instance, without using virt-manager, or its console variant virt-install. Usually, instances require more customization than these tools provide, so it is often better to make instances using the tools that lie underneath. The last section of this howto describes how you can perform the same steps with virsh, a generic tool for management of virtualized domains.

To clear up some terminology that is often confusing to new Xen users: dom0 is the privileged administrative domain of which only one can run. domU is an unprivileged domain, of which many can run at the same time. Although it is an incorrect analogy, it often helps to think of dom0 as the host system, and domU as a guest system.

We recommend to disable SELinux to avoid problem accessing images files located in non standard places.


Installing XEN

Check whether XEN is installed on your running kernel. Otherwise install it:

  yum install kernel-xen xen

Make sure that the xen-enabled kernel is the default one. Modify the file /etc/grub.conf if required.

Creating an image

The following command will create a /var/lib/xen/mailserver.img file of 2048MB, although the actual data blocks are allocated in a lazy fashion:

# dd if=/dev/zero of=/var/lib/xen/images/mailserver.img oflag=direct bs=1M seek=2047 count=1

or

# dd if=/dev/zero of=/var/lib/xen/images/mailserver.img oflag=direct bs=1M count=2048

This will avoid data block allocation problems if the volume that holds the image is full.

To avoid issues with SElinux later, check the SElinux context of the images:

  ls -Z /var/lib/xen/images/mailserver.img

should give eg

-rw-r--r--  root root root:object_r:xen_image_t        /var/lib/xen/images/mailserver.img

Preparing a Xen configuration file for the installation

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:

SL5 i386 XEN images

or

SL5 x86_64 XEN images

Same with older version of SLC: SLC44 i386 XEN images SLC45 i386 XEN images SLC45 x86_64 XEN images

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.img respectively.

Eg for SL50 i386, do

wget -O /boot/vmlinuz-xen-install http://linuxsoft.cern.ch/scientific/50/i386/images/xen/vmlinuz
wget -O /boot/initrd-xen-install.img http://linuxsoft.cern.ch/scientific/50/i386/images/xen/initrd.img


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

kernel = "/boot/vmlinuz-xen-install"
ramdisk = "/boot/initrd-xen-install.img"
extra = "text"
name = "mailserver"
memory = "512"
disk = [ 'tap:aio:/var/lib/xen/images/mailserver.img,xvda,w', ]
vif = [ 'bridge=xenbr0', ]
vcpus=1
on_reboot = 'destroy'
on_crash = 'destroy'

You may want to tune some of the parameters, like

  • the amount of memory that is dedicated to the domU
  • the name of the bridge, if you will be using a different bridge for this domU. Check if the bridge device is available with ifconfig <name_of_bridge>. For the example above use
  ifconfig xenbr0  

Besides that, this configuration file uses a kickstart file to perform the installation automatically. This example explicitly uses a text installation. You can also perform the installation automatically by giving a kickstart file appended to the 'extra' option.


Starting the installation

With the installation configuration set up, you have to launch now the domU instance:

# xm create mailserver

If you configured this domU correctly, the installation will happily start. 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).


Post-install configuration

Now that the installation is finished, this can be a good time to make a copy of the instance image to use as a template. At this point the SSH keys are not generated yet, making it easier to give each instance a unique set of SSH keys.

The installation configuration should now be modified for non-install use. This is the modified configuration:

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. If a GRUB configuration was found, this will be used to boot a kernel. This is very handy, because this will allow you to use/manage kernels in the domU. If yum update pulls in a security updated kernel in the domU, it will automatically be used during the next boot of the domain.

Another change is that we have changed how to handle crashes and reboots. You'll usually want to reboot a domain if a crash or reboot occurs.

With this configuration in place, you can test this domain:

# xm create mailserver

If you have installed SSH, you can log in to that domain through SSH, or you can use the Xen console:

# xm console mailserver

You can now administrate the domain as a usual Linux machine. You can shut down the domain with:

# xm shutdown mailserver

For more information on the options that xm provides, please refer to the xm manual page.


Automatically starting domains

If you would like a domain to start automatically when the (dom0) system is started, move the domain configuration to the /etc/xen/auto directory. For instance:

# mv /etc/xen/mailserver /etc/xen/auto

This will also shut down the domain properly when the system is shut down.


Special settings

To add a new virtual network interface (first check if device ethX is unused and available with ifconfig ethX):

/etc/xen/scripts/network-bridge start vifnum=1 bridge=xenbr1 netdev=eth1




This page has been inspired by this HowTo


Template:TracNotice