Home > Uncategorized > CentOS 5 Xen images – part 1: creating a base domU image with yum

CentOS 5 Xen images – part 1: creating a base domU image with yum

Copied from JP Houde’s blog:

I recently needed to configure Xen guests on a CentOS server. I didn’t want to use CentOS/Redhat’s tool for several reasons : I don’t like the fact that it creates a “disk” with a whole partition table within the partition where you install it. Installing the guest directly on a LVM logical volume seems better to me (I may not be right, I’m still somewhat new to Xen!). Also, it was very instructive to do all the steps by myself rather than using a tool that does everything.

However, I had several problems while trying to install my first guest system, so it took me quite some time to find the right way to do it. I found a lot of documentation on the web, but nothing really described what I really wanted to do. So here we are, I decided to write a post describing what to do exactly to make a custom guest image and install it as a Xen domU.

In this first part, I will explain how to make an OS image of CentOS 5 that will be suited for Xen.

Ready to use images

Jailtime.org offer Xen images for several operating systems, including CentOS 4 and 5. However, only 32-bit images are available. If 32-bit images are OK for you, I recommend that you use the jailtime images : it will be a lot easier.
A note about the jailtime.org CentOS image : I found that the console was not working on boot. The OS seemed to just hang after starting SSHD, but in fact, it was just that there was no console for Xen to connect to. If you have this problem, see the part about configuring the console in the “Custom CentOS 5 image” section of this article.

Custom CentOS 5 image

Since I wanted 64-bit domUs, I decided to make my own images. There are few things that need to be modified to make a standard CentOS installation work as a Xen domU. Here are the steps needed to make your own image with yum.

Prepare the environment

  1. Prepare a directory where you will store your image. I will use /mnt/centos.
    Note that you may want to chroot into the image when you need to work within it only. To do so, type :
    cd /mnt/centos; chroot .
    (Don’t chroot now, since there’s nothing in there for now)
  2. Create a special yum configuration file. We need a yum.conf file with “hard coded” architecture and version, instead of the variables the default yum.conf file contains.
    Create /etc/yum-xen.conf with the following content.

    [main]
    cachedir=/var/cache/yum
    keepcache=1
    debuglevel=2
    logfile=/var/log/yum.log
    pkgpolicy=newest
    distroverpkg=redhat-release
    tolerant=1
    exactarch=1
    obsoletes=1
    gpgcheck=1
    plugins=1
    metadata_expire=1800[base]
    name=CentOS-$releasever - Base
    mirrorlist=https://mirrorlist.centos.org/?release=5&arch=x86_64&repo=os
    gpgcheck=1
    gpgkey=https://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    mirrorlist=https://mirrorlist.centos.org/?release=5&arch=x86_64&repo=updates
    gpgcheck=1
    gpgkey=https://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
    #packages used/produced in the build but not released
    [addons]
    name=CentOS-$releasever - Addons
    mirrorlist=https://mirrorlist.centos.org/?release=5&arch=x86_64&repo=addons
    gpgcheck=1
    gpgkey=https://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
  3. Install the core packages.
    We will use yum to install a core CentOS system in our target directory.

    yum -c /etc/yum-xen.conf --installroot=/centos -y groupinstall core --disablerepo=extras

    Here, we disable the “extras” repository since we don’t need it, and the variables it contains will make yum fail. You may need to disabled other repositories if you have installed custom ones.

You should now have a base system in your /centos directory ! But that’s not all, we need to modify few things to make our system suitable as a Xen guest.

Changes needed to the base system

As said earlier, you should now chroot in the /centos directory for the next steps. If you don’t do that, you could end up modifying your host OS instead of the image.

  1. Console
    You need to add a console to /etc/inittab, or Xen won’t display any login prompt when the image boot. You can also remove the default TTYs (tty1-tty6), since they won’t be needed in a Xen guest.

    # add a console for xen
    co:2345:respawn:/sbin/mingetty console
    # comment out the default TTYs
    #1:2345:respawn:/sbin/mingetty tty1
    #2:2345:respawn:/sbin/mingetty tty2
    #3:2345:respawn:/sbin/mingetty tty3
    #4:2345:respawn:/sbin/mingetty tty4
    #5:2345:respawn:/sbin/mingetty tty5
    #6:2345:respawn:/sbin/mingetty tty6
  2. You need to disabled TLS (it would slow down the guest)
    # for 32 bit :
    mv /lib/tls /lib/tls.disabled
    # for 64 bit :
    mv /lib64/tls /lib64/tls.disabled
  3. Disable the hardware clock
    The Xen domU will use the host’s clock, so we replace hwclock with an empty shell script

    echo exit 0 > /sbin/hwclock
  4. Disable udev in /etc/rc.sysinit
    Apparently udev is problematic with Xen, so we will comment the line where it’s started in rc.sysinit (line 338):

    #/sbin/start_udev

    UPDATE 2008-02-14 : It seems that it may be a good idea to leave udev enabled after all… I’m getting permissions problem on devices such as /dev/null without udev. Enabling it fix the problem, and does not seem to cause any other problem.

  5. Network configuration.
    If you want, you can define network parameters.
    /etc/sysconfig/network-scripts/ifcfg-eth0

    TYPE=Ethernet
    DEVICE=eth0
    BOOTPROTO=static
    BROADCAST=192.168.0.255
    IPADDR=192.168.0.13
    IPV6ADDR=
    IPV6PREFIX=
    NETMASK=255.255.255.0
    NETWORK=192.168.0.0
    ONBOOT=yes

    /etc/sysconfig/network

    NETWORKING=yes
    HOSTNAME=myhost.l3i.ca
    GATEWAY=192.168.0.1

    /etc/resolv.conf (DNS resolver)

    nameserver 4.2.2.1
    nameserver 4.2.2.2
  6. SELinux
    You may want to disabled SELinux. That’s done in /etc/sysconfig/selinux (put SELINUX=disabled)
  7. Root password
    We need to create a root password and create the password database (or we wouldn’t be able to log in the system).

    pwconv
    passwd root
  8. Create the /etc/fstab file.
    In this file, /dev/sda1 is the root (ext3) filesystem and sda2 is swap. You will need to configure Xen with these device names.

    cat > /etc/fstab
    # This file is edited by fstab-sync - see 'man fstab-sync' for details
    /dev/sda1               /                       ext3    defaults 1 1
    /dev/sda2               none                    swap    sw       0 0
    none                    /dev/pts                devpts  gid=5,mode=620 0 0
    none                    /dev/shm                tmpfs   defaults 0 0
    none                    /proc                   proc    defaults 0 0
    none                    /sys                    sysfs   defaults 0 0
    #(press CTRL+D to end "cat")
  9. Disable HAL
    HAL will fail, so let’s just disable it.

    /sbin/chkconfig haldaemon off
  10. SSH
    A note about SSH : it will fail to generate a key on the first load because there is not /dev/urandom device. You will have to fix it after starting the domU, on the console. The following command will fix it :

    /sbin/MAKEDEV generic
    /etc/init.d/sshd start

You now have an image ready to be used as a Xen guest! Be sure to keep a copy before using it as a domU, so when you need to install another guest, you will have an image ready for it and won’t need to repeat these steps all over again.

Here is a link to an image I made myself using this procedure. You can use it if you don’t want to make your own. It is a 64-bit CentOS 5 core system, and the root password is “zaqxsw”.

In part 2, I will explain how to install a Xen guest from this image. (coming soon!)

Categories: Uncategorized Tags:
  1. richard
    May 19th, 2010 at 12:54 | #1

    There are some problems with your yum-xen.conf, $releasever doesn’t seem to resolve so the mirrorlist’s fail. At least in my centos5.5 install, yum works fine when using the default config ($releasever resolves fine). I tried fixing this by hardcoding a mirror into the conf:

    baseurl=https://mirror.centos.org/centos/5/updates/i386/

    This generates an error that the group core does not exist. “yum grouplist” indeed does not give me the group core.

  1. No trackbacks yet.