Adding Disk, CDROM and DVD Devices to a Running Xen domainU Guest System

From Virtuatopia
Jump to: navigation, search
PreviousTable of ContentsNext
Running and Connecting to VNC Servers on a Xen Guest (domainU) SystemXen Monitoring Tools and Techniques


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


Most Xen domainU guests are configured with access to a number of devices, typically for the root filesystem and swap space. It is not uncommon, however, to need to provide an executing domainU system with temporary access to block devices such as disks and CD/DVD drives.

Fortunately Xen provides considerable flexibility in terms of adding devices to a running domainU guest system and subsequently detaching them when they are no longer required. This chapter will cover the basics of this topic area.




Requirements for Xen domainU Block Device Attachment

Before a block device can be attached to running domainU guest system there are a number of rules which must be observed. These important rules are as follows:

  • The device to be attached must be mounted on the domain0 host system.
  • The device must not already be attached in write mode to any other domainU systems.
  • The domainU system must possess the appropriate drivers to read the filesystem located on the device. This is not usually an issue for Linux filesystems and CD/DVD devices but may be an issue for more rare and exotic filesystems.
  • The device name by which the domainU system will access the device must begin with xdv (for example /dev/xvda1).

An Overview of xm block-attach

Devices are attached to domainU guest system using the xm block-attach command the syntax for which is as follows:

xm block-attach <Domain Id> <Backend Device> <Frontend Device> <Mode>

Each of the commandline arguments warrants a brief explanation:

  • <Domain Id> is the id of the domainU to which the device is to be attached (this can be obtained by running xm list)
  • <Backend Device> represents the device as it is represented on the domain0 host system prefixed with the type. For example:
phy:/dev/sr0
  • <Frontend Device> is the device name for access on the domainU guest system. This name must be prefixed with xvd otherwise the device will not be visible to the domainU guest. For example:
/dev/xvda2
  • <Mode> is the read/write mode under which the device is to be attached. Options are r for read-only, w for read/write and w! for read/write with sharing.

Attaching a Device to a domainU Guest

With the above information in mind we can now attach a device to a domainU guest. The first piece of information we need is the ID of the guest domain. This can be obtained using the xm list command. The following output shows only one guest running on our system and it has an ID of 3:

xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0   875     1     r-----    790.2
XenGuest1                                    3   128     1     ------    190.5

Next we need to know the name by which the device to be added is accessed on the domain0 host (otherwise known as the backend device). For the purposes of this chapter we will assume that we are adding a DVD drive that is visible to the domain0 host system as /dev/sr0. This could equally be a disk drive partition such as /dev/hdb1 or /dev/sda3.

Before performing the attachment, we need to decide on a device name by which the device will be accessible on the domainU system (known as the frontend device). As mentioned previously the device name must be an xvd device (for example /dev/xvda2). Failure to use an xvd device type will result in the device not appearing in the domainU guest. For this chapter we will specify /dev/xvda2.

With the above information gathered we will attach the device. Since we are attaching a DVD drive we will specify read-only mode:

xm block-attach 3 phy:/dev/sr0 /dev/xvda2 r

The device is now attached the domainU system with an ID of 3 and should be accessible from within that guest environment as /dev/xvda2.

Mounting the Device in the domainU Guest

Once the device attachment has been performed the next step is to mount the device on the domainU system. Log into the domainU guest and check the new device is visible and configured:

ls -l /dev/xvda2
brw-r----- 1 root disk 202, 2 2008-05-02 15:46 /dev/xvda2

With the device attached it is ready to be mounted:

mkdir /tmp/mount
mount /dev/xvda2 /tmp/mnt

Detaching a Device from the domainU Guest

To detach a block device from the domainU first unmount it from the guest:

umount /tmp/mnt

Once unmounted from the domainU system move to the domain0 host and detach it using the xm block-detach specifying the domainU ID and the frontend device name (in this case /dev/xvda2):

xm block-detach 3 /dev/xvda2


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



PreviousTable of ContentsNext
Running and Connecting to VNC Servers on a Xen Guest (domainU) SystemXen Monitoring Tools and Techniques