Categories
SysOps

How to load kernel modules at boot

Load kernel modules at boot.

Create a dedicated drop-in module definition file inside /etc/modules-load.d/ directory.

$ cat <<EOF | sudo tee /etc/modules-load.d/usbip.conf
usbip_core
usbip_host
vhci_hcd
EOF
usbip_core
usbip_host
vhci_hcd

Inspect current systemd-modules-load service status.

$ sudo systemctl status systemd-modules-load.service
● systemd-modules-load.service - Load Kernel Modules
     Loaded: loaded (/lib/systemd/system/systemd-modules-load.service; static)
     Active: active (exited) since Fri 2022-01-21 00:25:14 CET; 42min ago
       Docs: man:systemd-modules-load.service(8)
             man:modules-load.d(5)
    Process: 334 ExecStart=/lib/systemd/systemd-modules-load (code=exited, status=0/SUCCESS)
   Main PID: 334 (code=exited, status=0/SUCCESS)
        CPU: 9ms

sty 21 00:25:14 milosz-IdeaCentre-5-14IOB6 systemd-modules-load[334]: Inserted module 'lp'
sty 21 00:25:14 milosz-IdeaCentre-5-14IOB6 systemd-modules-load[334]: Inserted module 'ppdev'
sty 21 00:25:14 milosz-IdeaCentre-5-14IOB6 systemd-modules-load[334]: Inserted module 'parport_pc'
sty 21 00:25:14 milosz-IdeaCentre-5-14IOB6 systemd-modules-load[334]: Inserted module 'msr'
sty 21 00:25:14 milosz-IdeaCentre-5-14IOB6 systemd[1]: Finished Load Kernel Modules.
Notice: journal has been rotated since unit was started, output may be incomplete.

Restart systemd-modules-load service to load these modules without reboot.

$ sudo systemctl restart systemd-modules-load.service
$ sudo systemctl status systemd-modules-load.service
● systemd-modules-load.service - Load Kernel Modules
     Loaded: loaded (/lib/systemd/system/systemd-modules-load.service; static)
     Active: active (exited) since Fri 2022-01-21 01:09:44 CET; 2s ago
       Docs: man:systemd-modules-load.service(8)
             man:modules-load.d(5)
    Process: 9683 ExecStart=/lib/systemd/systemd-modules-load (code=exited, status=0/SUCCESS)
   Main PID: 9683 (code=exited, status=0/SUCCESS)
        CPU: 8ms

sty 21 01:09:44 milosz-IdeaCentre-5-14IOB6 systemd[1]: Starting Load Kernel Modules...
sty 21 01:09:44 milosz-IdeaCentre-5-14IOB6 systemd-modules-load[9683]: Inserted module 'usbip_core'
sty 21 01:09:44 milosz-IdeaCentre-5-14IOB6 systemd-modules-load[9683]: Inserted module 'usbip_host'
sty 21 01:09:44 milosz-IdeaCentre-5-14IOB6 systemd-modules-load[9683]: Inserted module 'vhci_hcd'
sty 21 01:09:44 milosz-IdeaCentre-5-14IOB6 systemd[1]: Finished Load Kernel Modules.

Modules defined in the above drop-in module definition file will be loaded on system boot.

Additional notes

Please read modules-load.d, systemd-modules-load.service, and modprobe.d manual pages.