[libvirt] eject ISO from cdrom

Shi Jin jinzishuai at yahoo.com
Tue Mar 9 22:06:02 UTC 2010

Hi there,

I am using libvirt+qemu/kvm.
For a guest VM that is running, I could change its cdrom media by running the following virsh command:
virsh attach-disk <vm-id> <path-to-iso-file> hdc --driver file --type cdrom --mode readonly
This will change the media in the cdrom for the guest VM.

Once I am done, I can use virt-manager to disconnect the iso file to the cdrom. The resulting xml file looks like (only showing the relevant part)
    <disk type='file' device='cdrom'>
      <target dev='hdc' bus='ide'/>

However, I am having trouble to do the same task (eject cd media) using virsh command. I am successful in running the "virsh attach-device 1 emptyCD.xml" command where the emptyCD.xml is an xml without the source file path, just like the one above. However, I want to do it by a single command without the need to create xml files. It should be something like
> virsh attach-disk 1 "" hdc --driver file --type cdrom --mode readonly
However, virsh does not like the empty string "".

I also looked at the virt-manager source code, in this case, the python script is
 912         if curpath:
 913             # Disconnect cdrom
 914             self.change_cdrom_media(dev_id_info, None, _type=None)
Basically a None parameter is pass to the API. All I need to find out is how to do the same thing in the "virsh attach-disk" command.

Do you have any suggestions/comments?
Thanks a lot.


Shi Jin, PhD


More information about the libvir-list mailing list