3 Linux Loadable Module
Traditionally under Unix , device drivers had to be linked
with the kernel, and the system had to be brought down and then restarted
after installing a new driver. Linux introduced the concept of a dynamically
loadable driver called a module. Linux modules can be loaded or removed
dynamically without requiring the system to be shut down. All Linux
drivers can be written so that they are either of the statically linked type, or of the modular type which makes them dynamically loadable.
You can use the command insmod to insert a
module into the kernel and rmmod to remove the module from the
kernel. The example hello sample
shows how to insert and remove a module. Let's
look at the makefile of the sample:
To verify if the module is properly loaded:
[root@peanut /root] less /proc/modules.
On my PC, I have the following:
serial
18964 0
3c59x
21512 1
aic7xxx
124452 3
sd_mod
16768 3
hello
432 0 <-- This
is our hello module
To unload the module from the kernel:
[root@peanut /root] make unload
[root@peanut /root] less /proc/modules to verify
the module is unloaded.
serial
18964 0
3c59x
21512 1
aic7xxx
124452 3
sd_mod
16768 3