The modules.devname
file has nothing to do with module auto-loading. It contains information that can be used during system initialization to create files in the /dev
directory. The file is read by the kmod static-nodes
command. By default, kmod static-nodes
produces human-readable output, but during system initialization it is run as kmod static-nodes --format=tmpfiles
to generate output in a more machine-parseable form. Each line contains information that can be used to create a single directory or a single special file (see the tmpfiles.d
man page for details of the format). It does not contain the module name.
On systems using Systemd init, the kmod
command is run from the kmod-static-nodes.service
service. The output file in tmpfiles.d
format is placed in "/run/tmpfiles.d/static-nodes.conf", which will be read later by the systemd-tmpfiles --prefix=/dev --create --boot
command run from the systemd-tmpfiles-setup-dev.service
service to create the actual files in "/dev".
On systems using Sysv init, the kmod
command may be run by the /etc/init.d/udev
init script (on Debian type systems) or from somewhere else. The same init script creates the actual files in "/dev" based on the output from kmod
.
When a character special file for an unregistered character device number is being opened, the kernel will request the module with alias char-major-MAJOR-MINOR
or char-major-MAJOR
where MAJOR
and MINOR
are the major and minor device numbers of the special file. (See base_probe()
in "fs/char_dev.c".) If the kernel is configured with CONFIG_BLOCK_LEGACY_AUTOLOAD=y
, there is similar functionality when opening block special files for unregistered block device numbers, the kernel will request the module with alias block-major-MAJOR-MINOR
or block-major-MAJOR
. (See blk_request_module()
in "block/genhd.c" and blkdev_get_no_open()
in "block/bdev.c".)
The source code for a module uses the MODULE_ALIAS_CHARDEV()
, MODULE_ALIAS_CHARDEV_MAJOR()
, MODULE_ALIAS_BLOCKDEV()
, or MODULE_ALIAS_BLOCKDEV_MAJOR()
macros (which wrap the MODULE_ALIAS()
macro) to put these aliases into the module's .modinfo
section where the depmod
command can find them.