systemd: automate modprobe command at boot time

On any distro using systemd you can automatically load the module via modules-load.d:

  • create the config file:

    /etc/modules-load.d/rt2800usb.conf

  • open it and edit like this (add the module name):

    rt2800usb

  • next time you reboot the module should be automatically loaded


Troubleshooting:

Check if systemd service loaded the module:

systemctl status systemd-modules-load.service

The output should look like this:

systemd-modules-load.service - Load Kernel Modules
  Loaded: loaded (/usr/lib/systemd/system/systemd-modules-load.service; static)
  Active: active (exited) since Wed, 03 Apr 2013 22:50:57 +0000; 46s ago
        Docs: man:systemd-modules-load.service(8)
              man:modules-load.d(5)
 Process: 260 ExecStart=/usr/lib/systemd/systemd-modules-load (code=exited, status=0/SUCCESS)

The last line contains the PID (process id) and the exit code. status=0/SUCCESS means the module was successfully inserted, confirmed by:

journalctl -b _PID=260

output being:

Apr 03 22:50:57 mxhst systemd-modules-load[260]: Inserted module 'rt2800usb'

In case of failure, systemctl output looks like this:

systemd-modules-load.service - Load Kernel Modules
  Loaded: loaded (/usr/lib/systemd/system/systemd-modules-load.service; static)
  Active: failed (Result: exit-code) since Wed, 03 Apr 2013 22:50:59 +0000; 43s ago
        Docs: man:systemd-modules-load.service(8)
              man:modules-load.d(5)
 Process: 260 ExecStart=/usr/lib/systemd/systemd-modules-load (code=exited, status=1/FAILURE)

with journalctl -b reporting:

Apr 03 22:50:59 mxhst systemd-modules-load[260]: Failed to find module 'fakert2800usb'

When the exit code is 0/SUCCESS it means your module has been successfully inserted; running

lsmod | grep rt2800

should confirm that:

rt2800usb              26854  0 
rt2x00usb              19757  1 rt2800usb
rt2800lib              64762  1 rt2800usb
rt2x00lib              66520  3 rt2x00usb,rt2800lib,rt2800usb
mac80211              578735  3 rt2x00lib,rt2x00usb,rt2800lib

If lsmod output doesn't confirm (despite the service exit code being 0/SUCCESS) it means something removed the module after being loaded by modules-load.service. One possible cause is another *.conf file that blacklisted the module. Look for a line like:

blacklist rt2800usb

in /etc/modprobe.d/*.conf, /usr/lib/modprobe.d/*.conf or /run/modprobe.d/*.conf and comment it out / delete it.


To load a module on boot, you create a file in /etc/modules-load.d/; this file can have any name, but must end in .conf. In the case of your wifi driver, you could for example create the file /etc/modules-load.d/rt2800.conf.

In the file, add a single line with the name of the module you want to load like so:

rt2800usb

The Arch Wiki page on Kernel modules has more information.