Changes

Jump to: navigation, search

Building a Xen Guest Domain using Xen-Tools

10,950 bytes added, 19:11, 14 April 2008
New page: In Building a Debian or Ubuntu Xen Guest Root Filesystem using debootstrap we looked at manually building a Debian or Ubuntu based Xen guest domain (domU) by manually creating disk ima...
In [[Building a Debian or Ubuntu Xen Guest Root Filesystem using debootstrap]] we looked at manually building a Debian or Ubuntu based Xen guest domain (domU) by manually creating disk images and a configuration file and then using the ''debootstrap'' tool to populate the root filesystem with a base Linux installation. A much easier way to create a guest Xen system is to use a set of tools called ''Xen-Tools''. There purpose of this chapter, therefore, is to provide an overview of Xen-Tools and work step by step trough the process of creating a bootbale Xen guest domain using these tools.

== Getting Xen-Tools ==

Xen-Tools are available for download from the [http://www.xen-tools.org web site]. Before rushing to this web site to download these tools it is first worth checking if they are available from the repositories for your chosen Linux distribution. This is certain the case for Ubuntu Linux which installs the xen-tools as part of the ''ubuntu-xen-server'' package (if you already have this installed the following command does not need to be run):

<pre>
sudo apt-get install ubuntu-xen-server
</pre>

Once installed the next step is to set up some configuration options.

== Configuring Xen-Tools ==

Before proceeding with the creation of a Xen guest domain we need to decide upon a location in which to store the disk images associated with the domain. For the purposes of this chapter we will be using the ''/xen'' sub-directory. If you plan to use a different location modify the instructions in the remainder of this chapter accordingly.

The default configuration settings used by Xen-Tools are contained in a file named ''xen-tools.conf'' which is typically located in the ''/etc/xen-tools'' directory.

Edit this file to configure the desired defaults. Note that any of these defaults may be overridden using command-line arguments.

== Specifiy Xen-Tools Installation Location ==

Begin by setting the ''dir = '' to the directory into which the tools are to create the Xen guest image files:

<pre>
dir = /xen
</pre>

Alternatively a logical volume management (LVM) logical group may be specified using the ''lvm = '' directive:

<pre>
lvm = myvolgroup
</pre>

== Specifying the Xen-Tools Installation Source and Method ==

Next, specify the mechanism to be used to be used to install the base operating system packages of the guest domain's root filesystem via the ''install-method = '' line of the configuration file. For those using Debian or Ubuntu ''debootstrab'' should be specified. For systems which use the Red Hat Package Manager (RPM) such as Red Hat Linux, CentOS and Fedora use ''rpmstrap''.

If the root filesystem is to be copied from a disk location or extracted from a tar file specify the ''copy'' or ''tar'' options respectively in conjunction with the ''install-source = '' line indicating the location of the filesystem or tar file from which to install.

<pre>
install-method = debootstrap
</pre>

== Configuring Disk Space and Memory for the Xen Guest ==

The size of disk images and memory allocated to the Xen guest system are specified in the following lines:

<pre>
size = 4Gb # Disk image size.
memory = 512Mb # Memory size
swap = 1Gb # Swap size
fs = ext3 # use the EXT3 filesystem for the disk image.
dist = gutsy # Default distribution to install.
image = sparse # Specify sparse vs. full disk images.
</pre>

== Choosing a Linux Distribution ==

The ''dist = '' option defines the release of operating system to be installed. For example, the Gutsy release of Ubuntu is configured to be installed above. Some other options available include:

<pre>
sid - Debian
sarge - Debian
etch - Debian
dapper - Ubuntu
centos4 - CentOS 4
fedora-core4 - Fedora Core 4
fedora-core5 - Fedora Core 5
fedora-core5 - Fedora Core 5
fedora-core6 - Fedora Core 6
fedora-core7 - Fedora Core 7
</pre>

Note that this setting is not relevant if the ''install-method'' is set to ''copy'' or ''tar''.

== Configuring Xen Guest Network Options ==

Network settings are specified via the following lines of the Xen-Tools configuration file:

<pre>
gateway = 192.168.2.1
netmask = 255.255.255.0
broadcast = 192.168.2.255
# dhcp = 1
</pre>

Adjust these to match your environment. For example, if your network provides dynamic IP addresses using DHCP then uncomment (i.e remove the #) on the ''dhcp'' configuration line.

== Configuring the Kernel and RAM Disk ==

Xen guest systems are most often booted using the Kernel and initial RAM Disk or initial filesystem of the host operating system. These files typically reside in the ''/boot'' directory. The Xen-Tools configuration file provides two lines to specify the kernel and initial RAM Disk which are to be used by the guest system. These are as follows:

<pre>
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
</pre>

Modify these lines to point to the appropriate kernel and initial RAM disk for your system.

== Defining the Installation Source ==

If you have chosen to install your Xen guest root filesystem using ''debootstrap'' or ''rpmstrap'' the tools need to know where the package repositories are located. This is defined in the Xen-Tools configuration file via the ''mirror = '' directive. The following example shows the mirror option set to point to an Ubuntu repository:

<pre>
mirror = http://archive.ubuntu.com/ubuntu
</pre>

Alternatively multiple repositories may be specified for each distribution:

<pre>
mirror_etch=http://ftp.us.debian.org/debian
mirror_gutsy=http://archive.ubuntu.com/ubuntu
</pre>

== Miscellaneous Settings Xen-Tools Configuration ==

There are a number of miscellaneous Xen-Tools configuration settings. Perhaps the most useful are the ''boot'' and ''password'' options. If boot is defined to be 1 then the new guest system will automatically boot once the creation process has completed. If password is set to 1 the creation process will prompt for a root password for the guest system prior to completion.

<pre>
boot = 1
passwd = 1
</pre>

Also, the ''accounts'' option can be used if all user accounts on the host to be copied to the Xen guest system:

<pre>
accounts = 1
</pre>

== Xen Guest Console Settings ==

It is necessary to configure the console settings for the Xen guest. Choice are as follows:

<pre>
# serial_device = tty1 #default
# serial_device = xvc0
</pre>

Most recent kernels will work better with the ''serial_device = xvc0'' setting.

== Options Disk Drive Device Naming ==

Finally the device naming conventions used for the disk drives within the guest operating system may be optionally be defined. Xen-Tools defaults ''/dev/sda'' based names, but this can be changed to the more recent ''tap:aio'' based ''xvda'' conventions as follows:

<pre>
# disk_device = sda #default
disk_device = xvda
</pre>

== Building the Xen Guest Images ==

Now that we have completed the configuration process the next step is to generate the images for the Xen guest. This task is performed using the ''xen-create-image'' tool. This tool takes a wide range of command-line options which can be used to override the settings in a configuration file outlined above, or as an alternative to placing configuration settings in the configuration file. The following example creates the images based on the settings we defined in the Xen-Tools configuration file, avoiding the need to extensive use fo command-line options:

<pre>
xen-create-image --hostname=XenUbuntu
</pre>

The creation process will output some information relating to the configuration to be used for the guest Xen domain. Be sure to review this information to ensure it matches expectations (the creation process can take some time to complete so it is best to identify problems early in the creating process rather than discover them after the Xen guest has booted).

<pre>
General Information
--------------------
Hostname : XenUbuntu
Distribution : gutsy
Fileystem Type : ext3

Size Information
----------------
Image size : 4Gb
Swap size : 128Mb
Image type : sparse
Memory size : 128Mb
Kernel path : /boot/vmlinuz-2.6.22-14-xen
Initrd path : /boot/initrd.img-2.6.22-14-xen

Networking Information
----------------------
IP Address : DHCP


Creating swap image: /xen/domains/XenUbuntu/swap.img
Done

Creating disk image: /xen/domains/XenUbuntu/disk.img
Done

Creating ext3 filesystem on /xen/domains/XenUbuntu/disk.img
Done
Installation method: debootstrap
</pre>

The process can take a long time to complete and doesn't provide much in the way of feedback, particularly during the bootstrapping phase. For a more detailed commentary on the installation progress it is worth viewing the log file. This is typically located in /var/log/xen-tools/ and is named based on the name specified by the ''hostname'' command-line flag (in our example, therefore it is named ''XenUbuntu.log''). The best way to monitor this log file is to use the ''tail'' command.

For example:

<pre>
# tail -f /var/log/xen-tools/XenUbuntu.log

Setting up swapspace version 1, size = 134213 kB
no label, UUID=6da7c4eb-924d-46e1-a968-289433e48851
Installation method: debootstrap

Copying files from host to image.
Copying files from /var/cache/apt/archives -> /tmp/RC5uMIyZ8x/var/cache/apt/archives
Done
Done
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Checking component main on http://archive.ubuntu.com/ubuntu...
I: Validating adduser
</pre>

== Booting the Xen Guest System ==

Once the creation process is completed there should be a Xen guest configuration file for the new system located in ''/etc/xen''. In the case of our example this file is called ''XenUbuntu.cfg''. This is atext file so feel free to open it in a editor and review it. Many of the settings defined in the Xen-Tools configuration file should be reflected in this file.

Also the root filesystem and swap images will have been created (and are referenced in the guest configuration file). To review the contents of the root filesystem before attempting to boot the guest domain simply mount the image using the loopback interface. For example, the following command mounts our image at /tmp/mnt:

<pre>
mkir /tmp/mnt
mount -o loop /xen/domain/XenUbuntu/XenUbuntu.img
</pre>

Once the filesystem has been mounted change directory to /tmp/mnt to see the contents of the filesystem.

Be sure to unmount the image before booting the guest:

<pre>
umount /tmp/mnt
</pre>

Finally, the system can be booted using the Xen ''xm create'' command, referencing the Xen guest configuration file created by Xen-Tools:

<pre>
xm create /etc/xen/XenUbuntu.cfg -c
</pre>

All being well, the guest system will now boot. If any boot problems are encountered refer to the [[Solving Common Xen Boot Problems]] chapter of this book.
1,798
edits

Navigation menu