Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a KVM virtual machine that is managed via libvirsh. Now I want to use a different ISO image inside the VM.

How do I change the DVD in the virtual drive using virsh?

share|improve this question
up vote 13 down vote accepted

Add CDROM:

attach-disk guest01 /root/disc1.iso hdc --driver file --type cdrom
--mode readonly

Change CDROM:

attach-disk guest01 /root/disc2.iso hdc --driver file --type cdrom
--mode readonly

Remove CDROM:

 attach-disk guest01 " " hdc --driver file --type cdrom
 --mode readonly
share|improve this answer
    
Thanks, rkthr. I test this next week and come back here. +1 anyway :-) – DerMike Jun 10 '11 at 8:24
3  
Thanks for tip. For me it works but only if I remove '--driver file' from the command (version of virsh: 0.9.2). – Lukasz Stelmach Dec 23 '11 at 20:50
    
I had to add --config to the command. Probably due to the fact that the guest wasn't originally configured with a cdrom. This addressed the following: error: internal error: No device with bus 'ide' and target 'hdc'. cdrom and floppy device hotplug isn't supported by libvirt. – user59156 Oct 19 '15 at 15:59

I tried the attach-disk command and it didn't work for me. However, I found this doc on fedora which asks you to use the "update-device" command. This worked for me. You can find the article here: http://docs.fedoraproject.org/en-US/Fedora/18/html/Virtualization_Administration_Guide/sect-Attaching_and_updating_a_device_with_virsh.html

Just for completeness putting the steps here:

  • Create an XML file:

<backingStore/> <target dev='hdc' bus='ide'/> <readonly/> <alias name='ide0-1-0'/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk>

Make sure you don't have the <source> tag in your definition

  • Update the device:

    virsh update-device <guest name> <XML file name>

share|improve this answer
    
That would remove the device, not change the CD as the OP asks. It's also badly copied from your link - it's malformed XML as it stands. – Jack Douglas Nov 22 '14 at 12:07

In libvirt 0.9.12 and maybe earlier, a command change-media exists:

change-media <domain> <path> [<source>] [--eject] [--insert] [--update] [--current] [--live] [--config] [--force]

Change CD:

change-media guest01 hdb /pool/disc.iso

Eject CD:

change-media guest01 hdb --eject
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.