KVM/libvirt change CDROM

I was setting up some Windows virtual machines this evening on my Linux KVM/libvirt server, in order to experiment with how Windows handles IPv6 networks.

Installing windows was easy enough – standard virt-install commands, however post-reboot, Windows XP wants to access the CDROM again.

However the reboot causes the CDROM ISO to be unattached from the virtual CDROM drive – so it’s necessary to re-add it to continue installation

However the logical syntax based on virsh help, doesn’t work:

virsh # attach-disk devel-winxp1 /tmp/winxp.iso hdc
error: Failed to attach disk
error: this function is not supported by the connection driver: disk bus 'ide' cannot be hotplugged.

The correct syntax is:

virsh # attach-disk devel-winxp1 /tmp/winxp.iso hdc --type cdrom --mode readonly 
Disk attached successfully

Basically you need to tell libvirt that you’re attaching a *cdrom* and not an actual disk – I’m not sure why it doesn’t just figure that out, based on the fact the user is trying to obviously attach an ISO to a virtual optical drive device – maybe nobody has gotten around to implementing a nice autodetect method yet…

2 thoughts on “KVM/libvirt change CDROM

  1. nitro2k01

    Automatic “intelligence” can be a curse too, and sometimes you want to avoid, especially if the commands were mainly designed to be called from scripts. If you added automatic functionality like that (generally speaking) there’s always the risk that scripts will start behaving strangely.

    In a way this behavior makes perfect sense. The first command is perhaps analogous to disconnecting a physical optical drive (or hard drive or…) and attaching a new one, just to change the disk, while the second one is analogous to just switching the disk in the drive. I’m assuming that even the second line only works if the machine has been configured to have an optical drive on channel hdc before boot…

    Reply
    1. Jethro Carr Post author

      Yeah that is a good point too – I guess some improvements around the UI help would have prevented confusion, when attempting to use attach-disk, it could make a suggestion to use –type cdrom, or display that as an option when using help.

      As it stands, I had to google to find out how to do something that I would have expected to be somewhat intuitive.

      Reply

Leave a Reply