10

When I boot in GRUB2 and press c, I have access to GRUB shell.

How to change the keyboard layout (language) of this GRUB shell?

Note that I'm booting an Ubuntu VM inside Virtualbox.

4 Answers 4

9

First, check that you're using GRUB 2 (GRUB 0.x works differently).

grub-install --version

Generate a GRUB keyboard layout file. Below is the command for a french keyboard. For other languages, check /usr/share/X11/xkb/symbols/. Filename choice is not important (you can change bepo).

sudo grub-kbdcomp -o /boot/grub/bepo.gkb fr

Edit /etc/default/grub with root rights to have:

#GRUB_HIDDEN_TIMEOUT=0
GRUB_TERMINAL_INPUT="at_keyboard"

Edit /etc/grub.d/40_custom with root rights to have:

#!/bin/sh
exec tail -n +3 $0

insmod keylayouts
keymap /boot/grub/bepo.gkb

Finally:

sudo update-grub

Note: Forget immediately about using the Shift key to display GRUB menu! It may be normal that terminal_input at_keyboard make this key not work anymore. So make sure #GRUB_HIDDEN_TIMEOUT=0 is properly commented.

3
  • 1
    Trying this on Linux Mint 18.3 with german locale (de) completely disabled my keyboard while in grub. Probably because grub-kbdcomp reported multiple times invalid code and invalid identifier
    – xeruf
    Apr 22, 2018 at 16:46
  • Link is dead and solution isn't bullet proof on laptops.
    – Zulgrib
    Apr 27, 2018 at 11:48
  • 2
    Will this work as well for decrypting passphrase typing (full disk encryption including /boot)? Jun 10, 2019 at 18:45
2

Fine-tuning my grub (2.02-2ubuntu8.3), on an old fully functional Asus N73JF (multiboot Windows 7, Windows recovery, Ubuntu 15.10, Ubuntu 18.04...) a custom menu was not an option for me.

sudo grub-kbdcomp -o /boot/grub/layouts/laptop.gkb fr

(Ubuntu's grub2 uses /boot/grub/layouts from 15.10).

Next, I don't open /etc/default/grub nor /etc/grub.d/40_custom: I edit /etc/grub.d/00_header where I replace

    cat << EOF
  set gfxmode=${GRUB_GFXMODE}
  load_video
  insmod gfxterm
EOF

with

    cat << EOF
  set gfxmode=${GRUB_GFXMODE}
  load_video
  insmod gfxterm
  insmod terminal
  terminal_output gfxterm
  insmod keylayouts
  insmod at_keyboard
  terminal_input at_keyboard
  keymap laptop
EOF

Thanks to KrisWebDev for his question-answer: I learn a lot looking inside /boot/grub/i386-pc/.

1
  • I do not have /boot/grub/layouts in Ubuntu 20.04. /boot/grub/i386-pc/ has only binary .mod files. What do you learn from those?
    – jarno
    Jan 24, 2021 at 10:42
0

Comment on comment of jamo to 2nd answer: You can create /boot/grub/layouts manually.

sudo mkdir /boot/grub/layouts
0

Don't do it!

If anyone should try this on a notebook / laptop, don't! Like Zulgrib said in hirs comment this isn't bulletproof, i.a.it can wreak your grub boot-loader.

The German Debian Forum doesn't recommend it either!

This only works if a keyboard is connected that can be addressed with AT or USB. A laptop or notebook keyboard may not work at all and leaves you sitting in front of an unusable GRUB2! In any case, the keyboard of the Lenovo X220 does not work.

German Debian Forum

2
  • This is not an answer and this is an English only site.
    – David
    Feb 8 at 7:01
  • The content of the page I linked to translates to English if you click it.
    – DHC19
    Feb 11 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.