An Overview of Repository Based Installation
Linux distributions are essentially a collection of many different software packages combined with a Linux kernel. These packages are stored in repositories which may be accessed online to install and update Linux distributions. The key tools for performing these tasks on systems such as Red Hat Linux, Fedora and CentOS are called yum and rpm. Other Linux distributions (such as Debianand Ubuntu) use a different package management system which will be covered in Building a Debian or Ubuntu Xen Guest Root Filesystem using debootstrap.
In terms of creating a Xen guest domain the yum and rpm tools can be used to install the base root filesystem on a blank disk image or partition by downloading the necessary packages from an online repository. This contrasts with the approach described in previous chapters whereby the root filesystem is simply copied from the host operating system
Preparing to Create a Xen Guest Root Filesystem from Repositories
A Xen guest domain needs, at a minimum, a Xen configuration file, a root filesystem, a Linux kernel, an initial RAM Disk and ideally some swap space. In previous chapters we looked at a number of approaches to providing swap space and a root filesystem including the use of disk images, disk partitions and logical volume management. The remainder of this chapter assumes that suitable storage has been configured to hold the root filesystem, that swap space has been configured and a suitable Xen configuration file exists. If you have not yet configured a suitable filesystem for the root files refer to the following chapters (omitting the sections on cloning the host root filesystem) before proceeding with this chapter:
Building a Xen Virtual Guest Filesystem on a Disk Image (Cloning Host System)
Building a Xen Virtual Guest Filesystem on a Physical Disk Partition (Cloning Host System)
Building a Xen Virtual Guest Filesystem using Logical Volume Management (LVM)
Beginning the Installation
The first step in installing the base packages onto the root filesystem for the Xen guest domain is to mount the target filesystem so that it is accessible to the host system. The following steps assume that this filesystem has been mounted in /xen.
Initially, a number of directories and files need to be created in the filesystem in order for yum and rpm to function:mkdir -p /xen/var/lib/rpm mkdir -p /xen/var/log touch /xen/var/log/yum.log
Next the RPM database on the guest filesystem needs to be initialized:rpm --root /xen --initdb
Next the general release description RPM package for the Linux distribution needs to be downloaded and installed. To obtain this file go to the web site for your chosen distribution and look on the download mirrors for the file containing -release- in its name.
Once the package has been downloaded install it as follows:rpm -ihv --nodeps --root /xen centos-release-5-1.0.el5.centos.1.i386.rpm
Finally, use yum to install the full set of base packages for the operating system. The following command will download all required packages from the repository and install them:yum --installroot=/xen -y groupinstall Base
This process involves the download and installation of over 300 packages so may take some time to complete. Upon completion copy the appropriate directories from the /lib/modules directory of the host system to /xen/lib/modules. For example:cp -r /lib/modules/2.6.18-53.1.14.el5xen /xen/lib/modules
Configuring the Guest System using chroot
The next step is to configure the guest system so that it is ready to boot. This is achieved using chroot. For example:chroot /xen
This essentially creates a new shell for us to work on where the root (/) directory is changed to point to /xen. From this shell prompt create a new /etc/fstab which matches the device settings in the Xen configuration file created previously. Also take this opportunity to set up the root password and add any additional users that may be needed.
Booting the Xen Guest System
Now all that remains is to boot the guest operating system. Before issuing the command to do so it is important to note that the system may not boot for a number of reasons. If the system fails to boot be sure to read the Xen Guest Boot Problems section at the end of this chapter.
Before booting the guest system it is important to first unmount the guest root filesystem:umount /xen
With the set up and configuration complete we are now ready to start up the guest OS. This is achieved using the xm create command:xm create XenGuest1.cfg -c
The -c flag above instructs Xen to attach a console to the guest system so that we see output as the system boots.