The Computer Oracle

Change CD-ROM via virsh

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5 Looping

--

Chapters
00:00 Change Cd-Rom Via Virsh
00:14 Answer 1 Score 24
00:36 Accepted Answer Score 19
00:56 Answer 3 Score 1
01:34 Answer 4 Score 0
02:08 Thank you

--

Full question
https://superuser.com/questions/239870/c...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linuxkvm

#avk47



ANSWER 1

Score 24


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



ACCEPTED ANSWER

Score 19


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



ANSWER 3

Score 1


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, and you can find it at Attaching and updating a device with virsh. Here are the steps:

  • 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>
    



ANSWER 4

Score 0


First you have to export existing configuration:

virsh dumpxml guest_name > config.xml

Then you have to open file and copy cdrom section and add the line with iso image path like

<source file='some.iso'/>

So the result is something like

<disk type='file' device='cdrom'>
   <source file='some.iso'/>
   <driver name='qemu' type='raw'/>
   <backingStore/>
   <target dev='hdb' bus='ide'/>
   <readonly/>
   <alias name='ide0-0-1'/>
   <address type='drive' controller='0' bus='0' target='0' unit='1'/>
 </disk>

and save it as cdrom.xml.

After that:

virsh update-device guest_name cdrom.xml

#Device updated successfully