Keymap Problems with Virt-Manager
So here's the problem:
I'm trying to use an Ubuntu 8.04.3 (Hardy) machine as a host for some KVM virtual machines. The Ubuntu server is headless and my management client is an Apple MacBook with Mac OS X 10.5.8 and the X11 server installed.
The basic steps I use to manage the virtual machines are (executed on the Macintosh):
In the xterm connect to the Ubuntu machine with ssh (enabling X11-Forwading):
ssh -X ubuntu.local
Open virt-manager by typing:
sudo virt-manager -c qemu:///system
Up to this step everything works and I get a virt-manager window on my OS X machine.
The real pain begins after connecting to the graphical console of a virtual machine: Every key on my keyboard (an apple keyboard with german layout) results in something completely wrong in the VM. For example pressing Return on my keyboard results in a lowercase j in the VM, t maps to w, 9 maps to - and so on. After some time I discovered that the number 8 is interpreted as Return ...
Addtionally it is not possible to press CRTL+ALT to leave the graphical
console. This can be easily fixed on your Mac by creating a file in your
Home directory (
.Xmodmap with the following content:
clear Mod1 keycode 66 = Alt_L keycode 69 = Alt_R add Mod1 = Alt_L add Mod1 = Alt_R
Luckily I found this snippet in peter's blog.
But this doesn't solved the original problem with the completely b0rked keyboard layout in the VNC session opened by virt-manager. After some time I was able to resolve it with the following method (Everything done on the Ubuntu machine - the KVM host):
Create a file
/usr/local/bin/kvmwith the following contents:
#! /bin/bash exec /usr/bin/kvm -k de "$@"
Be sure to replace
dewith whatever keyboard layout you are using on the client machine.
The path and name of the file is not important, it just has to match the one used in the next step. Be sure NOT to overwrite your
In the config of your virtual machine (has to be done for every VM), which can be found at
/etc/libvirt/qemu/<name>.xmlmodify the following line:
# old: <emulator>/usr/bin/kvm</emulator> # new: <emulator>/usr/local/bin/kvm</emulator>
Restart libvirtd with
The small wrapper, in this example saved as
-k de to kvm (which is basically just qemu) and therefore
instructs qemu to start the VNC server for the virtual machine with the
de. You still have to configure the correct keyboard layout
in the Operating System of the VM, but at least my keyboard now sends the
correct keys to the VM through SSH+X11+VNC ...