2

How can I automatically switch on num lock before request passphrase to unlock full encrypted disk (LVM)?

  • I'm not sure what you are asking. What are you trying to accomplish? – Elder Geek Sep 12 '16 at 20:45
  • I try to reach that numlock will be automatically in state on when I am going to type passphrase to unlock encrypted disk. I am talking about this: https://duckduckgo.com/?q=ubuntu+encrypted+disk+passphrase&t=canonical&iax=1&ia=images&iai=http%3A%2F%2Fwww.linuxbsdos.com%2Fwp-content%2Fuploads%2F2014%2F05%2FPartitionSpecs12-600x450.png – Nik Novák Sep 12 '16 at 20:52
  • Why not simply insure that it's on at boot? It's not yet possible for the machine to know in advance what you are going to do and when. – Elder Geek Sep 12 '16 at 20:58
  • And now, do you know answer to my question, please? (I am not native English speaker, so sorry for my expressions) – Nik Novák Sep 12 '16 at 21:02
  • But wait ... I have set my Ubuntu to display boot messages and I can see that there are executed some scripts located in /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
  • See my updated answer – Elder Geek Sep 13 '16 at 15:20

3 Answers3

1

You should enter your BIOS before booting and there should be an option allowing you to turn on numlock at startup.

Jacques
  • 11
1

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

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
  • 3
    Would this answer still apply at the disk-encryption unlock screen, well before X is loaded? – Nick Weinberg Sep 13 '16 at 04:38
  • @NickWeinberg To which part of the answer are you referring? – Elder Geek Sep 13 '16 at 15:24
  • 1
    Everything 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 mentioning xev 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
0

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"
Jonas D.
  • 101