There has been a similar question - but IMHO there has to be a simpler solution. If num-lock is on in the BIOS - why is it turned off during linux boot and/or KDE/Gnome/whatever startup?

1 Answer 1


Linux initializes most peripherals so that they'll be in a known state. This includes the keyboard: Linux's internal data about the keyboard had better match the LEDs, so what Linux does is to turn off the LEDs (as far as I recall, the CPU can't read the state of the LEDs on a PC keyboard) and declare all *Lock to be off.

I like to have NumLock on by default. For Linux text consoles, what I used to do¹ is to run

for t in /dev/tty[0-9]*; do setleds -D +num <$t; done

from a boot script (/etc/rc.local or /etc/init.d/50_local_setleds or wherever the distribution likes to put those).

Nowadays, at least on some distributions such as Debian, you can add LEDS=+num to /etc/console-tools/config (or /etc/kbd/config depending on which one you have).

The X window system has its own keyboard handling, so you need to deal with it separately. What I do is to switch caps lock permanently off (I don't have a Caps Lock key in my layout) and switch num lock permanently on (I don't have a Num Lock key in my layout, and the keypad keys send KP_1 and so on). If you want to retain the modifiers but make Num Lock default on, you can write a small program to call XKbLockModifiers to set the modifier inside X and XChangeKeyboardControl to set the physical LED.

¹ Used to, because I haven't bothered with text consoles in a while.

  • You mention consoles - was there not a kernel-option for numlock in old linux-kernels? 0.x or 1.y? Anyway - is there no Xconfig-option for numlock?
    – Nils
    Oct 26, 2011 at 21:08
  • @Nils Mmmm maybe, I don't remember. I don't think there's anything for X, but I learned about keyboards in X before XKB existed, so I might be missing some of that newfangled stuff from the very late 20th century. Oct 26, 2011 at 21:13
  • 1
    I'll add a note that on Debian, the setting numlock after boot is done by the kbd package which creates an kbd init script.
    – carandraug
    Apr 24, 2014 at 22:11
  • 1
    @Rodrigo The operating system can know the state of a key. What it can't know, as far as I know, is the state of the LED — it can only remember whether it last turned the LED on or off, but that doesn't work across an operating system change (e.g. BIOS → bootloader → Linux). Nov 30, 2016 at 18:05
  • 1
    @Rodrigo That question deals with applications obtaining information from the operating system. The part you are arguing about is how the operating system would obtain the information. Nov 30, 2016 at 18:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .