KVM

From Noah.org
Revision as of 06:11, 9 December 2009 by Root (talk | contribs)
Jump to navigationJump to search


KVM Networking

Manual if you want bridging... Gah!

Edit the file /etc/network/interfaces:

auto eth0
iface eth0 inet static
# Don't need to set eth0 since it will get bridged.
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_stp off
bridge_maxage 12
bridge_hello 2

edit libvirt guest XML definition

Edit the file for your given VM. In this example the guest name is model1. In my system the full path is /etc/libvirt/qemu/model1.xml. Look for the interface section and change it to a bridge something like the following:

    <interface type='bridge'>
        <mac address='54:52:00:1e:67:94'/>
        <source bridge='br0'/>
    </interface>

Restart the host's networking

You will notice a momentary interruption of the connection to the machine.

/etc/init.d/networking restart

Restart libvirtd

/etc/init.d/libvirt-bin restart

Start your libvirt client and test the connection

I use `virt-manager` or `virsh`.


KVM network console port

Add the following to /etc/rc.local, where 00:E0:81:2B:0C:C1 is the MAC address of the destination nc listener and 12345 is the listening port:

/sbin/modprobe netconsole netconsole=@/eth0,12345@10.0.0.1/00:E0:81:2B:0C:C1

The log client is just the NetCat command:

nc -dul 12345

It helps to disable sync logging. Edit /etc/syslog.conf:

 /var/log/messages

to

 -/var/log/messages

Add the following to /etc/rc.local:

echo 9 > /proc/sysrq-trigger

KVM Remote via VNC

This works quite well.

libvirtd

Libvirt does not do the actual virtualization itself. It is just a client-server interface to virtual machines. This allows you to manage the guests remotely through a simple GUI interface. I have not decided if this tool is worth the trouble or not. It's simple to just SSH into a server and manage it from the command-line. Libvirt is still a little rough. It's very fragile. You will find that you have to restart it often:

/etc/init.d/libvirt-bin restart

virsh

The XML config files are stored here: /etc/libvirt/qemu/*.xml.

virsh -c qemu:///system

Common commands. Note that domain is the guest name. Also note that list should really be called list_only_running; you want the --all option to make it actually list all the domains no matter what state they are in.

help
list --all
domstate [domain]
start [domain]
destroy [domain]

localhost

Multiple VNC screen sessions can run on the same machine. By default each session starts at port 5900+session_number. So if you are running just one VNC screem it will usually be mapped to port 5900; the next one will be mapped to 5901; and the next one 5902 and so on.

ssh -N -f -L 5900:192.168.1.13:5900 username@gateway.example.com
vncviewer AutoSelect=0 FullColor=1 localhost

Or like this to view VNC session 0 on the machine 192.168.1.13.

vncviewer AutoSelect=0 FullColor=1 -via username@gateway.example.com 192.168.1.13:0

session 1 on the machine 192.168.1.13:

vncviewer AutoSelect=0 FullColor=1 -via username@gateway.example.com 192.168.1.13:1

Note that when you use via the names and addresses are from the point of view of the gateway machine. So machine 192.168.1.13 on the LAN visible to the gateway machine. You could also just say localhost if you want to connect to a VNC session running on the gateway machine itself.

vncviewer AutoSelect=0 FullColor=1 -via username@gateway.example.com localhost

So why use via at all in that case? Why not just do this?

vncviewer AutoSelect=0 FullColor=1 username@gateway.example.com

Remember that we may still be going through a firewall. Firewalls rarely allow the VNC ports 5900 through. The via option says to go through SSH (port 22), which most firewalls will allow -- plus this adds SSH encryption to the session.

remote KVM server

sudo virt-install --connect qemu:///system --name ubuntu910 --force --ram 512 --file ubuntu910.qcow2 --file-size 12 --cdrom ubuntu-9.10-desktop-i386.iso --vnc --noautoconsole --accelerate --os-type linux --os-variant generic26

Error: Rect too big

This is a bug in the vncviewer. Add these options to the command-line:

AutoSelect=0 FullColor=1
vncviewer AutoSelect=0 FullColor=1 -via username@gateway.example.com localhost:0