FirstServed Tech Blog - FirstServed and the Art of Server Tuning

How to mount and eject a CD-rom on a Windows Xen guest

Originally, it was possible to access the QEMU console from within a VNC viewer window, by pressing Ctrl-Alt-1.  Since this made for a major security breach – users are able to mount any file on Dom0 this way, the feature has been disabled in recent Xen releases.  That makes for a major problem, since mounting, ejecting and changing CD’s in Windows seems only possible by rebooting the Virtual Machine.

After a bit of trial and error, we came to a solution that allows the mounting and ejecting of CD’s from within Windows:

In your Xen guest config file, you must specify an empty CD device – since without it Windows will fail to recognize a CD-rom device:

disk=['phy:/dev/...,ioemu:hda,w',',hdc:cdrom,r']

Mounting a CD-rom

Execute xm block-list to view the configured bloack devices for your Xen guest:

# xm block-list <vm-id> –long
(768
    ((backend-id 0)
        (virtual-device 768)
        (device-type disk)
        (state 1)
        (backend /local/domain/0/backend/vbd/1/768)
    )
)
(5632
    ((backend-id 0)
        (virtual-device 5632)
        (device-type cdrom)
        (state 1)
        (backend /local/domain/0/backend/vbd/1/5632)
    )
)

Note the cdrom’s device number and detach it from the guest. Use the –force switch, else detaching will fail.

 
# xm block-detach 1 5632 -f

Now reattach the device with the correct path specified ( phy:/dev/cdrom, file:/path/to/some/iso, … ):

# xm block-attach 1 phy:/dev/cdrom /dev/hdc r

Unmounting a CD-rom

Eject the cdrom from Windows by right-clicking on its icon and selecting ‘Eject’.

Eject the cdrom physically from Dom0 if needed:

# eject /dev/cdrom

Remounting a CD-rom

Now’s the fun part: it appears that if you try to remount exactly the same backend device, e.g. /dev/cdrom, the Windows HVM guest will not be signalled that a new device has been inserted.  A workaround for this is to attach and to detach another device first – any will do, as long as it’s different:

# xm block-attach 1 phy:/dev/sda /dev/hdc r
# xm block-detach 1 5632 -f

Then attach your new device:

# xm block-attach 1 phy:/dev/cdrom /dev/hdc r

Leave a Reply

You must be logged in to post a comment.