0

new to Linux. I've been having a few problems since I installed some time ago, one of the main issues being my keyboard layout defaults to US on a GB keyboard.

I've found the command setxkbmap -layout gb fixes this. Problem is, I have to run it each time I restart the laptop.

I've tried creating a shell script as follows in /etc/init.d

#!/bin/bash 
# A she-bang - says what interpreter to use

### BEGIN INIT INFO
# Provides:          SetKeyboardGB
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Change Keyboard to GB
# Description:       Changes Keyboard to GB on satrtup.
### END INIT INFO

# This will always run (Hopefully) 
setxkbmap -layout gb

exit 0

This executes absolutely fine when I just run it, and I've already ran update-rc.d SetKeyboardGB defaults but it won't seem to run when restarting the laptop. I feel like I've missed something in setting up my init.d script, but I haven't found the documentation easy to follow.

Any help is appreciated.

2 Answers2

0

You could probably get away with creating a service that sets the keyboard like your are trying to do. However that service would have to compete with one that comes with Debian, keyboard-setup. So that is not the answer.

I would recommend running the following as root

# dpkg-reconfigure keyboard-configuration
# service keyboard-setup restart

to set the layout. The latter of the commands should apply the settings, but a proper reboot might be necessary if it does not work.

The keyboard layout settings are stored in /etc/default/keyboard which will be set by dpkg-reconfigure keyboard-configuration.

Best of luck!

Mr.Christer
  • 692
  • 1
  • 10
  • 12
  • Thanks very much for your answer! I'll try this the next chance I have and let you know how I get on. – Good Neighbour Mar 06 '18 at 06:48
  • I verified the above answer and got it to work on both Debian and Ubuntu systems. Just a note: logout followed by a login seems necessary. Here are more details on [keyboard configuration](https://wiki.debian.org/Keyboard) – Mr.Christer Mar 15 '18 at 10:45
  • What does the command `cat /etc/default/keyboard | grep XKBLAYOUT` output? I want to understand why the answer did not work. – Mr.Christer Mar 15 '18 at 10:52
0

I tried the above, but unfortunately it didn't seem to work. The solution was actually a little simpler than I had imagined - I feel dumb for not noticing it. In the bottom right of the LXDE desktop there is an option for keyboard layout which I somehow missed. Despite specifying otherwise during installation, it defaulted to US - I changed this to UK, Extended WinKeys and this seems to have stuck between reboots.

  • Great that you solved it. I believe that most desktop environment offer some graphical interface to change the keyboard layout. I wanted to be more general. – Mr.Christer Mar 15 '18 at 10:48