Tuesday, 23 April 2013

CD ROM related VM goodness

Need to change the settings for a CD ROM drive on a virtual machine? Here is an example for a physical device and for an .iso image. This needs to be put in the vm config xml file which should be accessed by entering the following command;
virsh edit <vmname>

Firstly for a block device;
<disk type='block' device='cdrom'>
<driver name='qemu' type='raw'/>
<source dev='/dev/sr0'/>
<target dev='hdc' bus='ide'/>
<address type='drive' controller='0' bus='1' unit='0'/>
<readonly/>
</disk>

And for a disk image try this;
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/srv/vmhost-01/ubuntu-12.04.2-server-amd64.iso'/>
<address type='drive' controller='0' bus='1' unit='0'/>
<target dev='hdc' bus='ide'/>
<readonly/>
</disk>

I'm guessing the address line may need adjusting but it should be about right.

vnc for virtual machines over the network

I have recently been playing around with Virtual machines quite a lot using ubuntu + libvirt + KVM etc. I keep coming across a problem which takes me ages to figure out but which should be simple.

Once I have started my vm and connected it to a VNC port I can never get to it over the network from a machine with a graphical interface. You are "supposed" to use ssh to create a secure tunnel to the vm host and connect VNC via that, this seems a bit of overkill however for a fairly secure LAN or if you are connecting via a management vlan that only admin's have access to.

It is probably worth noting that this could be a security risk, do some more research if you are not happy. I suspect that changing "0.0.0.0" in the following lines to "192.168.1.0" or "192.168.1.153" for example would restrict it to your local subnet or a specific machine (assuming the address range is right for your network) but I have not tested this so please don't quote me...

Anyhow, the file we need to edit is;

/etc/libvirt/qemu.conf

the line we need is;

# vnc_listen = "0.0.0.0"

remove the hash, save the file and restart qemu;

service qemu-kvm restart

That should do the job