I have a custom xmodmap file I use, including useful multi-language diacriticals, english quotes, dashes &c. I want to use this map with kmscon, so I need to create a xkb configuration from it. Is there an automated method to do it? Or even a straightforward manual process, since I won't need to do this frequently?


5 Answers 5


Make your own xkb configuration file

The idea is to "read" the current keyboard config (do not call xmodmap), and write your own symbols file based on it. First:

xkbcomp -xkb $DISPLAY

This creates server-0_0.xkb. In this file, take the following block:

xkb_symbols "pc+inet(evdev)+compose(menu)+whatever(option)" {
    key <ESC> { [ Escape ] };

change the first line into:

default xkb_symbols "my_symbols" {
    include "pc+inet(evdev)"
    include "compose(menu)+whatever(option)"

(I think you can break options into as many "include" lines as you like). Change the keys you want to modify and prepend them with override:

override key <AE10>  { [ 0, parenright, degree ]};

Remove all unchanged keys.

System-wide installation

Put all this into /usr/share/X11/xkb/symbols/my_terrific_kb. Now users may load it with setxkbmap my_terrific_kb (in .xinitrc or .xsessionrc). Probably you can put Option "XkbLayout" "my_terrific_kb" in xorg.conf for a system-wide change.

Single-user installation

Put all this into ~/anywhere/my_terrific_kb. Find the XInput id of your keyboard with xinput list. Then run xkbcomp -i <XInput_id> ~/anywhere/my_terrific_kb $DISPLAY.

  • Ok, but what should I do on a system where I am not root? Commented Apr 4, 2016 at 19:48
  • Edited answer. I'm not 100% sure for the last section: I found in my archives I did use xkbcomp to apply my custom xkb config; however I dropped this method in favour of system-wide installation, I can't remember why. Maybe you need a full keyboard definition, not just overrides. Please test. Prepare command-line setxkbmap de in a terminal in case things go wrong (copy-paste a newline to validate the line if Return is also broken)
    – L. Levrel
    Commented Apr 4, 2016 at 20:19
  • Thanks. Looks complicated. I will try it as soon as I find the time for this kind of experiments. Unfortunately also the single-user installation requires root or xinput already installed. I hope the XInput_id will not change from one X session to another.? If there is no easier solution xkb is a really crippled bastard and I will stay with Xmodmap. Commented Apr 4, 2016 at 21:28
  • If the file is readable, you can grep XINPUT /var/log/Xorg.0.log
    – L. Levrel
    Commented Apr 5, 2016 at 8:36
  • 1
    Note that while this starts with "do not call xmodmap", if you ignore that instruction and do call it with the configuration you want to import, and then continue on from there, you'll get a file which includes your previously-defined mappings, making this a handy starting point.
    – mattdm
    Commented Nov 1, 2016 at 13:52

The map file produced by xkbcomp :0 custom-xkb-keymap consists of many components that you can load by simply swapping the arguments xkbcomp custom-xkb-keymap :0. It shows a few warnings here, but seems to work, when I change the layout in the file.

The xkb layout is stored in the symbols directory, e.g. /usr/local/share/X11/xkb/symbols. The path may vary depending on the system. When you need the layout, you need to cut out the part looking like:

xkb_symbols "id+id+id(pc104)" {

and store it in the symbols directory. Please make sure, you don't overwrite any file there! Once it is stored there (for example as mylayout) you can load it by typing setxkbmap mylayout. And this corresponds with the xorg.conf setting Option "XkbLayout" "mylayout" in the section InputDevice (see man page for kbd for further details).

It seems that the other parts in the xkcomp output correspond to the files in the other directories, so if something does not work, you will probably have to split up the custom-xkb-keymap into its components and copy it to the proper directories under /usr/local/share/X11/xkb. But this is something I have never done, yet.

Better layouts

Instead of using raw dumps that look like decompiled code, you can also make your own symbols file, which is more readable. I have got my own custom layout, which will probably not be usable for most of you, but you can still take a look at this short file that I use for programming on German keyboards (just to get an idea how this can look like and what you can do with a symbols file).


I just solved the problem. After I applied my xmodmap configuration, I used xkbcomp :0 custom-xkb-keymap do copy the current xkb keymap (from display :0) to a file named custom-xkb-keymap.

  • 1
    Once you've done that, where do you put the file so that it's loaded automatically?
    – mattdm
    Commented Dec 4, 2015 at 16:58

I had trouble actually installing the keyboard on GNOME (Elementary OS) following the other answers here, but eventually I figured it out.

What I recommend is:

  • Follow the other answers (L. Levrel) to export your current xmodmap to create xkb file from it (e.g. you will have terrific_kb)
  • copy/move this file under /usr/share/X11/xkb/symbols/
  • then open /usr/share/X11/xkb/rule/evdev.xml and add following under the language you want:
        <description>English (US, My Terrific Keyboard)</description>
  • then open the usual "System Settings" > "Keyboard" GNOME UI and select your keyboard.

I also put this quick tutorial under with some of my binding changes: https://github.com/bubersson/init/tree/master/keyboard/xkb-custom-keyboard


There is a similar problem in this thread: Xephyr: keyboard mapping not working properly Similar to the provided solution you can save your keyboard settings with

setxkbmap -display :0 -print > mykeymap

This file can be applied by xkbcomp on other systems:

xkbcomp mykeymap :0

This command can take place in the autostart of gnome or other DE's. I don't know if all manual changes will be taken over, but I think it's worth a try. Where to put this file to be automatically loaded without using xkbcomp, I don't know.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .