Online Book Reader

Home Category

UNIX System Administration Handbook - Evi Nemeth [157]

By Root 2886 0
in Solaris. This organization should make it much easier for third parties to write packages that integrate easily and seamlessly into the kernel, at least in theory.

You can add a driver with the add_drv command. This command loads the driver into the kernel and makes the appropriate device links (all links are rebuilt each time the kernel boots). Once you add_drv a driver, it remains a part of the system until you actively remove it. You can unload drivers by hand with rem_drv.

Whenever you add a driver using add_drv, it is a good idea to also run drvconfig. This command reconfigures the /devices directory and adds any files that are appropriate for the newly loaded driver.

Loadable modules that are not accessed through device files can be loaded and unloaded with modload and modunload.

Loadable kernel modules in Linux


Linux is both more and less sophisticated than Solaris in its handling of loadable kernel modules, at least from the system administrator’s point of view. Under Linux, almost anything can be built as a loadable kernel module. The exceptions are the root filesystem type and the device on which the root filesystem resides.

Loadable kernel modules are conventionally stored under /lib/modules/version, where version is the version of your Linux kernel as returned by uname -r. You can inspect the currently loaded modules with the lsmod command:

# lsmod

Module Size Used by

ppp 21452 0

slhc 4236 0 [ppp]

ds 6344 1

i82365 26648 1

pcmcia_core 37024 0 [ds i82365]

This machine has the PCMCIA controller modules, the PPP driver, and the PPP header compression modules loaded.

Linux LKMs can be manually loaded into the kernel with insmod. For example, we could manually insert our example snarf module with the command

# insmod /path/to/snarf.o

Parameters can also be passed to loadable kernel modules; for example,

# insmod /path/to/snarf.o io=0xXXX irq=X

Once a loadable kernel module has been manually inserted into the kernel, it will only be removed if you explicitly request its removal. We could use rmmod snarf to remove our snarf module.

You can use rmmod at any time, but it works only if the number of current references to the module (listed in the Used by column of lsmod’s output) is 0.

Linux LKMs can also be loaded semiautomatically by modprobe, which is like a souped-up insmod that understands dependencies, options, and installation and removal procedures. modprobe uses /etc/modules.conf to figure out how to handle each module.

You can dynamically generate an /etc/modules.conf file that corresponds to all your currently installed modules by running modprobe -c. This command generates a long file that looks like this:

#This file was generated by: modprobe -c (2.1.121)

path[pcmcia]=/lib/modules/preferred

path[pcmcia]=/lib/modules/default

path[pcmcia]=/lib/modules/2.3.39

path[misc]=/lib/modules/2.3.39

...

# Aliases

alias block-major-1 rd

alias block-major-2 floppy

...

alias char-major-4 serial

alias char-major-5 serial

alias char-major-6 lp

...

alias dos msdos

alias plip0 plip

alias ppp0 ppp

options ne io=x0340 irq=9

The path statements tell where a particular module can be found. You can modify or add entries of this type if you want to keep your modules in a nonstandard location.

The alias statement provides a mapping between block major device numbers, character major device numbers, filesystems, network devices, and network protocols and their corresponding module names. This facility supports dynamic loading as implemented by kerneld (discussed below).

The options lines are not dynamically generated. They specify options that should be passed to a module when it is loaded. For example, we could use the following line to tell the snarf module its proper I/O address and interrupt vector:

options snarf io=0xXXX irq=X

modprobe also understands the statements pre-install, post-install, pre-remove, post-remove, install, and remove. These statements allow commands to be executed when a specific module is inserted into or removed from the running kernel.

Return Main Page Previous Page Next Page

®Online Book Reader