Kernel modules

Kernel modules are programs that run inside the kernel. They also can be understood as device drivers. Kernel modules can included in the kernel file /usr/src/linux/arch/i386/boot/bzImage or be separate files found in /lib/modules. As separate files, they have to be loaded on request, manually or at startup using /etc/conf.d/modules.

Not having the kernel modules in the kernel file /usr/src/linux/arch/i386/boot/bzImagegives some advantages:

  1. Whats loaded can be seen via lsmod

  2. Kernel module parameters and options can be passed easily

  3. Kernel modules can be unloaded rmmod, without requiring to reboot the system

Sometimes you do not know what kernel modules you have. Therefore watch what make && make modules_install

prints out:

INSTALL drivers/media/dvb/dvb-usb/dvb-usb-dib0700.ko

means you have the kernel module dvb-usb-dib0700

It is also possible to pass module parameters to modules included in the kernel. The equivalent of modprobe usbcore blinkenlights=1 can be passed as kernel parameter in the form usbcore.blinkenlights=1

Kernel modules communicate to the application (user space) via device files /dev/*.

modules directory

For kernels 2.6 and newer the directory /etc/modules.d and the file /etc/modprobe.conf have been introduced with a simplified syntax. However since backward compatibility to kernel 2.4 stuff is an important issue both methods are supported in parallel. The support for the file /etc/modprobe.conf will stop in the future.

Therefore the future is to add or modify files under /etc/modules.d . The files be considered need to end with conf. As example a tv card needs some parameters passed when its kernel modules is loaded, to get the right support for the tuner.

So create a file /etc/modprobe.d/tv.conf with the line inside to be used together with modprobe.

      options saa7134 card=2 tuner=69  

update modules

Since those config files are a key thing for the installation, Gentoo does not recommend to edit them manually and uses a program update-modules -v to do it (run it with the -v verbose option, so you see what it refuses to do). The command update-modules -v creates (or updates) /etc/modules.conf from the directory /etc/modules.d. Therefore do not edit /etc/modules.conf except you want delete something there that stays in after a update-modules -v. You might have to set the old-linux useflag and re-emerge module-init-tools.

(There was also modules-update that is now replace with update-modules).

Those conf files contain:

  1. aliases to tell insmod/modprobe which modules to use modprobe -c shows them all

  2. options to be passed when a module is loaded

To get help type or update-modules -h.

update-modules updates:



/lib/modules/<kernel version>/modules.dep

To force an update update-modules --force

Working with the modules

Kernel modules in can be inserted and removed by a user using the console.

insmod inserts module to the kernel (version of kernel and module do have to match, -f force does ignore version) uname -r shows the kernel version.

modprobe does the same and more and is more convenient to be used. It has it configuration directory /etc/modprobe.d where default parameters for the modules can be set.

rmmod => removes the module

lsmod => lists modules present (Formats just cat /proc/modules )


Module Size Used by

radeon 104064 1

drm 65620 2 radeon

The number under used shows how many applications (references) using it currently

modprobe -s -k char-major-63 loads the kernel module mapped to the character device with the major number 63.

/var/log/messages shows eventually problems during loading of the module.

modinfo give information about the kernel module

modinfo /lib/modules/$(unmame -r)/kernel/sound/core/oss/snd-pcm-oss.ko

modinfo /lib/modules/$(uname -r)/video/fglrx.ko

Modules depend from each other /lib/modules contains /lib/modules/<kernel version>/modules.dep showing how. If a module depends on others then the whole dependency tree of modules will be loaded. depmod produces this file (so you can delete /lib/modules/<kernel version>/modules.dep and re-crate a new one).

cat /proc/ioports shows the area in the IO memory space occupied by the kernel modules.

cat /proc/devices shows the major numbers assigned to the kernel modules.

Opening or loading a kernel module creates a link between /dev file and the kernel module itself. This is done via the major number. The major number is a constant value in the kernel module. Obviously, there might be more than one kernel module per major number. /dev file as well have a constant major number as seen by ls /dev -l. However this is not enough.


Filenames use - as separator character (snd-pcm-oss.ko), whereas lsmod shows them with _ separation character (snd_pcm_oss).

In OpenRC the file /etc/conf.d/modules holds the modules including their parameters to be loaded during the init startup process.

When the system is running and ned devices are plugged in then also this event can trigger to load the missing modules.

Some useful commands:

find /lib/modules/`uname -r`/ -name "pwc*.ko*"

depmod -a

modinfo /lib/modules/$(uname -r)/kernel/drivers/usb/media/pwc/pwc.ko

An evolutionary way of a device driver is that it will be created in a packet completely separated from the kernel sources. Those device drivers will also be installed under /lib/modules and are often found in /lib/modules/<kernel version>/misc. If there is common interest, then the device drivers might get adopted by the kernel sources. When this happens, it can happen that multiple versions of the same device driver are under /lib/modules but inside different directories. ls -lR /lib/modules/<kernel version> shows that.


Open Source means source code that needs to be compiled to get binary. However Linux can handle also binaries. The gentoo kernel source comes with executable binaries as in /usr/src/linux-4.12.12-gentoo/firmware/radeon. Those binaries are used for the radeon graphic cards.

Other binaries are usually added to /lib/firmware. This is done by installing a package containing firmware as under gentoo emerge linux firmware.

Further, when creating a kernel, firmware can be included

Figure 3.1. firmware blobs

Firmware blobs

dmesg | grep 'firmware' will show if the firmware is loaded and used. There are some option in the kernel to have more debug messages. However if the kernel starts it looks into various places for the firmware and can produce error messages even if it later finds the firmware and loads it.

[ 10.421498] dvb-usb: found a 'Hauppauge Nova-T Stick' in cold state, will try to load a firmware

[ 10.433650] usb 2-4: loading /lib/firmware/updates/4.12.12-gentoo/dvb-usb-dib0700-1.20.fw failed with error -2

[ 10.433658] usb 2-4: loading /lib/firmware/updates/dvb-usb-dib0700-1.20.fw failed with error -2

[ 10.441880] usb 2-4: loading /lib/firmware/4.12.12-gentoo/dvb-usb-dib0700-1.20.fw failed with error -2

[ 10.477139] dvb-usb: downloading firmware from file 'dvb-usb-dib0700-1.20.fw'

[ 10.682581] dib0700: firmware started successfully.

Linurs Servernest startpage