How can I automatically switch on num lock before request passphrase to unlock full encrypted disk (LVM)?
3 Answers
You should enter your BIOS before booting and there should be an option allowing you to turn on numlock at startup.

- 11
-
1Thank you, but I have it turned on and after BIOS gives control to OS, numlock switches to state off. – Nik Novák Sep 12 '16 at 21:17
Don't be convinced that NumLock is off just because the indicator light is out. As I mentioned in How do I make the Caps Lock key a third Shift key? " testing shows that the NumLock indicator light is flaky even without a KVM switch and has to be tapped twice to get back in sync with NumLock If you always leave it on you can ignore the light or if it bothers you you can tap it twice to get it back in sync. Why this occurs is likely a basis for a new question..."
Edit:
Enable NumLock during startup
Enabling Numlock on startup can be done in several different ways. First install numlockx:
sudo apt-get install numlockx
Place command with init scripts
More information regarding init scripts can be found for example here and here or with a simple google search
sudo sed -i 's|^exit 0.*$|# Numlock enable\n[ -x /usr/bin/numlockx ] \&\& numlockx on\n\nexit 0|' /etc/rc.local
One way to guarantee that numlock will be turned on after bootup for the TTYs is to run setleds via rc.local (a script run after every runlevel change; which in particular runs after booting up). To do so add something similar to the following in the file /etc/rc.local:
# Turn Numlock on for the TTYs:
for tty in /dev/tty[1-6]; do
/usr/bin/setleds -D +num < $tty
done
Another similar approach:
One might use setleds in /etc/rc to define the initial and default state of NumLock, e.g. by
INITTY=/dev/tty[1-8]
for tty in $INITTY; do
setleds -D +num < $tty
done
Another approach would be to add a reboot cron task this combined with setleds
in your script should do exactly what your looking for.
Sources:
https://help.ubuntu.com/community/NumLock#Enable_NumLock_during_startup
man setleds

- 36,023
- 25
- 98
- 183
-
3Would this answer still apply at the disk-encryption unlock screen, well before X is loaded? – Nick Weinberg Sep 13 '16 at 04:38
-
-
1Everything after the first paragraph, unless I'm mistaken. I don't think
xdotool
would work in a purely console-only environment, before X is loaded. I'm not sure mentioningxev
makes sense either, since it's hard to have "X events" without X. – Nick Weinberg Sep 13 '16 at 20:40 -
@NickWeinberg Point taken and answer edited. Have you had a chance to see if the numlock actually sticks at boot (regardless of indicator light)? – Elder Geek Sep 14 '16 at 02:32
-
@ElderGeek Sorry, but in my case is num lock really turned off and the light indicator is synchronized unlike caps lock whose led indicator is always off. But thank you for your answer. – Nik Novák Sep 14 '16 at 19:58
-
@NikNovák Interesting, I have 2 systems that have very little in common that are demonstrating this behaviour. – Elder Geek Sep 14 '16 at 21:48
-
@ElderGeek I tried the first that you write (sudo sed -i ...), but it doesn't work; at least I don't exactly knew where to save this command or just run it and I don't know how to format it (#!/bin/sh ...) and how to name the file. Could you explain this details please? (Sorry for my English) – Nik Novák Sep 14 '16 at 22:59
-
It looks to me like they are placing it in /etc/rc.local. Perhaps the reboot cron task would be easier. Place the code block above it in a script and call it with cron. The link should make how to do that clear. – Elder Geek Sep 14 '16 at 23:27
-
@ElderGeek Sorry, but I can't understand your solution - I don't know what to do. I don't need num lock on when switching TTY, I just need num lock on when it requests for my passphrase to unlock disk (I have LVM with full disk encryption ). – Nik Novák Sep 17 '16 at 20:55
-
@NikNovák did you try the reboot cron task linked above? Did it work for you? If not, What happened instead? Please [edit] the information into your question to improve the odds of receiving a useful answer. Thank you for helping us help you! – Elder Geek Sep 19 '16 at 12:53
What finally worked for me (on Ubuntu 22.04.2) was to update XKBOPTIONS
in /etc/default/keyboard
to include numpad:pc
.
This enabled the numpad on several occasions during boot, including (albeit without lighting up the indicator in my case) during the disk unlock/decryption step
f.e.:
XKBLAYOUT="us"
XKBOPTIONS="numpad:pc"

- 101
/scripts/init-premount
and/scripts/local-top
(before request for passphrase). However when I tried to find these files I found that no/scripts/*
location exists. Later I found two locations that seems like duplicates:/etc/initramfs-tools/scripts
and/usr/share/initramfs-tools/scripts
. I tried to paste script from here (https://help.ubuntu.com/community/NumLock) to the first one, but it doesn't worked. – Nik Novák Sep 12 '16 at 22:55