# kvm and cdrom/dvd media detection/change [solved]

## vaxbrat

Does anyone have a good write up on how kvm can handle removeable media such as cdrom and dvd?  I notice that the -cdrom option on startup requires either an iso or media be present when starting the guest.  Also how can kvm get the guest to sense an eject/insert event when a cdrom or dvd is swapped out during a software installation?Last edited by vaxbrat on Mon Apr 13, 2009 11:50 pm; edited 1 time in total

----------

## bbgermany

check out libvirt and virt-manager. this can swap cd-images or drives while running the vm.

bb

----------

## Hu

You can use the -drive option to attach an empty CD drive at start, then insert an ISO via the monitor later.  KVM seems to create this CD drive by default, but you may want to use -drive if you want the CD to appear on a different interface.  The monitor is also able to eject the mounted ISO from the virtual CD drive.

----------

## vaxbrat

So, I finally got some time to play with this again and built virt-manager and related.  I see libvirt uses the kvm USE flag but virt-manager doesn't.  It also didn't give me the option to use anything other than qemu for the hypervisor.  I briefly tried to use xen, but had some troubles building xen and xen-tools so I can understand why I didn't see that.

I also notice that virt-manager thoughtfully decided to set up iptables for me to masquerade for the guests.  That's okay at first blush, but I did have a direct bridge working without masq by just adding a host route record for the guest.  I wanted to go that way since my guest at work would need to be a dhcp client, and I would also want to be able to have inbound connections work since it would get updated via the corporate "spyware" (Altiris).  Under this scheme I would have to play games with with both dnat/snat and it looks like virt-manager is only doing the outbound masquerading.

Hu:  Which monitor are you talking about here?  The virt-manager or some kvm thing?

----------

## Hu

I was referring to the KVM monitor.  Assuming you did not redirect it with the -monitor command line option, it should show up on virtual console 2.  Switch virtual consoles by holding down the grab key sequence and pressing a number.  Virtual console 1 defaults to showing the guest's video output.

----------

## vaxbrat

Ahh.  I think I see what happened here.   You are using the vnc setup while I'm just using sdl when playing with the kvm directly on the comand line.

Also I see that the virt-manager 0.6.0 ebuild DOES NOT include kvm support.  When I pulled the latest source from the homepage (0.7.0), kvm had been added.  I need to do some more checking of protections on this new version (installed to /usr/local) since the new vm wizard has all buttons greyed out and won't let me get past the first of 5 panels.

----------

## Hu

The SDL presentation also allows access to the monitor.  Start kvm with a basic command line, such as kvm -hda mydisk.img -snapshot.  When the window appears, press Ctrl+Alt+2.  You will get the monitor pane that I described.  Press ctrl+alt+1 to return to the guest video card.

The monitor can be moved elsewhere via the -monitor command line option.  Some front ends may do this so that they have more precise control over it.  See the kvm documentation, section 3.3, subsection "Debug/Expert options" for the full list of places that the monitor can be sent.

----------

## vaxbrat

I see that now.  I read that too quickly and thought that you were referencing the standard virtual consoles on ctrl-alt-f1 etc instead of the numeric 1 etc.

One gripe I have now is kvm tends to hold onto my cursor on shutdown if the windows guest decides to not behave and actually shutdown or finally reset.  For some reason the winders corporate loadsets I've been playing with sometimes get into a state where they don't want to finally end it all on a shutdown.  It's annoying since I then have to bop over to another box on the kvm switch, ssh in and kill -9 the kvm instance to get my cursor back.

----------

