virt-manager keymaps on OS X

I’m not crazy about the lack of a definitive package manager for OS X. I tried for about a day to work with Open Source on OS X, then I built an Ubuntu VM. I’ve been using ssh with X forwarding when I need a graphical interface; OS X has reasonable good built in support for X11. However, others have found that the keymap and meta keys are broken. While I got a kick out of “After some time I discovered that the number 8 is interpreted as Return,” I did need to log in to a guest to do some debugging.

The accepted solution to making Ctrl+Alt release keyboard focus correctly in the vncviewer spawned by virt-manager is to create a .Xmodmap file in your home directory with this content:

clear Mod1
keycode 66 = Alt_L
keycode 69 = Alt_R
add Mod1 = Alt_L
add Mod1 = Alt_R

I killed the X server by focusing on it and choosing quit, and it seemed to be read the .Xmodmap file okay without my needing to restart the entire system.

The workaround for the broken keymap pointed me in the right direction, but I wasn’t happy with the solution. A little digging around the libvirt domain xml reference pointed out that you can add a keymap as an attribute to the vnc element in the domain xml definition. Use ‘virsh edit’ to edit the domain XML and modify the vnc line to add this attribute so it looks like so:

<graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1' keymap='en-us'/>

I destroyed the guest and restarted it and the keyboard worked now without any “8 is now enter” trickery. I’m pretty sure you can choose any keymap from /usr/share/qemu/keymaps. If you use vmbuilder you will want to add this to /etc/vmbuilder/libvirt/libvirtxml.tmpl as well.

19 thoughts on “virt-manager keymaps on OS X

  1. Pingback: Learnings Nov 30th « Rubinauts Blog

  2. Martijn

    Thanks for the tip! Definitely a better solution that all the ‘alias kvm’ methods I’ve seen.

    I just wish this could be made the default keymap somehow. Seems silly to have to do this everytime I create a new guest via virt-manager.

  3. btm Post author

    If I had to do that a lot, I might look into hacking the schema file [1] or modifying the source. Really, the time should be taken to figure out under what circumstances this happens and produce an upstream fix rather than a workaround.

    [1] /usr/share/libvirt/schemas/domain.rng

  4. cbmuser

    I have just checked my domain XML configuration files on my Debian Squeeze kvm host and it seems that the behavior is a bug which has been introduced during the past 6 months. This occurred to me when trying to fix the XML configuration files of my domains according to your instructions and to my very surprise, domains that were installed around September 2010 were not missing the “keymap” line.

    In fact, I have realized already a few weeks ago, that only new domains which I installed were affected by the problem. The old machines did have a proper layout. Thanks to your discovery I am now able to explain this and can confirm that the additional line fixes the problem.

    I suggest reporting a regression bug upstream to virt-manager/libvirt at RedHat Bugzilla [1]. I will check whether this has already been reported and, if not, write a bug report myself.

    Thanks for the debugging,

    Adrian

    [1] https://bugzilla.redhat.com/

  5. pkb

    The bit about the broken keymap is a fantastically useful bit of information — thanks for posting this.

    I combine this with using XQuartz X11 2.6.1 and the preference to swap the ALT_L & ALT_R and Mode_Switch keys.

    Thanks buckets.

  6. Pingback: Using virt-manager on MacOSX with Dvorak keyboard layout | Garion's blog

  7. David Herring

    I am trying to connect via a UK using ssh -X user@ubuntu.server and then running virt-manager. I can send a cntrl-alt-delete having made the .Xmodmap file changes. However I cannot get the keyboard to work properly…specifically it will not send the ‘a’ character. Have set kvm to kvm -f eb-gb and still no joy.

    Any ideas what else to try for a uk mac keyboard ?

    Thx Dave

  8. John C

    FAO David Herring; the problem, I found, is that the mac is using a US keyboard, even the UK ones, so if you follow the original advice and put in the US keymap, it works (well, did for me, snow leopard).

  9. Ivan Lezhnjov IV

    Somewhat related. Using Real VNCViewer I had to press Control_L+Option_L on a Mac OS X to release captured mouse pointer in virt-manager (tbh, took me a while to press Option_L instead of Alt_L and every single other option lol)

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.