I have set up a virtual machine running Windows XP on my Ubuntu laptop. Using the virt-manager
GUI application, I can insert a CD in my drive and go to Details→IDE CDROM 1 and click on the Connect
button. Then the CD becomes available in my virtual machine.
How can I do the same through the command line? Obviously, I'd like to be able to disconnect from the command line too.
Note: I can start the VM from the command line using virsh start testbed
(testbed being the name of the domain/VM).
If you defined no CDROM when you created your virtual machine, you can attach the device even to a running domain (virtual machine) by running the following command:
If you already defined a CDROM, but it pointed to an ISO image, in my experience, you can still run the same command. The
hdc
part needs to match the block device you have in thetestbed
virtual machine.When you want to point to an ISO image again, you replace
/dev/sr0
to the filename on the host, something likeThe documentation suggests using
virsh update-device
, but it is more labour to create an XML definition something like:If you are into this way, save something like that into a file (say
~/cdrom-real.xml
) and then fire:Use virsh's qemu-monitor-command to pass the eject and change commands down to qemu.
First use "info block" to get qemu's device name for your cdrom.
So in my case I'm interested in drive-ide0-0-0. So to change the disk, do this:
Regarding the "info block" command above, the correct way to call it is like this:
ie
I was passing through a BluRay player that didn't work correctly unless I passed it through another way. Here is how I did it based on this article.
https://lime-technology.com/forums/topic/33851-blu-ray-dvd-rom-passthrough/
Find SCSI #:
Edit Domain XML and add this:
Note: Replace scsi_host# with the # found in lssci
I had to force the XML to be accepted as virsh edit gave errors, just press i and then reboot vm to test.
mount -t iso9660 /dev/sr0 /media
You can use whatever device is set for your cdrom in /dev directory. Also /dev/cdrom is a link to the proper device on most Linux systems. The -t is for type of device you are mounting and iso9660 is the universal type for cdrom media.
The mount point can be whatever you want obviously, just make sure it exists.