I am trying to toggle num-lock on my Raspberry Pi 2 running Raspbian jessie, I need it to run during the initial CLI boot up (before <hostname> login: or startx), I have tried numlockx and setleds but none work until logged in.
I already have a script that runs during boot and was hoping to incorporate it into the existing script.
In case you were wondering it is so I can have num-lock for my password.

- 103
- 4

- 253
- 1
- 2
- 8
-
http://unix.stackexchange.com/search?q=numlock – Ghanima Nov 30 '15 at 14:09
5 Answers
Yup. There's a way.
Open up
/etc/kbd/config
with your favorite editor.Search for a line that says
LEDS=+num
. It should be on line 67 if I'm not mistaken.Uncomment it. I assume you know how to uncomment since I think you know scripting.
Profit.

- 7,136
- 1
- 28
- 52
-
-
1It worked a charm! Now I just have to get used to not pressing numlock – absenthecon Dec 06 '15 at 12:13
-
@TrentFitzpatrick I also have to get used to it, since I got used to pressing numlock on my laptop every boot. – Aloha Dec 06 '15 at 13:49
-
http://imgur.com/OYOi1JB now if only I had a faster way to code..... – absenthecon Dec 06 '15 at 13:53
-
@TrentFitzpatrick Try not doing it on the pi. Maybe mount a folder on the pi as a network drive on Windows, then do the actual coding on Windows (using sublime or notepad++). – Aloha Dec 06 '15 at 14:48
-
@TrentFitzpatrick Or maybe get a comfy chair and place the keyboard on your lap. – Aloha Dec 06 '15 at 14:48
-
1
-
1
-
-
-
-
@PandaLion98 does it work on Rpi B+ with Jessie? I've just tried it and it didn't work – VMMF Jun 23 '16 at 01:27
-
-
2I don't have any file at
/etc/kbd/config
. I triedsudo touch /etc/kbd/config
, but it complained that there was "No such file or directory". – Michael Innes Nov 16 '17 at 22:28 -
-
@pandalion98, yes, the latest version of Raspbian Stretch with desktop – Michael Innes Nov 17 '17 at 23:24
-
While this isn't directly answering the Raspbian Jessie question, for those other Googler's who run Raspbian Stretch, which doesn't have /etc/kbd/config
, here's the solution:
- Install numlockx:
sudo apt-get install numlockx
- Edit this file:
sudo nano /usr/share/lightdm/lightdm.conf.d/01_debian.conf
- At the end of that file, add this line:
greeter-setup-script=/usr/bin/numlockx on
- Save the file and reboot, and you NumLock key should still be on
Sources:
https://www.raspberrypi.org/forums/viewtopic.php?t=192383
which in turn cites:
https://unix.stackexchange.com/questions/375920/numlock-on-startup-on-linux-mint-18-2

- 2,348
- 8
- 25
- 43

- 171
- 1
- 2
-
Good to know there is a solution for X. But sadly that does not help in Raspbian Light. :( – kwasmich May 28 '18 at 09:03
-
1Note also this will not work, as per the question, "before
login: or startx". It will also not work at all unless you are using lightdm (the GUI login). – goldilocks May 28 '18 at 12:25
/etc/kbd/config
has been removed in Raspbian Stretch, but you can set the numlock state using /usr/bin/setleds
instead.
For example, to enable numlock in all VTs:
#!/bin/bash
# Turn Numlock on for the TTYs:
for tty in /dev/tty[1-6]; do
/usr/bin/setleds -D +num < "$tty";
done
You put this script in /usr/local/bin/numlock
, and invoke it at boot time, for example using a systemd service (/etc/systemd/system/numlock.service
):
[Unit]
Description=numlock
[Service]
ExecStart=/usr/bin/numlock
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Enable the service with systemctl enable numlock.service
.
Source: http://forums.debian.net/viewtopic.php?t=134006#p650222

- 121
- 2
-
1Note that this will only work for CLI. It does not work on Stretch on the UI boot. – aaronburro Mar 22 '19 at 16:25
On Raspbian 10 (Buster), there's a slightly easier way. In a terminal:
sudo apt install numlockx
In the default text editor, vim.tiny
, or nano
save the following text into the file ~/.config/autostart/NumLock.desktop
:
[Desktop Entry]
Type=Application
Name=Numlock on
Comment=Set numlock to on at logon
NoDisplay=true
Exec=numlockx on
NotShowIn=GNOME;KDE;XFCE;
That's it. This is based on how the system already configures keyboard and mouse settings.

- 111
- 1
Command line:
sed -i 's/#LEDS=+num/LEDS=+num/' '/etc/kbd/config'

- 11,898
- 7
- 46
- 56
-
How exactly does this work? How would the OP get this to run before setting the hostname and before startx? – Steve Robillard Apr 20 '16 at 22:28
-
You just run it once, it modifies the file forever. It is the programmatic equivalent to the manual steps up there. – Kevin Bougé Apr 21 '16 at 13:53
-
Most sysadmins like to know how the programs/scripts in their systems work. Serious ones audit everything that needs to run in a mission-critical environment. People also like to make sure that random scripts/commands they get online are not malicious. This is why we want to know what this does, not for us, but for the laypeople. – Aloha Nov 18 '17 at 11:59