no edit summary
the chapter of [[Xen Virtualization Essentials]] we will look at the steps involved in configuring Xen to boot a paravirtualized guest operating system from a disk image file. The approach taken in this chapter involves cloning the root filesystem of the host operating system. This is just one of a number of ways of building a root filesystem for a Xen guest. Other methods are covered in later chapters.
== Xen Requirements ==
In order to boot a Xen guest domain a number of criteria need to be met. Firstly, a Xen enabled host operating system must be installed on the physical hardware and the Xen daemon (xend) must be running. Secondly, a suitable Xen aware kernel and initial RAM Disk for the guest domain must be available and referenced in the Xen configuration file. Thirdly a root filesystem containing the pertinent Linux directories, files libraries and tools necessary for the operating system to boot and function must be available. Finally the guest operating system will need access to some swap space.
In this chapter we assume that the first of the above criteria has been met (in as much as you have the Xen environment for your chosen Linux distribution installed and functioning on your hardware platform). Given this assumption, this chapter will cover in detail the steps necessary to create disk images to store the root filesystem and swap space, populate the root filesystem with the necessary elements of a Linux distribution. Once these steps are complete we will then work through the creation of a Xen configuration file with references to the root and swap disk images, and also appropriate kernel and initial RAM Disk images such that the guest operating system will boot as a Xen guest domain.
Having generated a blank disk image the next task is create a filesystem on it so that it able to store the files and directories that comprise the root filesystem. The following example creates an ext3 type filesystem on our ''XenGuest1.img'' disk image. Note that ''mkfs'' identifies the disk as an image file rather than a block device and seeks confirmation that a filesystem is to be created. When prompted simply enter ''y'':
== Creating a Swap Space Disk Image ==
In order to create a disk image to act as swap for our Xen guest operating system we once again use the ''dd'' command. In
the is instance we will create a 1Gb swap disk image named ''XenGuest1.swap'':
the an image file to act as the swap device we need to format this image as swap space using the ''mkswap'' command as follows:
With the root filesystem and swap space images created it is now necessary to install the
necessary files on the root filesystem in order to make the system functional when it boots.
== Cloning the Host OS on the Guest Domain ==
Having created the mount point and mounted our root filesystem image the next step is to copy the relevant files from the host operating system to guest filesystem image. Execute the following command to copy the required directories and files to the root filesystem (be very careful to substitute the correct destination path if you mounted the filesystem somewhere other than ''/tmp/loop'':
The amount of time the copy process takes to complete will depend to a large extent on the speed of physical disk drive and the number of additional applications and packages installed in the root partition of the host operating system.
Once the copy process is completed a number of directories need to be created (once again the following example assumes the image has been mounted at /tmp/loop):
The ''tmp'' directory created above must have read/write access for all users. To ensure this the chmod command needs to be run:
Note that using the default host system initial RAM disk can cause problems on some Linux distributions. If the system fails to boot it may be necessary to generate an init RAM disk without SCSI modules. Details on this and solutions to other Xen problems can be found at [http://www.linuxtopia.org/ProblemSolutions/index.html Linuxtopia.org]
Next, the amount of memory to be allocated to the guest system is defined using the ''memory = '' directive. The following
assigned 512Mb to the guest:
Finally the ''disk = '' directive is used to map the disk images we have created
with guest operating system devices. The following lines map the root and swap images to ''/dev/xvda1'' and ''/dev/xvda2'' respectively and define the root filesystem as ''/dev/xvda'':
It is important to keep in mind that at this point in the process we have copied all of the system files from our host operating system onto the disk image for our guest operating system. It is vital at this point, therefore, that we change any system configuration files to meet the requirements of our guest domain. Typical settings that will need to be changed are:
* ''/etc/fstab'' - This file contains the mappings between physical and network devices and filesystems. This will need to be changed to reflect the disk
configuiration used by the guest system.
* ''/etc/passwd'' - Contains password information for all user and application accounts on the host system. It is important to remove the entries for any accounts which will not be required on the guest system.
* ''/etc/group'' - This file contains information about user and application groups and, as with the
passd file, should be modified to remove any groups not required in the guest system.
* ''/etc/hosts'' - Contains information about the local host and other hosts on the network. Be sure to change the name of the local host to match the name to be used by the guest operating system.
== Modifying /etc/fstab for the Guest System ==
In the preceding section we talked about the system configuration files which may need to be modified in the root filesystem of the guest operating system. One file which needs particular attention is the ''etc/fstab'' file. The file currently present in the guest root filesystem is a direct replica of the file used by the host operating system. It is almost certain that this file will not be configured to work with the disk represented by our root filesystem and swap images. The following shows a typical file from a CentOS, Red Hat Enterprise Linux or Fedora host operating system: