5.4. Automatic LKM Loading and Unloading
5.4.1. Automatic Loading
You can cause an LKM to be loaded automatically when the kernel first needs it. You do this with either the kernel module loader, which is part of the Linux kernel, or the older version of it, a kerneld daemon.
As an example, let's say you run a program that executes an open system call for a file in an MS-DOS filesystem. But you don't have a filesystem driver for the MS-DOS filesystem either bound into your base kernel or loaded as an LKM. So the kernel does not know how to access the file you're opening on the disk.
The kernel recognizes that it has no filesystem driver for MS-DOS, but that one of the two automatic module loading facilities are available and uses it to cause the LKM to be loaded. The kernel then proceeds with the open.
Automatic kernel module loading is really not worth the complexity in most modern systems. It may make sense in a very small memory system, because you can keep parts of the kernel in memory only when you need them. But the amount of memory these modules uses is so cheap today that you will normally be a lot better off just loading all the modules you might need via startup scripts and leaving them loaded.
Red Hat Linux uses automatic module loading via the kernel module loader.
Both the kernel module loader and kerneld use modprobe , ergo insmod , to insert LKMs. See Section 5.3 .
5.4.1.1. Kernel Module Loader
There is some documentation of the kernel module loader in the file Documentation/kmod.txt in the Linux 2.4 source tree. This section is more complete and accurate than that file. You can also look at its source code in kernel/kmod.c .
The kernel module loader is an optional part of the Linux kernel. You get it if you select the CONFIG_KMOD feature when you configure the kernel at build time.
When a kernel that has the kernel module loader needs an LKM, it creates a user process (owned by the superuser, though) that executes modprobe to load the LKM, then exits. By default, it finds modprobe as /sbin/modprobe , but you can set up any program you like as modprobe by writing its file name to /proc/sys/kernel/modprobe . For example:
# echo "sbin/mymodprobe" >/proc/sys/kernel/modprobe
The kernel module loader passes the following arguments to the modprobe : Argument Zero is the full file name of modprobe . The regular arguments are -s , -k , and the name of the LKM that the kernel wants. -s is the user-hostile form of --syslog ; -k is the cryptic way to say --autoclean . I.e. messages from modprobe will go to syslog and the loaded LKM will have the "autoclean" flag set.
The most important part of the modprobe invocation is, of course, the module name. Note that the "module name" argument to modprobe is not necessarily a real module name. It is often a symbolic name representing the role that module plays and you use an alias statement in modules.conf to tell what LKM gets loaded. For example, if your Ethernet adapter requires the 3c59x LKM, you would have probably need the line
alias eth0 3c59x
in /etc/modules.conf . Here is what the kernel module loader uses for a module name in some of the more popular cases (there are about 20 cases in which the kernel calls on the kernel module loader to load a module):
When you try access a device and no device driver has registered to serve that device's major number, the kernel requests the module by the name block-major- N or char-major- N where N is the major number in decimal without leading zeroes.
When you try to access a network interface (maybe by running ifconfig against it) and no network device driver has registered to serve an interface by that name, the kernel requests the module named the same as the interface name (e.g. eth0 ). This applies to drivers for non-physical interfaces such
* License

