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
- 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) - 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
- 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.
- 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
- 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
- Disable the hardware clock
The Xen domU will use the host’s clock, so we replace hwclock with an empty shell scriptecho exit 0 > /sbin/hwclock
- 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.
- Network configuration.
If you want, you can define network parameters.
/etc/sysconfig/network-scripts/ifcfg-eth0TYPE=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
- SELinux
You may want to disabled SELinux. That’s done in /etc/sysconfig/selinux (put SELINUX=disabled) - 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
- 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")
- Disable HAL
HAL will fail, so let’s just disable it./sbin/chkconfig haldaemon off
- 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!)
Recent Comments