Kernel Modules


Linux systems store device drivers as so called kernel modules which usually are stored in /lib/modules/. The modules stored here are either loaded or unloaded into the kernel to provide functionalities to system devices. Kernel modules are loaded by default when the system boots up but, you can later load them manually.

lsmod command can be used to view the currently loaded kernel modules:

Kernel modules

Kernel modules

As seen from the output of the lsmod command, a kernel module can be used by another module and/or process or not used at all (0 values stands for not used).

If you don’t know a module’s purpose you can search the internet for it or use the modinfo command to view more details about it:

Modinfo

Modinfo

If the Linux kernel has the auto module loading feature enabled then you don’t need to worry about loading kernel modules but, if you want to load a module manually, read the following section.

Modules can be loaded into the kernel using one of the following commands:

insmod – loads a single module into the kernel. This command will not load any module dependencies so those should be loaded before performing this operation.

modprobe – loads a kernel module and all its dependencies.

With insmod you need to specify the full path of the module, with modprobe command this is not needed.

Just add the kernel module name and modprobe will load it and all its dependencies:

Load kernel modules

Load kernel modules

Modprobe command will actually execute multiple instances of the insmod command to load all dependencies. You can use the -v (verbose) parameter to check out its operation:

[root@localhost /]# modprobe -v bluetooth
insmod /lib/modules/2.6.32-573.3.1.el6.x86_64/kernel/net/rfkill/rfkill.ko
insmod /lib/modules/2.6.32-573.3.1.el6.x86_64/kernel/net/bluetooth/bluetooth.ko
[root@localhost /]#

Configuration files for modprobe are stored under /etc/modprobe.d/ or /etc/modprobe.conf. Other useful parameters for this command are:

-r – removes a kernel module and all its dependencies

-n – executes a dry-run to check out if all requirements are met but does not actually load the kernel module

-l – list all loadable modules

–show-depends – can be used to display all module dependencies

[root@localhost /]# modprobe –show-depends bluetooth
insmod /lib/modules/2.6.32-573.3.1.el6.x86_64/kernel/net/rfkill/rfkill.ko
insmod /lib/modules/2.6.32-573.3.1.el6.x86_64/kernel/net/bluetooth/bluetooth.ko

For other parameters available with these two commands check out their man pages.

To remove a loaded kernel module, use the rmmod command as seen in the following example:

[root@localhost /]# modprobe bluetooth
[root@localhost /]# lsmod | grep bluetooth
bluetooth 97895 0
rfkill 19255 1 bluetooth
[root@localhost /]# rmmod bluetooth
[root@localhost /]# lsmod | grep bluetooth
[root@localhost /]#

The command can also be used with one of the following commands:

-f – force module removal

-w – wait until the module becomes unused

-v – verbose

Note that rmmod will unload one specific kernel module. If you want to unload a kernel module and all its dependencies, use the modprobe command as described earlier.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s