Mounting and Unmounting CD and DVD Images in Xen

A simple, but often hard to figure out, task with virtualizing with Xen is learning how to mount and unmount, dynamically, CD and DVD image files, also known as ISOs.  This is actually quite simple but the commands are unintuitive.  The first step is to download the ISO file that you while to mount and to place it on the Dom0 filesystem.

The commands that we use are the “xm block-attach” and “xm block-detach” commands.  First we will attach a new ISO file to the CD or DVD drive of a virtualized Windows guest, DomU, on Xen:

xm block-attach 2 file:/tmp/myimage.iso hdc r

In this case we are attaching myimage.iso in Dom0’s /tmp directory to the hdc device of our DomU guest number two.  If you don’t know which guest number you want use the “xm list” command to get a list of all of the images running on your server.  The trailing “r” is for “read only”.  Use “w” if you want your block device to be writable.

Now to detach that same device we will use the following command:

xm block-detach 2 hdc

In this case we are detaching the hdc device’s ISO image from domain number two.

Leave a comment