How to add a CDROM or DVD drive to a running Xen domainU guest

From Virtuatopia
Jump to: navigation, search

Xen provides great flexibility in terms of dynamically adding block devices such as disk drives and CDROM/DVD drives to running domainU guest systems.

This is achieved using the xm block-attach command, the syntax for which is as follows:

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

where:

  • <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/xvda1

  • <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.

With this information in mind we can now attach a DVD device to a running domainU guest. The first step is to identify the correct device on the domain0 host. The device name varies from one Linux distribution to another so the best way to achieve this is to insert is disk into the drive and run the mount command. For example, the following mount output shows an iso9660 format DVD disk on device /dev/sr0:

/dev/sr0 on /media/LXFDVD100A type iso9660 (ro,nosuid,nodev,uhelper=hal,uid=500)


Next we need to identify the domainU to which we wish to attach the device. A list of running running guests can be obtained using xm list:

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

This shows only one guest running which is XenGuest1 with an ID of 3.

With this information we can now attach our DVD device to the domainU guest:

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

Once the device is attached log into the domainU system and check the device is now visible:

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

Assuming the device is visible all that remain is to mount it:

mount /dev/xvda2 /mnt
mount: block device /dev/xvda2 is write-protected, mounting read-only

The device is now mounted and accessible.

To detach the device first unmount it from the domainU system:

umount /mnt

Finally, detach the device from the domain0 host using xm block-detach combined with the domainU ID and the frontend device name (in this case /dev/xvda2):

xm block-detach 3 /dev/xvda2