Using QEMU Disk Images for Xen DomainU Systems

From Virtuatopia
Revision as of 18:51, 29 May 2016 by Admin (Talk | contribs) (Text replacement - "<google>BUY_XEN_ESSENTIALS_BOTTOM</google>" to "<htmlet>xen<htmlet>")

Jump to: navigation, search
PreviousTable of ContentsNext
Building a Xen Guest Domain using Xen-ToolsCreating and Booting a Xen Guest domainU using an NFS Mounted Root Filesystem


Purchase and download the full PDF and ePub versions of this Xen eBook for only $8.99 Add to Cart


In earlier chapters we have looked at using raw disk images and physical disks as filesystems for a Xen based domainU. Another option is to use the disk images used by QEMU. In this chapter we will cover the steps necessary to create a QEMU disk image, install an operating system into it and then use pygrub to boot the system as a Xen guest system (domainU).




Creating a QEMU Disk Image for the Xen domainU

The first step in the process of using QEMU disk images with Xen is to create a disk image. This is achieved using the qemu-img tool. QEMU supports a number of different image types. For the purposes of this chapter we will use the raw type which is the standard and portable disk image used by QEMU by default. The following command-line creates a new QEMU 4GB disk image called XenQemu.img:

qemu-img create -f raw XenQemu.img 4G

Installing the Guest Operating System

At this point we have a raw QEMU disk image which is ready to have an operating system installed within it. In order to install the operating system we will use the QEMU emulator to boot and install from a Linux installation CD. In order to boot from the CDROM drive we need to tell QEMU the CDROM device on the host system (in this case it is /dev/hdc but will be different depending on the Linux distribution and hardware configuration) together with the -boot d command-line argument. Finally, we need to reference the QEMU disk image created above with the -hda flag and the amount of memory to be allocated using -m:

qemu -hda XenQemu.img -cdrom /dev/hdc -boot d -m 256

Once booted follow the instructions to install the guest operating system into the QEMU disk image.

Configuring the Guest Operating System for Xen

Once the installation is completed boot the installed guest system once again using the QEMU environment. This time, however, we are booting from the disk image rather than the installation device so need to specify the -boot c option:

qemu -hda XenQemu.img -boot c -m 256

Once the system has booted the next step is to install Xen support into the guest. This can be achieved either using the package management system for your chosen distribution or by copying the appropriate kernel and initial RAM images into the /boot directory.

If you choose to manually install the Xen kernel and initial RAM images then it will be necessary to add appropriate entries to the GRUB configuration file. The following example shows a /boot/grub/grub.conf file modified to allow the system to boot a Xen enabled kernel:

default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Xen (2.6.18-53.1.14.el5xen)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.1.14.el5xen ro root=LABEL=/
        initrd /initrd-2.6.18-53.1.14.el5xen.img

title Non-Xen (2.6.18-53.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.el5 ro root=LABEL=/
        initrd /initrd-2.6.18-53.el5.img

If you installed the Xen packages using the package management system provided by your Linux distribution it is important to check the /boot/grub/grub.conf file to ensure that it does not attempt to load the Xen hypervisor in the domainU system. If the grub.conf file appears as follows, edit the file so that it is similar to the example shown above:

default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-53.1.14.el5xen)
        root (hd0,0)
        kernel /xen.gz-2.6.18-53.1.14.el5
        module /vmlinuz-2.6.18-53.1.14.el5xen ro root=LABEL=/
        module /initrd-2.6.18-53.1.14.el5xen.img
title CentOS (2.6.18-53.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.el5 ro root=LABEL=/
        initrd /initrd-2.6.18-53.el5.img

Failure to make these changes will likely result in the following message when attempting to boot the Xen guest domain.

Error: (2, 'Invalid kernel', "elf_xen_note_check: ERROR: Not a Xen-ELF image: No ELF notes or '__xen_guest' section found.\n")

Mounting QEMU Disk Image Partitions

Once a QEMU disk image has been created and a guest operating system installed it can sometimes be useful to mount partitions from the disk image on the host system. This is achieved using the lomount utility. For example, if we need to make changes to the GRUB configuration in the /boot filesystem of the domainU filesystem onto /mnt we would execute the following command:

lomount -diskimage XenQemu.img -partition 1 /mnt

Note that the above command assumes /boot is on partition 1 of the QEMU disk image.

pyGRUB and the Xen Configuration File

In order to boot the Xen domainU system we have created we need to use the pygrub tool. This is a special Python tool which is able to reach into a disk image and find the GRUB settings and kernel and RAM disk images. The path to pygrub is, therefore, defined within the Xen domainU configuration file. In this file we also need to specify the mapping for the QEMU disk image, the required memory allocation and boot="c" to indicate we are booting from the disk drive, for example:

bootloader = "/usr/bin/pygrub"
memory = 256
name = "qemuxen"
disk = [ 'file:/home/xen/qemu/qemuxen.img,hda,w' ]
boot = "c"

Booting the Xen domainU System

Once we have everything configured it is time to boot the Xen guest (domainU) system. This is achieved using xm create combined without Xen domainU configuration file which we have named XenQemu.cfg:

xm create XenQemu.cfg -c 

Assuming everything is configured correctly, the pyGRUB menu should appear providing a choice of kernels from which to boot. Select the Xen enabled kernel and press enter to boot the guest domain:

Xen qemu pygrub screen.jpg

If the system fails to boot refer to the section below for solutions to common Xen problems.

Xen Guest Boot Problems

A number of different problems can occur during the boot process of the Xen guest system. Solutions to common Xen problems are as follows:


Cannot find HTML file xen<htmlet> <hr> <table border="0" cellspacing="0" width="100%"> <tr> <td width="20%">[[Building a Xen Guest Domain using Xen-Tools|Previous]]<td align="center">[[Xen Virtualization Essentials|Table of Contents]]<td width="20%" align="right">[[Creating and Booting a Xen Guest domainU using an NFS Mounted Root Filesystem|Next]]<td> <tr> <td width="20%">Building a Xen Guest Domain using Xen-Tools<td align="center"><td width="20%" align="right">Creating and Booting a Xen Guest domainU using an NFS Mounted Root Filesystem<td> <table>.html