Linux kernel is a wonderful piece of software which will act a master to all softwares installed in an OS. In this post we will see how to load servents(aka modules) in to kernel. Though Linux architecture taken inspiration from Unix, there are some differences between their kernel architecure. One major difference is Linux kernel is a modular kernel where as Unix kernel is a monolithic kernel.

What is a modular kernel?

A modular kernel is a type of kernel where you can load a module(a piece of software to make some hardware/software to work properly) or remove a module when that module is no longer required by your Operating System. In windows world these are called as "Drivers". This is the beauty of Linux kernel where you can load only required modules and remove unwanted modules which will have less burden on the system.

In this post we will see "How to load a module at the time of boot." We have two options to do this. One is prescribed one and other one is a work around which you should not prefer.

Load kernel modules using modules file

Ubuntu/Debian machines:

In Debian based machines like Ubuntu the modules file is located at /etc/modules. For example if you want pptp

#vi /etc/modules

 

Content:

mac80211
cfg80211

 

Save the file and exit.

Redhat/Centos/Fedora machines:

In Redhat based machines we have to create a shell script file say for example xyz.modules in /etc/sysconfig/modules folder and change permissions to executable. We can create as many .modules files you want or keep all modules in single .modules file.

Example:

#vi /etc/sysconfig/modules/xyz.modules

 

File content:

#!/bin/sh

 

 

/sbin/insmod xyzmodule

Save the file and change permissions to executable

chmod +x /etc/sysconfig/modules/xyz.modules

 

Load kernel modules through /etc/rc.local file

This is common in most of the Linux flavors. Edit /etc/rc.local file to enter modprob/insmod commands to execute them at the time of booting.

Note 1: This note is for people who do not know about /etc/rc.local file. This is a file which will be executed after init completes its booting and before we get login prompt. This is just file with sequence of commands. If you want to execute any command at the time of boot, you just have to keep that command in this file. 

#vi /etc/rc.local

 

Content:

modprob mac80211
insmod /lib/modules/3.19.0-15-generic/kernel/drivers/net/wireless/iwlwifi/iwlwifi.ko

 

Save the file and exit. 

Now your system will load these modules when ever it boots up.

In our next posts we will see how to use other kernel related commands like lsmod, insmod, modinfo, rmmod, modprob, depmod, dkms, kmod.