Activating numlock on bootup - ArchWiki

Jump to content

# Activating numlock on bootup

From ArchWiki

## Console

### Early bootup (mkinitcpio)

You can enable numlock right after the kernel boots in the initramfs. This is the only way to ensure numlock is on even during full-disk encryption password entry. Install mkinitcpio-numlockAUR and add the `numlock` mkinitcpio hook before `encrypt` in the `/etc/mkinitcpio.conf` HOOKS array:

    /etc/mkinitcpio.conf

    ...
    HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont numlock block encrypt lvm2 filesystems fsck)
    ...

Then regenerate the initramfs for the change to take effect.

Note The `numlock` hook will not work for systemd-based initramfs. In this case, you can install mkinitcpio-sd-numlockAUR and use the `sd-numlock` hook in the mkinitcpio configuration.

An advantage of using this method is that the numlock setting will be replicated in the later boot process, and new virtual consoles will default to having numlock on.

### With systemd service

The factual accuracy of this article or section is disputed.

Reason: numlockx works only with X11, not with wayland. (Discuss in Talk:Activating numlock on bootup)
Tip These steps can be automated by installing the systemd-numlockonttyAUR package and enabling the `numLockOnTty` service.

First install the numlockx package.

Then create a script to set the numlock on relevant TTYs:

    /usr/local/bin/numlock

    #!/bin/bash

    for tty in /dev/tty{1..6}
    do
        /usr/bin/setleds -D +num < "$tty";
    done

Once the script is created, you will need to make it executable. Otherwise the script cannot run.

Then create and enable a systemd service:

    /etc/systemd/system/numlock.service

    [Unit]
    Description=numlock

    [Service]
    ExecStart=/usr/local/bin/numlock
    StandardInput=tty
    RemainAfterExit=yes

    [Install]
    WantedBy=multi-user.target

### Extending getty@.service

This is simpler than using a separate service and does not hardcode the number of VTs in a script. Create a drop-in snippet for `getty@.service` which are applied on top of the original unit:

    /etc/systemd/system/getty@.service.d/activate-numlock.conf

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

Note If you experience any problems, try replacing `ExecStartPre` with `ExecStartPost`, and/or disabling the hint as described below.

To disable the numlock activation hint displaying on the login screen, edit `getty@tty1.service` and add `--nohints` to agetty options:

    [Service]
    ExecStart=
    ExecStart=-/usr/bin/agetty --noreset --nohints --noclear - ${TERM}

### Bash alternative

Add `setleds -D +num` to `~/.bash_profile`. Note that, unlike the other methods, this will not take effect until after you log in.

## X.org

Various methods are available.

### startx

Install the numlockx package and add it to the xinitrc file before any `exec` statement:

    ~/.xinitrc

    numlockx &
    exec window manager

### MATE

By default, MATE saves the last state on logout and restores it during the next login. To enable numlock on every login, you must change the following dconf properties:

    $ dconf write org.mate.peripherals-keyboard remember-numlock-state false
    $ dconf write org.mate.peripherals-keyboard numlock-state 'on'

### KDE Plasma

Go to System Settings > Input & Output > Keyboard, in the Hardware tab, in the NumLock on Plasma Startup section, choose the desired NumLock behavior.

For this to work, make sure that System Settings > System > Session > Background Services > Keyboard Daemon is enabled.

Note If the Background Services section is not accessible through System Settings in KDE Plasma, running the shell command `kcmshell6 kcm_kded` (substituting for your kcmshell version as necessary) should yield this menu.

### GNOME

Run the following command:

    $ gsettings set org.gnome.desktop.peripherals.keyboard numlock-state true

In order to remember last state of numlock key (whether you disabled or enabled), use:

    $ gsettings set org.gnome.desktop.peripherals.keyboard remember-numlock-state true

Alternatively, you can use add `numlockx on` (from numlockx) to a startup script or `~/.profile`.

### GDM

Create the following dconf keyfile:

    /etc/dconf/db/gdm.d/90-numlock

    [org/gnome/desktop/peripherals/keyboard]
    remember-numlock-state=true
    numlock-state=true

According to gsettings definitions, `remember-numlock-state` decides whether to remember and restore the last state of numlock, and `numlock-state` provides an initial value. The mutter source code shows that if `remember-numlock-state` is false, the `numlock-state` setting won't even be touched, and the query function will return a default false value directly.

To prevent GDM from updating the value of `numlock-state` (force a deterministic numlock state), create a `locks` directory and lock it, as the guide says:

    /etc/dconf/db/gdm.d/locks/numlock

    /org/gnome/desktop/peripherals/keyboard/numlock-state

And run the following command:

    # dconf update

This is a general method and also suitable for GDM on Wayland.

### Xfce

In the file `~/.config/xfce4/xfconf/xfce-perchannel-xml/keyboards.xml`, make sure the following values are set to true:

    ~/.config/xfce4/xfconf/xfce-perchannel-xml/keyboards.xml

    <property name="Numlock" type="bool" value="true"/>
    <property name="RestoreNumlock" type="bool" value="true"/>

Note If the file does not exist then open Settings > Keyboard, then check and uncheck the Restore num lock state on startup. This will create the `keyboards.xml` file.

### SDDM

In the file `/etc/sddm.conf`, under the `[General]` section, set `Numlock=on`:

    [General]
    ...
    Numlock=on

### SLiM

In the file `/etc/slim.conf`, find the line and uncomment it (remove the `#`):

    /etc/slim.conf

    numlock             on

### OpenBox

In the autostart file, add:

    ~/.config/openbox/autostart

    numlockx &

### LightDM

See LightDM#NumLock on by default.

### LXDM

Set the option in `lxdm.conf`:

    /etc/lxdm/lxdm.conf

    numlock=1

### LXQt

Set the option in `~/.config/lxqt/session.conf`:

    ~/.config/lxqt/session.conf

    [Keyboard]
    numlock=true

## Wayland

### Sway

See Sway#Activating numlock on startup.

### Hyprland

Set the option in `~/.config/hypr/hyprland.lua` or a referenced file:

    ~/.config/hypr/hyprland.lua

    hl.config({
      input = {
        ...
        numlock_by_default = true,
      },
    })

### Labwc

See Labwc#Activating numlock on startup.

### SDDM with KWIN (KDE Plasma)

Create or edit `/var/lib/sddm/.config/kcminputrc`:

    /var/lib/sddm/.config/kcminputrc

    [Keyboard]
    NumLock=0

The file must be owned by `sddm:sddm`

### Plasma Login Manager

Edit `/var/lib/plasmalogin/.config/kdedefaults/kcminputrc`:

    /var/lib/plasmalogin/.config/kdedefaults/kcminputrc

    [Keyboard]
    NumLock=0

The file must be owned by `plasmalogin:plasmalogin`

### DWL

Initialize the `xkb_rules` struct with the `numpad:mac` option:

    [dwl_source_root]/config.def.h

    static const struct xkb_rule_names xkb_rules = {
      .options = "numpad:mac",
    };

Categories:

- Boot process
- Keyboards

Hidden category:

- Pages or sections flagged with Template:Accuracy

Activating numlock on bootup
Add topic