[HowTo] Automatically enabling NumLock on ttys

There are various methods for automatically enabling NumLock in graphical sessions, so I won’t be covering those here, but I personally do find it handy to also have NumLock automatically enabled in tty sessions, and maybe you do too. :wink:


1 - In early userspace

1.1 - If you are using the systemd and sd-vconsole hooks in /etc/mkinitcpio.conf

For this method, you need a package from the AUR, called mkinitcpio-sd-numlock. :backhand_index_pointing_down:

pamac build mkinitcpio-sd-numlock

Next, open /etc/mkinitcpio.conf in an editor — if you’re going to be doing it from the command line, then you’ll need elevated privileges — and add sd-numlock to your HOOKS= line, right after sd-vconsole.

Save the file, and then rebuild your initramfs. :backhand_index_pointing_down:

sudo mkinitcpio -P

1.2 - If you are still using the older base, udev, keymap and consolefont hooks in /etc/mkinitcpio.conf

This approach is similar to the one in 1.1, but the package you now need to install from the AUR is called mkinitcpio-numlock, without the “-sd-” in its name. :backhand_index_pointing_down:

pamac build mkinitcpio-numlock

And of course, this approach also requires you to edit /etc/mkinitcpio.conf, but the hook you must now add is simply called numlock, and it should be put right after consolefont, or if you do not have the consolefont hook, right after the keymap hook.

Save your /etc/mkinitcpio.conf and rebuild your initramfs. :backhand_index_pointing_down:

sudo mkinitcpio -P

2 - From regular userspace (i.e. shortly after the kernel has booted)

2.1 - The easiest way

This method also requires a package from the AUR, called systemd-numlockontty. :backhand_index_pointing_down:

pamac build systemd-numlockontty

After the package has been built and installed, you can immediately enable it in your running instance and have it run at every next boot all in one go, like so… :arrow_down:

sudo systemctl enable --now systemd-numLockOnTty.service

2.2 - The hands-on way

Create a plain text file in /etc/systemd/system/getty@.service.d/ — you could call this file activate-numlock.conf or numlock-on.conf, or something like that — with the following content… :backhand_index_pointing_down:

[Service]
ExecStartPre=/bin/sh -c 'setleds -D +num < /dev/%I'

As the matter of fact, the above is exactly what the systemd-numlockontty package from the AUR does too. :wink:

2.3 - Other methods

Yes, there are yet other methods, but for those I am going to refer to the Arch Wiki. :backhand_index_pointing_down:


Have fun! :wink:

3 Likes