Loading Drivers Manually

Linux provides several commands for managing modules:

insmod This command loads a single module. You can specify the module by its module name or by its filename. For instance, insmod via-rhine loads the via-rhine.o module (it may be compressed with gzip, and hence be called via-rhine.o.gz). Kernel modules are stored in subdirectories of/lib/modules/version, where version is the Linux kernel version. The problem with the insmod command is that it often fails because of unmet dependencies—the module may rely upon features that aren't present in the kernel or any loaded modules. To overcome such problems, you must load the missing modules. The modprobe command makes this task easier.

modprobe This command loads a module and all the modules upon which it depends. It works much like insmod, but it's less likely to fail because of unmet dependencies.

depmod In order to load all depended-upon modules, modprobe relies upon a catalog of module dependencies. This catalog is created with the depmod command. Specifically, typing depmod -a creates the catalog in /lib/modules/vers/on/modules.dep, where version is the kernel version number. This command normally appears in a startup script, such as /etc/rc.sysinit or/etc/init.d/boot.localfs. Thus, you shouldn't need to type this command unless you update your modules and don't want to reboot.

rmmod This command unloads kernel modules; it's the opposite of insmod. If you add the -r or-stacks option, the command deletes a set of modules—essentially, the command works as the opposite of modprobe rather than of insmod.

All of these commands support several options that influence their behavior. One of the most important of these options is the -k or -autoclean option to insmod and modprobe. This option sets the auto-clean flag on the installed module or modules. This flag causes the kerneld daemon, if it's running, to remove the module automatically after a period of time (generally about a minute) if it's unused. This practice can help keep modules from consuming memory if they're used for brief periods of time, but if you load modules manually, it can be an inconvenience to have to load them again.

Another important insmod and modprobe option is -f or-force. Ordinarily, Linux will load only modules that match the version of the running kernel. This option will attempt to force a module load even if the version number doesn't match. This option is often necessary when using drivers provided with commercial software such as VMware. It doesn't always work, though, particularly when the version numbers differ greatly, such as a driver for a 2.2.x kernel loaded on a 2.4.x kernel.

As a general rule, you'll load drivers manually only when you're testing them or debugging a system—for instance, if a driver fails to load, you might try loading it manually to identify the problem. You'll then configure the system to load the driver automatically, as described in the next section. In some cases, though, you might write a script to load a driver prior to performing some task, and then unload the driver afterward. You might do this if you have problems with the automatic kernel loading and unloading.

0 0

Post a comment