Skip to content

Instantly share code, notes, and snippets.

@CornelisDenhart
Last active December 29, 2023 00:18
Show Gist options
  • Save CornelisDenhart/cb614625842016008804a7d0003ece3b to your computer and use it in GitHub Desktop.
Save CornelisDenhart/cb614625842016008804a7d0003ece3b to your computer and use it in GitHub Desktop.
Changing Keyboard Repeat Rate for typing LUKS Password in Debian

My problem was, that the keyboard starts after a shorter time pressing down a key with repeating keystrokes than in the normal desktop environment.

This makes it more difficult to correctly enter the passphrase, requiring extra short keystrokes.

After all, in my opinion the repeat keys function makes no sense in an environment without visual feedback, so I wanted to get rid of it.

Since at startup, not the normal Linux is running, but initramfs, the normal settings don't apply here.

The problem is discussed at several places, but no solution worked for me, like these:

So on the command line, there is a command kbdrate. See man kbdrate. However, there is no setting to disable this feature but it can be sufficiently slowed down. kbdrate seems to be installed on every Debian system by default.

So my solution is divided into 2 steps:

1. Integrating kbdrate into initramfs

This can be accomplished by following this guide: https://forums.debian.net/viewtopic.php?t=73452 As root, just create the file nano /usr/share/initramfs-tools/hooks/kbdrate, insert this content and make it executable:

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

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

. /usr/share/initramfs-tools/hook-functions # Provides copy_exec 
rm -f ${DESTDIR}/bin/kbdrate # copy_exec won't overwrite an existing file 
copy_exec /usr/sbin/kbdrate /bin/kbdrate # Takes location in filesystem and location in initramfs as arguments

2. Executing kbdrate inside initramfs when System boots

For this edit the already existing file nano /usr/share/initramfs-tools/scripts/init-top/keymap and add this at the end:

if [ -x /bin/kbdrate ]; then 
       /bin/kbdrate -r 2.0 -d 1000 -s 
fi

This will set the repeat function delay to 1 second and after this generate 2 strokes per second. According to manpage, these are minimum values. Setting -r to 0 will sesult in no effect.

When done, building the initramfs for example: update-initramfs -k 6.1.0-16-amd64 -u

Verification, that kbdrate was integrated: lsinitramfs /boot/initrd.img-6.1.0-16-amd64 | grep kbdr

should give the output: usr/bin/kbdrate

I suggest to try it out on the old kernel first, not to mess up the system.

After reboot, it should work. This was tested with Debian Bookworm on Lenovo Thinkpad T470 and T480, with plymouth activated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment