Keyboard layout switching

Keyboard layout maps scancodes from a keyboard into characters sent to application. Keyboard layout can also do more complex transformations via so called dead keys which do not output characters on their own but modify output of subsequent keys. An appropriate keyboard layout is required to support both non-QWERTY keyboards as well as QWERTY keyboards used to enter characters outside of ASCII set.

OpenRC
Edit which is documented but not very understandable. It appears that one should choose appropriate keyboard map likely from as the value for keymap and then optionally also pick files from appropriate include directory such as  other locations might or might not work as values for the   variable.

Lastly add to the boot run level.

Custom Keymap
To make your own keymap just look at the provided keymaps in /usr/share/keymaps for examples.

Here is an example custom keymap which is the same as the U.S. qwerty keymap except the forward slash and apostrophe keys are swapped:

To find the keycodes mapped to keys you can view the output of:

or if you can't find your key run:

Just press the key and its keycode will be shown. When you're done wait a few seconds, and showkey will close.

systemd
systemd uses and includes both tty font and keyboard layout settings but lacks advanced settings found in OpenRC. Valid values should match what OpenRC supports for the corresponding variable.

X11
Modern X11 applications usually use libXklavier (das Klavier being German for keyboard so it has nothing to do with a certain K DE) and can be configured by using setxkbmap. Furthermore X11 supports much broader set of keyboard layouts than virtual terminal. It should be kept in mind that proper desktop environment will do its own keyboard layout management and there's no need to directly use aforementioned application but it can come in handy when dealing with broken or lacking keyboard layout management.

KDE4
Open System Settings and navigate to Input Devices module.

Generic desktop environment
Edit and call setxkbmap from there.

Generic X11
Querying existing configuration:

Setting a keyboard layout:

Setting a keyboard layout and its variant:

Finding the supported layouts and variants or values of other xkb properties does not appear to be possible with this application and the only generic way to determine supported values is by examining. For sake of sanity use of a proper desktop environment with its own keyboard layout management is advised.

Editing file
This method is recommended for configuration without desktop environments, in other words just X11 with a window manager. Create the file and configure it with relative keyboard settings.