Set Default keyboard in terminal [Solved]

If you are new to Linux or new to Sabayon Linux and just not sure where to post, here ya go. Post without fear of being told to RTFM :)

Moderator: Moderators

Post Reply
stefano.balzarotti
Baby Hen
Posts: 4
Joined: Wed Aug 22, 2018 23:02

Set Default keyboard in terminal [Solved]

Post by stefano.balzarotti » Thu Aug 23, 2018 0:46

I have a problem, every time I boot sabayon in terminal mode or I switch terminal with CTRL + ALT+ F1, the keymaps are wrong.
I have an Italian keyboard and I want the OS recognize and use Italian keymaps as default.
I tried to follow many tutorials I found online, but no one works, I guess in sabayon uses different settings than other distributions.
Thanks.

Fitzcarraldo
Sagely Hen
Posts: 8191
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom
Contact:

Re: Set Default keyboard in terminal

Post by Fitzcarraldo » Thu Aug 23, 2018 1:01

Log-in as the root user.

List the console keymaps available:

Code: Select all

# localectl list-keymaps
Chose the console keymap you wish to use (e.g. Italian):

Code: Select all

# localectl set-keymap it
N.B. The above systemd command does not change the console keymap specified in /boot/grub/grub.cfg, which remains as “vconsole.keymap=us“. You will have to fix that later by editing /etc/default/sabayon-grub and running grub2-mkconfig -o /boot/grub/grub.cfg, as I show further on.

List the X11 keymaps available:

Code: Select all

# localectl list-x11-keymap-layouts
Chose the X11 keymap you wish to use (e.g. Italian):

Code: Select all

# localectl set-x11-keymap it
Update the environment variables and profile to adopt what you specified:

Code: Select all

# env-update && source /etc/profile
Reboot:

Code: Select all

# systemctl reboot
Log-in as the root user.

Fix the console keymap specified in grub.cfg:

Code: Select all

# nano /etc/default/sabayon-grub
and replace "rd.vconsole.keymap=us" with "rd.vconsole.keymap=it", and replace "vconsole.keymap=us" with "vconsole.keymap=it".

Code: Select all

# grub2-mkconfig -o /boot/grub/grub.cfg
Reboot:

Code: Select all

# systemctl reboot

Fitzcarraldo
Sagely Hen
Posts: 8191
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom
Contact:

Re: Set Default keyboard in terminal

Post by Fitzcarraldo » Thu Aug 23, 2018 1:28

When you edit /etc/default/sabayon-grub note that there are two vconsole.keymap variables:

Code: Select all

vconsole.keymap=us rd.vconsole.keymap.us
You need to edit them both:

Code: Select all

vconsole.keymap=it rd.vconsole.keymap.it
I've updated my first post accordingly, to make it clear.

stefano.balzarotti
Baby Hen
Posts: 4
Joined: Wed Aug 22, 2018 23:02

Re: Set Default keyboard in terminal

Post by stefano.balzarotti » Thu Aug 23, 2018 1:58

Most commands I already found on other tutorials, but I missed the part of grub that fixed all.
Thank you very much.

stefano.balzarotti
Baby Hen
Posts: 4
Joined: Wed Aug 22, 2018 23:02

Re: Set Default keyboard in terminal [Solved]

Post by stefano.balzarotti » Thu Aug 23, 2018 8:15

If I want also set the keyboard of GRUB shell, what should I do?
If found many tutorials that generates a keyboard layout with grub-kbdcomp or grub-mklayout, but those commands doesn't work on my distribution.
Thanks in advance.

Fitzcarraldo
Sagely Hen
Posts: 8191
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom
Contact:

Re: Set Default keyboard in terminal [Solved]

Post by Fitzcarraldo » Thu Aug 23, 2018 21:50

grub-kbdcomp is just a shell script that is a wrapper for the Debian ckbcomp utility and grub-mklayout. No Entropy package for ckbcomp exists, although there is a Gentoo Portage package:

Code: Select all

# eix ckbcomp
[I] sys-apps/ckbcomp
     Available versions:  (~)1.164
     Installed versions:  1.164(15:51:32 23/08/18)
     Homepage:            https://anonscm.debian.org/cgit/d-i/console-setup.git
     Description:         Compile an XKB keymap for loadkeys
(eix is a Gentoo Linux Portage command, not a Sabayon Linux command, so do not bother trying it.)

You will have to file a request in the Sabayon Linux Bugzilla for an Entropy package of ckbcomp to be added to the Entropy repository.

Actually, changing the keymap (keyboard layout) for the GRUB shell is far more complicated than for the post-boot virtual console (VT a.k.a. TTY) and X Windows, and I have not been able to do it successfully. Furthermore I believe it may be dependent on whether the machine uses PC BIOS or UEFI, and whether GRUB is using 'terminal_output gfxterm' or 'terminal_output console' (Sabayon Linux uses the former).

If you want to tinker you could try the following, although the chances of it changing the keyboard mapping from us to it are probably zero.

1. As there is no Entropy package for ckbcomp, install it via Portage.

1.1 Install Gentoo's Portage overlay manager.

Code: Select all

# equo install git
# equo install layman
1.2 Synchronise the Gentoo Portage package ebuild tree.

Code: Select all

# emerge --sync
1.3 Synchronise the Sabayon distribution's Gentoo Portage overlay package ebuild tree.

Code: Select all

# layman -S
1.4 Add the Sabayon distribution's Gentoo Portage overlay.

Code: Select all

# layman -a sabayon-distro
1.5 Synchronise the Sabayon distribution's Gentoo Portage overlay package ebuild tree.

Code: Select all

# layman -S
1.6 Install sys-apps/ckbcomp via Portage as there is no Entropy package.

Code: Select all

# emerge -1v ckbcomp
2. Create a new sub-directory to store the GRUB keyboard layout file.

Code: Select all

# mkdir /boot/grub/layouts
3. Convert the X11 keymap to the GRUB keymap. The option for ckbcomp must exist in the directory /usr/share/X11/xkb/symbols/ for this to work.

Code: Select all

# ckbcomp it | grub2-mklayout -o /boot/grub/layouts/it.gkg
Unknown keyboard scan code 0x54
Unknown keyboard scan code 0x65
Unknown keyboard scan code 0x7f
4. Append 'GRUB_TERMINAL_INPUT=at_keyboard' (may need to be 'GRUB_TERMINAL_INPUT=usb_keyboard' instead).

Code: Select all

# nano /etc/default/grub
# tail -n 8 /etc/default/grub

if [ -f "/etc/default/sabayon-grub" ]; then
        # this file is placed by the Sabayon Installer and contains
        # custom GRUB_CMDLINE_LINUX parameters created at install
        # time.
        . /etc/default/sabayon-grub
fi
GRUB_TERMINAL_INPUT=at_keyboard
5. Add insmod and keymap lines as shown below.

Code: Select all

# nano /etc/grub.d/40_custom
# tail -n 2 /etc/grub.d/40_custom
insmod keylayouts
keymap $prefix/layouts/it.gkb
6. Check what locales are available.

Code: Select all

# locale --all-locales | grep -i it
7. Change locale as shown below.

Code: Select all

# nano /etc/default/sabayon-grub
# grep locale /etc/default/sabayon-grub 
GRUB_CMDLINE_LINUX="locale=it_IT dolvm rd.lvm.lv=sabayon_sabayon/swap rd.lvm.lv=sabayon_sabayon/root resume=/dev/mapper/sabayon_sabayon-swap splash vconsole.keymap=it rd.vconsole.keymap=it quiet"
8. Regenerate the grub.cfg file.

Code: Select all

# grub2-mkconfig -o /boot/grub/grub.cfg
9. If the machine uses UEFI rather than PC BIOS, update the GRUB files in the EFI directory.

Code: Select all

# grub2-install --efi-directory=/boot/efi
10. Reboot to check if the it keymap has been loaded for the GRUB shell.

Code: Select all

# systemctl reboot
Good luck!

Fitzcarraldo
Sagely Hen
Posts: 8191
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom
Contact:

Re: Set Default keyboard in terminal [Solved]

Post by Fitzcarraldo » Fri Aug 24, 2018 16:14

I have been investigating further and have the feeling it is not possible to achieve what you want. It appears that the only allowable character codes on the GRUB command line are ASCII (i.e. not Extended ASCII) codes, therefore I assume the keymap is limited to a US keymap. I cannot even change to a British keymap on the GRUB command line, even though I am able to generate the file /boot/grub/layouts/gb.gkb and the GRUB Shell command line accepts the commands 'insmod keylayouts' and 'keymap gb'.

The official GRUB documentation states the following (see https://www.gnu.org/software/grub/manua ... t-terminal):
17.4 Input terminal

Firmware console on BIOS, IEEE1275 and ARC doesn’t allow you to enter non-ASCII characters. EFI specification allows for such but author is unaware of any actual implementations. Serial input is currently limited for latin1 (unlikely to change). Own keyboard implementations (at_keyboard and usb_keyboard) supports any key but work on one-char-per-keystroke. So no dead keys or advanced input method. Also there is no keymap change hotkey. In practice it makes difficult to enter any text using non-Latin alphabet. Moreover all current input consumers are limited to ASCII.
Note that the documentation states 'ASCII', not 'Extended ASCII'. ASCII is limited to codes 000 to 127 (see the character table in e.g. http://www.asciitable.com/).

During my experimentation I also changed GRUB_TERMINAL_OUTPUT="gfxterm" to GRUB_TERMINAL_OUTPUT="console" so that the GRUB menu was not graphical, but it made no difference to the keymap. I also tried GRUB_TERMINAL_INPUT="at_keyboard" and GRUB_TERMINAL_INPUT="usb_keyboard", and the result was the same whichever I used.

So, in summary, I think you are out of luck as far as the GRUB Shell command line is concerned.

stefano.balzarotti
Baby Hen
Posts: 4
Joined: Wed Aug 22, 2018 23:02

Re: Set Default keyboard in terminal [Solved]

Post by stefano.balzarotti » Sat Aug 25, 2018 21:52

ASCII It's ok, I don't need to use special characters on GRUB shell, I doubt it can be useful.
I only need the correct key map because it's really hard to type the right commands with a wrong keyboard map.
I feel there is some problem with sabayon, since keyboard layouts works on Debian :cry:
Nevermind thank you very much for your help.

Fitzcarraldo
Sagely Hen
Posts: 8191
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom
Contact:

Re: Set Default keyboard in terminal [Solved]

Post by Fitzcarraldo » Sun Aug 26, 2018 19:32

You're welcome.

Actually, the problem lies with Gentoo in this case (Sabayon is based on Gentoo). As I mentioned earlier, the Debian utility ckbcomp does not even exist in Sabayon. ckbcomp in Gentoo is only available in the testing branch, and is at Version 1.164, as I mentioned in my third post. As you saw in my third post, even if I install ckbcomp-1.164 via Portage in Sabayon, it does not permit the keymap to be changed on the GRUB command line. However, 1.164 is not the latest version of ckbcomp available in Debian. What version of ckbcomp and grub are you using in Debian? They may be later versions than the versions in Gentoo, which might explain why it works in Debian on your machine. The status today in Gentoo and Sabayon is as follows:

Gentoo Stable
sys-apps/ckbcomp - None.
sys-boot/grub-2.02-r1

Gentoo Testing
sys-apps/ckbcomp-1.164
sys-boot/grub-2.02-r2

Sabayon
sys-apps/ckbcomp - None.
sys-boot/grub-2.02_beta3-r1

I notice that the latest version available in Debian at the moment is 1.185 (https://salsa.debian.org/installer-team ... -setup.git), committed by Holger Wansing on 14 August 2018 (https://salsa.debian.org/installer-team ... tree/1.185). So I created a quick-and-dirty ebuild for ckbcomp-1.185 in a local overlay on one of my laptops running Gentoo Stable, and I installed ckbcomp-1.185. Using that version I created a file /boot/grub/layouts/gb.gkb for a keyboard with the British English layout (my laptops and USB keyboards at home all have the British English layout). The new gb.gkb I generated for GRUB 2.02-r1 made no difference when I used 'terminal_input usb_keyboard' in GRUB, but did make a difference when I used 'terminal_input at_keyboard'. Keys such as \ | ' @ # ~ [ { ] } and " that are in a different location on the British keyboard than on a US keyboard were correctly detected, but there was a delay in characters appearing on the screen and the Enter key was not detected, which therefore makes it useless.

As I find this problem interesting, I will probably experiment further and install the Master version of ckbcomp (sys-apps/ckbcomp-9999 in Gentoo parlance) from Debian (at the moment the latest commit was on 23 August 2018) to see if that makes a difference. I also think GRUB itself may be to blame (I have seen complaints in several other distributions' forums about GRUB's at_keyboard module hanging), so I may also experiment on another of my laptops which has Gentoo Testing installed rather than Gentoo Stable.

Fitzcarraldo
Sagely Hen
Posts: 8191
Joined: Sat Mar 10, 2007 5:40
Location: United Kingdom
Contact:

Re: Set Default keyboard in terminal [Solved]

Post by Fitzcarraldo » Mon Aug 27, 2018 2:40

OK, I have made some further investigations and am now able to select the keymap used on the GRUB command line in Sabayon.

I followed the instructions in my third post but used the following command to generate the it.gkb file instead:

Code: Select all

# ckbcomp it nodeadkeys | grub2-mklayout -o /boot/grub/layouts/it.gkb       
Unknown keyboard scan code 0x54
Unknown keyboard scan code 0x65
Unknown keyboard scan code 0x7f
I used the following command to generate a gb.gkb file as well, as it is possible to switch keyboard layouts from the GRUB command line:

Code: Select all

# ckbcomp gb extd | grub2-mklayout -o /boot/grub/layouts/gb.gkb
Unknown keyboard scan code 0x54
Unknown keyboard scan code 0x65
Unknown keyboard scan code 0x7f
Everything else remains the same as in my third post:

Code: Select all

# tail -n 1 /etc/default/grub
GRUB_TERMINAL_INPUT=at_keyboard

Code: Select all

# tail -n 2 /etc/grub.d/40_custom 
insmod keylayouts
keymap $prefix/layouts/it.gkb

Code: Select all

# grep terminal_input /boot/grub/grub.cfg
terminal_input at_keyboard
# grep gkb /boot/grub/grub.cfg
keymap $prefix/layouts/it.gkb
# grep layouts /boot/grub/grub.cfg
insmod keylayouts
keymap $prefix/layouts/it.gkb
The versions of ckbcomp and grub used in Sabayon are as follows:

Code: Select all

# equo search --installed sys-boot/grub
╠  @@ Searching...
╠      @@ Package: sys-boot/grub-2.02_beta3-r1 branch: 5, [__system__] 
╠          Installed:     version: 2.02_beta3-r1 ~ tag: NoTag ~ revision: 2
╠          Slot:          2
╠          Homepage:      https://www.gnu.org/software/grub/ 
╠          Description:   GNU GRUB boot loader 
╠          License:       BitstreamVera GPL-2-with-font-exception GPL-3
╠   Keywords:  sys-boot/grub
╠   Found:     1 entry

Code: Select all

# equo rescue spmsync
# equo search ckbcomp
╠  @@ Searching...
╠      @@ Package: sys-apps/ckbcomp-1.164 branch: 5, [__system__] 
╠          Installed:     version: 1.164 ~ tag: NoTag ~ revision: 9999
╠          Slot:          0
╠          Homepage:      https://anonscm.debian.org/cgit/d-i/console-setup.git 
╠          Description:   Compile an XKB keymap for loadkeys 
╠          License:       GPL-2
╠   Keywords:  ckbcomp
╠   Found:     1 entry
When I boot a machine with Sabayon installed and I press 'c' when the GRUB menu appears, I see the following if I press each key on the second-to-last row of keys on the keyboard:

Code: Select all

grub> <zxcvbnm,.-
That corresponds to an Italian keyboard layout (https://upload.wikimedia.org/wikipedia/ ... ut.svg.png). As I mentioned before, due to GRUB's limitations only standard ASCII chars are possible, so it is not possible to type characters such as é, è, € etc. on the GRUB command line.

You can tell if the GRUB keylayouts module is loaded by entering the following command on the GRUB command line:

Code: Select all

lsmod
Below is what I then see on the screen of a UEFI machine running up-to-date Sabayon. I have removed the Sabayon logo from the middle of the GRUB graphical menu.

Code: Select all

                                                GNU GRUB  version 2.02~beta3

   Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere
   else TAB lists possible device or file completions. ESC at any time exits.


grub> lsmod
Name    Ref Count       Dependencies
minicmd 1
keylayouts      1
gfxterm_background      1              bitmap,video,extcmd,gfxterm,bitmap_scale,video_colors
bitmap_scale    2               bitmap
video_colors    2
png     1               bitmap,bufio
bitmap  7
search  1               search_label,extcmd,search_fs_file,search_fs_uuid
search_label    2
search_fs_file  2
search_fs_uuid  2
gfxterm 3               video,font
all_video       1               video_cirrus,video_bochs,efi_uga,efi_gop
video_cirrus    2               video_fb,video
video_bochs     2               video_fb,video
efi_uga 2               video_fb,video
efi_gop 2               video_fb,video
video_fb        12
font    5               video,bufio
video   24
loadenv 1               extcmd,disk
disk    2
test    1
normal  1               gettext,boot,extcmd,bufio,crypto,terminal
gzio    0
gettext 3
boot    2
extcmd  8
bufio   10
crypto  2
terminal        2
part_gpt        2
ext2    4               fshelp
fshelp  5
grub>
Shown below is what I see when I perform the following steps on the GRUB command line:
1. press each key on the second-to-last line of keys on the keyboard and press Enter;
2. check which GRUB terminal input module is loaded;
3. change from the Italian to the British keyboard layout;
4. press each key on the second-to-last line of keys on the keyboard and press Enter;
5. switch back to the Italian keyboard layout;
6. press each key on the second-to-last line of keys on the keyboard and press Enter.
In each step the output on the screen is correct:

Code: Select all

grub> <zxcvbnm,.-
error: syntax error.
error: Incorrect command.
error: syntax error.
grub> terminal_input
Active input terminals:
at_keyboard
Available input terminals:
console serial* serial
grub> keymap gb
grub> \zxcvbnm,./
error: can't find command `zxcvbnm,./'.
grub> keymap it
grub> <zxcvbnm,.-
error: syntax error.
error: Incorrect command.
error: syntax error.
grub> 
There is an annoying problem, though, which I think may be due to GRUB's at_keyboard module: I often have to press a key more than once for it to appear on the command line, and sometimes characters appear in upper case even when I have not pressed the Shift key, and I then have to press Backspace and keep trying until the character appears in the correct case. I assume newer versions of GRUB might improve the performance.

EDIT (28 August 2018): I have now also tried the above-mentioned ckbcomp command on my PC BIOS Core i7 laptop running Gentoo Stable with OpenRC (not systemd) with GRUB Version 2.02-r1 and ckbcomp Version 1.185:

Code: Select all

# eix -I grub
[I] sys-boot/grub
     Available versions:  
     (0)    0.97-r16 0.97-r18
     (2)    2.02-r1(2/2.02-r1)^st ~2.02-r2(2/2.02-r2)^st **9999(2/9999)^st
       {custom-cflags debug device-mapper doc efiemu +fonts libzfs mount multislot ncurses netboot nls sdl static test +themes truetype GRUB_PLATFORMS="coreboot efi-32 efi-64 emu ieee1275 loongson multiboot pc qemu qemu-mips uboot xen xen-32" KERNEL="linux"}
     Installed versions:  2.02-r1(2)^st(09:20:53 16/05/18)(fonts nls sdl themes truetype -debug -device-mapper -doc -efiemu -libzfs -mount -multislot -static -test GRUB_PLATFORMS="pc -coreboot -efi-32 -efi-64 -emu -ieee1275 -loongson -multiboot -qemu -qemu-mips -uboot -xen -xen-32")
     Homepage:            https://www.gnu.org/software/grub/
     Description:         GNU GRUB boot loader

Code: Select all

# eix -I ckbcomp
[I] sys-apps/ckbcomp
     Available versions:  (~)1.164 (~)1.185[1]
     Installed versions:  1.185[1](14:41:28 26/08/18)
     Homepage:            https://salsa.debian.org/installer-team/console-setup.git
     Description:         Compile an XKB keymap for loadkeys

[1] "local_overlay" /usr/local/portage

Code: Select all

# ckbcomp it nodeadkeys | grub-mklayout -o /boot/grub/layouts/it.gkb       
Unknown keyboard scan code 0x54
Unknown keyboard scan code 0x65
Unknown keyboard scan code 0x7f

Code: Select all

# grep GRUB_TERMINAL_INPUT /etc/default/grub
GRUB_TERMINAL_INPUT="at_keyboard"

Code: Select all

# tail -n 2 /etc/grub.d/40_custom 
insmod keylayouts
keymap $prefix/layouts/it.gkb

Code: Select all

# grep terminal_input /boot/grub/grub.cfg
terminal_input at_keyboard
# grep gkb /boot/grub/grub.cfg
keymap $prefix/layouts/it.gkb
# grep layouts /boot/grub/grub.cfg
insmod keylayouts
keymap $prefix/layouts/it.gkb
The configured keymaps also work correctly on the GRUB command line on this laptop running Gentoo. Unlike the UEFI Pentium G2030 desktop PC running Sabayon mentioned further up in this post, on the laptop there is no delay in characters appearing on the screen when I press keys and characters are always the correct case.

Post Reply