The kernel's modules_install
Makefile target may be used to install the built module somewhere appropriate for the kernel so that it can be loaded by modprobe
.
This can be invoked from a rule in the external module's Makefile. See the install:
target in the Makefile below for an example:
# Note: this `ifneq` and its matching `else` and `endif` can be omitted
# for recent kernels.
ifneq ($(KERNELRELEASE),)
# KBuild part of Makefile
obj-m += mymodule.o
else
# Normal part of Makefile
#
# Kernel build directory specified by KDIR variable
# Default to running kernel's build directory if KDIR not set externally
KDIR ?= "/lib/modules/$(shell uname -r)/build"
all:
$(MAKE) -C "$(KDIR)" M="$(CURDIR)" modules
install: all
$(MAKE) -C "$(KDIR)" M="$(CURDIR)" modules_install
clean:
$(MAKE) -C "$(KDIR)" M="$(CURDIR)" clean
.PHONY: all install clean
endif
Install the module using this Makefile with the command: sudo make install
. By default, it will be installed in the /lib/modules/$(KERNELRELEASE)/extra
directory, but the subdirectory name extra
can be changed by setting the INSTALL_MOD_DIR
variable. (Also, a prefix can be prepended before the /lib/modules
part by setting the INSTALL_MOD_PATH
variable, which is useful for installing into a staging directory.)
To load the module automatically on system start-up, the systemd-modules-load.service service can be used. This requires the module name to be listed in a file matching one of the following patterns:
/etc/modules-load.d/*.conf
/run/modules-load.d/*.conf
/usr/lib/modules-load.d/*.conf
The /etc/modules-load.d/*.conf
pattern is most appropriate for local system admininistration. For example:
/etc/modules-load.d/local.conf
:
mymodule
(Older systems without systemd may have used a different method to specify the modules to be loaded on system start-up, such as listing them in a file called /etc/modules
. That is still supported on Debian and Ubuntu systems.)
Modules for device drivers with device probe
functions can use the MODULE_DEVICE_TABLE(type, name)
macro to register a table of matching device IDs. Then udev
will load the module automatically when a matching device is detected and so do not need to be listed in a modules-load.d
configuration file.