Cannot set keyboard layout with localectl

Dear EndeavourOS community,

I have recently tried to change the keyboard layout on my EndeavourOS (BSPWM) by following the instructions described in the article “Xorg/Keyboard configuration” of the archlinux wiki and by looking up for solutions on different forums, but unfortunately to no avail.

Below, you can find the keyboard layout settings I have used till the present day, which I received by entering localectl status:

System Locale: LANG=en_US.UTF-8
    VC Keymap: sg
   X11 Layout: ch

Listed below are the XKB settings I obtained from setxkbmap -print -verbose 10:

Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     ch
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwertz)
types:      complete
compat:     complete
symbols:    pc+ch+inet(evdev)
geometry:   pc(pc105)
xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwertz)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+ch+inet(evdev)"	};
	xkb_geometry  { include "pc(pc105)"	};
};

To set the desired system default keyboard mapping for X11 and the virtual console, I used the following command:

localectl set-x11-keymap us "" altgr-intl

I verified, whether the changes were applied by using localectl status; the command displayed the desired settings. Additionally, I inspected /etc/vconsole.conf and /etc/X11/xorg.conf.d/00-keyboard.conf; again, the expected changes were applied to these files.

However, after rebooting the system, the console and X11 keyboard layouts were not set to the values specified in /etc/vconsole.conf and /etc/X11/xorg.conf.d/00-keyboard.conf.

While checking the XKB settings I noticed, that the old settings were being used, although the files /etc/vconsole.conf and /etc/X11/xorg.conf.d/00-keyboard.conf contain the correct specifications.

I assume, the XKB settings are being overridden by the tools provided by EndeavourOS, since a colleague of mine, who is using Arch Linux and not EndeavourOS, had no issues setting the keyboard layout with localectl.

To ensure that the desired XKB settings are being applied correctly every time I log in, I added the following command to my bspwmrc:

setxkbmap -layout us -variant altgr-intl

This solution seems to work fine after I log in, but during the login process (LightDM) the wrong keyboard layout is used.

The current method does not work as preferred, therefore I am seeking for a solution which uses the localectl command and sets the keyboard layout without any issues.

Thank you in advance!

Hello,
could you post the content of /etc/vconsole.conf and /etc/X11/xorg.conf.d/00-keyboard.conf ?

Are you using dracut or mkinitcpio?

Please, define your preferences in more detail in groups (system, user, display manager) and type (message/applications language, typing languages/variations).
Also, do you want/need a real multi-user system, or should every user have the same setup?

Although you have done a nice job reading and testing, this subject is very complicated, and various actors affect the final outcome.

Hi PigOfDestiny,

here is the content of /etc/vconsole.conf:

KEYMAP=us
XKBLAYOUT=us
XKBVARIANT=altgr-intl

and the content of /etc/X11/xorg.conf.d/00-keyboard.conf:

# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us"
        Option "XkbVariant" "altgr-intl"
EndSection

mkinitcpio is installed, I checked this with pacman -Ss mkinitcpio:

endeavouros/mkinitcpio-openswap 0.1.0-3 [installed]
    mkinitcpio hook to open swap at boot time
core/mkinitcpio 35.2-1 [installed]
    Modular initramfs image creation utility
core/mkinitcpio-busybox 1.35.0-1 [installed]
    Base initramfs tools
core/mkinitcpio-nfs-utils 0.3-7 [installed]
    ipconfig and nfsmount tools for NFS root support in mkinitcpio
extra/hwdetect 2023.02.20-1 [installed]
    Hardware detection script with loading modules and mkinitcpio.conf
...

dracut is not installed; pacman -Ss dracut outputs the following:

endeavouros/eos-dracut 1.1-1
    Dracut scripts and hooks for EndeavourOS
endeavouros/kernel-install-for-dracut 1.7-5
    Enables systemd-boot automation using kernel-install with dracut
extra/dracut 056-2
    An event driven initramfs infrastructure

Hi petsam,

setting the United States-International keyboard layout for X11 and the virtual console is what I am trying to achieve.

Regarding my preferences:

System: EndeavourOS (BSPWM)
User: Only one user
Display manager: LightDM

Message/application language: en_US.UTF-8
Typing language/variation: us/altgr-intl

I do not have any special preferences, such as switching between the keyboard layouts or languages. Currently, my system has only one user. Therefore I do not want or need a real multi-user system; the same setup for every user would suffice.

I hope I could answer your questions.

From what I understood your only remaining problem is that you still have the wrong keymap at login, right?

You could try and set the mkinitcpio hook sd-vconsole to /etc/mkinitcpio.conf in the hook section.
After that run sudo mkinitcpio -P to re-generate the initramfs.

This way the keymap should be included to the initramfs and be accessible from early file system.

Edit: Note the wiki page for further information: https://wiki.archlinux.org/title/mkinitcpio
Note that the order of the hooks in the conf-file is relevant.

Hi PigOfDestiny,

yes, the only remaining problem is the wrong keymap at login. I added the sd-vconsole to /etc/mkinitcpio.conf in the hook section as you suggested:

...
HOOKS="base udev autodetect modconf block keyboard keymap consolefont sd-vconsole filesystems fsck"
...

Then I ran sudo mkinitcpio -P and received the following output:

==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'
  -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img --microcode /boot/intel-ucode.img
==> Starting build: '6.2.12-arch1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [modconf]
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: 'xhci_pci'
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [sd-vconsole]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating zstd-compressed initcpio image: '/boot/initramfs-linux.img'
==> Image generation successful
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'fallback'
  -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-fallback.img -S autodetect --microcode /boot/intel-ucode.img
==> Starting build: '6.2.12-arch1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [modconf]
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: 'qed'
==> WARNING: Possibly missing firmware for module: 'bfa'
==> WARNING: Possibly missing firmware for module: 'qla2xxx'
==> WARNING: Possibly missing firmware for module: 'wd719x'
==> WARNING: Possibly missing firmware for module: 'qla1280'
==> WARNING: Possibly missing firmware for module: 'aic94xx'
==> WARNING: Possibly missing firmware for module: 'xhci_pci'
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [sd-vconsole]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating zstd-compressed initcpio image: '/boot/initramfs-linux-fallback.img'
==> Image generation successful

After rebooting the system, the wrong keymap is still being used at login.

Then the easy solution is to set system configuration properly and delete/deactivate any local settings (in your home folder).
This is from my notes for a us, gr keyboard configuration (use your preferred values) :

Do not forget --no-convert. It is important.
Check your .profile , .xprofile, bspwrc and linked scripts for other language settings and delete/deactivate them.
Delete /etc/default/language
At the end, locale.conf, vconsole.conf, and 00-keyboard.conf will have your configuration.
If DM is not following, there are per DE solutions.

Console font

  • Setting console font face
    Check available console fonts (example for Greek)
ls /usr/share/kbd/consolefonts/ | grep gr

In /etc/vconsole.conf add/edit

FONT=eurlatgr

To temporarily show and change the font, while being in TTY

showconsolefont
setfont
setfont eurlatgr

Basic setting of keyboard layout with localectl

Use localectl to set keymap layout and switch.
Find available layouts and options

localectl list-x11-keymap-models
localectl list-x11-keymap-layouts
localectl list-x11-keymap-variants [LAYOUT]
localectl list-x11-keymap-options

Set console keymap layout

localectl --no-convert set-keymap us gr

Additionally, set X11 additional settings

localectl --no-convert set-x11-keymap us,gr pc105 , terminate:ctrl_alt_bksp,grp:lalt_lshift_toggle,grp_led:scroll

After setting, kernel images should be rebuilt, because they read these settings/files.

1 Like

Hi petsam,

sorry for the late reply. I followed your instructions by checking the file ~/.config/bspwm/bspwmrc. I do not have the files ~/.profile and ~.xprofile in my home directory. Neither does the /etc/default/language file exist on my system.

In bspwmrc, I deactivated the following command using #:

# setxkbmap -layout us -variant altgr-intl

Afterwards, I set my console keyboard layout with

localectl --no-convert set-keymap us

and the X11 settings with

localectl --no-convert set-x11-keymap us "" altgr-intl

After rebooting however, the previous keyboard layout is being used and not the one I set above with localectl.

Below are the changes which were applied to the files /etc/vconsole.conf

KEYMAP=us
XKBLAYOUT=us
XKBVARIANT=altgr-intl

and /etc/X11/xorg.conf.d/00-keyboard.conf

# Written by systemd-localed(8), read by systemd-localed and Xorg. It's
# probably wise not to edit this file manually. Use localectl(1) to
# instruct systemd-localed to update it.
Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us"
        Option "XkbVariant" "altgr-intl"
EndSection

setxkbmap -print -verbose 10 command prints out the previous layout.

Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     ch
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwertz)
types:      complete
compat:     complete
symbols:    pc+ch+inet(evdev)
geometry:   pc(pc105)
xkb_keymap {
	xkb_keycodes  { include "evdev+aliases(qwertz)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete"	};
	xkb_symbols   { include "pc+ch+inet(evdev)"	};
	xkb_geometry  { include "pc(pc105)"	};
};

I know this is a stupid question but the command;

localectl --no-convert set-x11-keymap us pc105 altgr-intl

has been executed with Sudo. I don’t see it anywhere. Therefore, I am in principle for specifications to always show the prompt.

This command is actually unnecessary because you specified “no convert” when configuring X11.

Dear EndeavourOS community,

I was finally able to set the keyboard layout successfully by editing the etc/default/keyboard file. I came across this file while I was inspecting the calamares installer source code. I commented out the old configuration and added below the desired keyboard configuration.

# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page.

# XKBMODEL="pc105"
# XKBLAYOUT="ch"
# XKBVARIANT=""
# XKBOPTIONS=""
# 
# BACKSPACE="guess"

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT="altgr-intl"
XKBOPTIONS=""

BACKSPACE="guess"

I don’t find this approach very legit, since I edited the default keyboard configuration file instead of setting the layout with localectl, but it works for me now.

Top :+1:

Then please set to solved

Hi HPF-84E,

the issue still remains that the keyboard layout cannot be set using localectl. Don’t you think I shouldn’t mark it is as solved, since the solution I provided seems to be a “hack”?

My mistake (memory leaks…) I was talking about this file /etc/default/keyboard. It is not used by Arch, but some programs read it (like lightdm).

If you want to test, delete/rename this file and try the rest of the settings.

Since as explained, keyboard layout is different for sections (system, user, console, DM), check and post what setting is active for each of them.

Unless you post a link to relevant justification, please, don’t post what you are not sure. :wink:

It is obsolete for your setup.
It is intented for a systemd init setup. keymap consolefont are doing the same thing.

Hi petsam,

I tried the solution you suggested by renaming /etc/default/keyboard to /etc/default/keyboard-changed. After rebooting, the keyboard layout is set correctly. Thank you for your help and for the explanation. I think, I can mark this post as solved now.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.