Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[Solved] Enable numlock right after the kernel boots

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
newuser
Posts: 7
Joined: 2021-08-26 23:37
Has thanked: 2 times
Been thanked: 1 time

[Solved] Enable numlock right after the kernel boots

#1 Post by newuser »

I would like to enable numlock right after the kernel boots. Because I encrypted the disk during the installation and I need to ensure numlock is on when I enter the full-disk encryption password.

I was able to enable numlock in BIOS, and it works, but then it automatically disables itself before entering the full-disk encryption password. I have also been able to set NumLock on by default on my LightDM display manager.

If you know a procedure to enable numlock right after the kernel boots, please comment.

Thanks in advance. :)

Code: Select all

Operating System: Debian GNU/Linux 11 (bullseye)
Kernel: Linux 5.10.0-14-686-pae
Architecture: x86
Last edited by newuser on 2022-05-30 18:30, edited 1 time in total.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Enable numlock right after the kernel boots

#2 Post by Head_on_a_Stick »

https://dev1galaxy.org/viewtopic.php?pid=33465#p33465

Please search the boards before posting. No, wait... :mrgreen:
deadbang

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Enable numlock right after the kernel boots

#3 Post by p.H »

newuser wrote: 2022-05-25 00:30 I need to ensure numlock is on when I enter the full-disk encryption password.
Why ? Are you too lazy to press num lock or shift ?
The passphrase is needed by the initramfs, so I am afraid that /etc/rc.local is too late for what the OP wants.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 132 times

Re: Enable numlock right after the kernel boots

#4 Post by Head_on_a_Stick »

^ Good point, thanks p.H.

@OP: you could try adding my code block as a script (ie, made executable with a #!/bin/sh shebang at the top) and place it at /etc/initramfs-tools/hooks/numlock then regenerate the initramfs:

Code: Select all

# update-initramfs -u -k all
No idea if that would actually work though.
deadbang

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Enable numlock right after the kernel boots

#5 Post by p.H »

/etc/initramfs-tools/hooks/ is for "hook scripts" which are run by update-initramfs when building the initramfs. Scripts meant to be embedded in the initramfs and executed at boot time can be placed in /etc/initramfs-tools/scripts/ subdirectories (init-premount seems a suitable location, see man initramfs-tools).

I guess you also need to create an initramfs hook script to include /usr/bin/setleds into the initramfs (using copy_exec, see above manpage).

Finally, I am not sure that setting all tty's is useful, so maybe remove the loop and just set the current tty.

newuser
Posts: 7
Joined: 2021-08-26 23:37
Has thanked: 2 times
Been thanked: 1 time

Re: Enable numlock right after the kernel boots

#6 Post by newuser »

Thanks for the comments, I enabled numlock on early bootup and also on TTYs.

For the TTYs I edited the rc.local file.
/etc/rc.local

Code: Select all

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

INITTY=/dev/tty[1-8]
for tty in $INITTY; do
        setleds -D +num < $tty
done
exit 0
And for the early bootup

I edited a hook script to include setleds into the initramfs.
/etc/initramfs-tools/hooks/setleds

Code: Select all

#!/bin/sh
PREREQ=""
prereqs()
{
   echo "$PREREQ"
}

case $1 in
prereqs)
   prereqs
   exit 0
   ;;
esac

. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
copy_exec /usr/bin/setleds /bin
exit 0
And I edited a boot script placed in init-premount.
/etc/initramfs-tools/scripts/init-premount/start-numlock

Code: Select all

#!/bin/sh
PREREQ=""
prereqs()
{
   echo "$PREREQ"
}

case $1 in
prereqs)
   prereqs
   exit 0
   ;;
esac

#. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
/bin/setleds -D +num
exit 0
Now the 3 scripts has execute permissions.

Finally I ran

Code: Select all

sudo update-initramfs -u
I'm happy with the result because It works on the early boot, and TTYs.
I'll keep looking to get it enabled only on tty6 after the early boot.

Thanks a lot.
Last edited by newuser on 2022-05-30 18:31, edited 1 time in total.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Enable numlock right after the kernel boots

#7 Post by p.H »

newuser wrote: 2022-05-26 14:48 /etc/rc.local

Code: Select all

!/bin/sh
Typo here, missing #.

newuser
Posts: 7
Joined: 2021-08-26 23:37
Has thanked: 2 times
Been thanked: 1 time

Re: Enable numlock right after the kernel boots

#8 Post by newuser »

p.H wrote: 2022-05-28 09:42
newuser wrote: 2022-05-26 14:48 /etc/rc.local

Code: Select all

!/bin/sh
Typo here, missing #.
Sorry, I have pasted the text incompletely. :roll:

Now I leave it like this:
/etc/rc.local

Code: Select all

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

setleds -D -num < /dev/tty1
setleds -D +num < /dev/tty6
exit 0

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Enable numlock right after the kernel boots [solved]

#9 Post by p.H »

Thanks for the feedback.
May I ask why you want it only in tty1 and tty6 ?

newuser
Posts: 7
Joined: 2021-08-26 23:37
Has thanked: 2 times
Been thanked: 1 time

Re: Enable numlock right after the kernel boots [solved]

#10 Post by newuser »

Hi, yes. It's because on the keyboard tty6 it's near to tty7 where the desktop environment seams to be working. So if I run in some trouble in the graphical session, it will be easy to switch and logging in tty with numlock on.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Enable numlock right after the kernel boots [solved]

#11 Post by p.H »

I do not get it. How is it easier to press Ctrl+Alt+F6 than Ctrl+Alt+F1 to F5 ?

CaptainCook
Posts: 1
Joined: 2023-12-17 23:36
Has thanked: 1 time

Re: Enable numlock right after the kernel boots

#12 Post by CaptainCook »

newuser wrote: 2022-05-26 14:48 Thanks for the comments, I enabled numlock on early bootup and also on TTYs.

For the TTYs I edited the rc.local file.
/etc/rc.local

Code: Select all

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

INITTY=/dev/tty[1-8]
for tty in $INITTY; do
        setleds -D +num < $tty
done
exit 0
And for the early bootup

I edited a hook script to include setleds into the initramfs.
/etc/initramfs-tools/hooks/setleds

Code: Select all

#!/bin/sh
PREREQ=""
prereqs()
{
   echo "$PREREQ"
}

case $1 in
prereqs)
   prereqs
   exit 0
   ;;
esac

. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
copy_exec /usr/bin/setleds /bin
exit 0
And I edited a boot script placed in init-premount.
/etc/initramfs-tools/scripts/init-premount/start-numlock

Code: Select all

#!/bin/sh
PREREQ=""
prereqs()
{
   echo "$PREREQ"
}

case $1 in
prereqs)
   prereqs
   exit 0
   ;;
esac

#. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
/bin/setleds -D +num
exit 0
Now the 3 scripts has execute permissions.

Finally I ran

Code: Select all

sudo update-initramfs -u
I'm happy with the result because It works on the early boot, and TTYs.
I'll keep looking to get it enabled only on tty6 after the early boot.

Thanks a lot.
That is awesome thank you so much for the two scripts to initiate num lock after kernel boot. It was super annoying to have to press the num lock button every time i had to enter the decrypt password. So this is great and the only thing that has worked for me so far.

arzgi
Posts: 1185
Joined: 2008-02-21 17:03
Location: Finland
Been thanked: 31 times

Re: Enable numlock right after the kernel boots [solved]

#13 Post by arzgi »

Almost all computers I have had, had a bios option to set numlock at boot. However, it is very advisable to learn scripcting to make linux maintenance easier.

Post Reply