Linux: How to load a kernel module automatically at boot time

by Vivek Gite on September 14, 2006 · 6 comments

Q. How do I Load a Linux kernel module automatically at boot time so that my hardware is automatically recognized during system boot sequence?

A. Linux kernel follows modular kernel design. Loadable Kernel Modules (LKM) are object files that contain code to extend the running kernel, or so-called base kernel. LKM's are typically used to add support for new hardware, filesystems etc.

Loading a kernel module is an essential task. File /etc/modules.conf (or /etc/modules - see a note below for more info) is configuration file for loading kernel modules.

The configuration file consists of a set of lines. All empty lines, and all text on a line after a '#', will be ignored.

This file is used - if new hardware is added after installation and the hardware requires a kernel module, the system must be configured to load the proper kernel module for the new hardware.

For example, if a system included an IDE CD-ROM, the module configuration file contains the following 3 lines:
# vi /etc/modules.conf
Append following lines:
ide-cd
ide-core
cdrom

Save and close the file. Reboot the system.

NOTE: If you are using Debian Linux or Ubuntu Linux use file /etc/modules file instead of /etc/modules.conf (which works on Red Hat/Fedora core/Cent OS etc)

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 6 comments… read them below or add one }

1 Balakumar September 8, 2009

Try this method to load module at boot time

#echo module_name >> /etc/rc.modules
#chmod +x /etc/rc.modules

Reply

2 Yacob Hassidim October 9, 2011

Hello,
I use Ubuntu 11.4 (Linux 2.6.38)
I tried both the files modules.conf and rc.modules.
Unfortunately the modules is not loaded.
Do you have any idea?
Thanks,
Yacob.

Reply

3 Dave October 19, 2011

/etc/modules is the file you’re looking for Yacob

Reply

4 Yacob Hassidim October 23, 2011

Hello Dave,

Thank you.
I tried this file also but the modules are not loaded.
Do you have another idea?
Thanks,
Yacob.

Reply

5 SIFE November 3, 2011

Try this:
echo “modprobe module_name” >> /etc/modprobe.d/modeprobe.conf

Reply

6 Steve November 18, 2011

My understanding is that modprobe.conf and modules.conf are only configuration files. They do not invoke modprobe. All they do is provide modprobe with information about what it should do when it is invoked.

Scripts that are run immediately after the boot (in the start up sequence) are called rc scripts. Many systems have a script called rc.local. This script is arranged in such a way (normally with symlinks) that it is executed as the last script in the start up sequence. This is a good place to put additional commands that are required and which have not been invoked already. The normal location of this script is /etc/rc.d/rc.local.

Therefore if the modprobe command is added to that script it will be executed at the end, and before a login shell prompt is provided. Determine the location of modprobe. If, for example, it is /sbin/modprobe, then the end of the rc.local file should look something like this:
# Put your required modprobe command here:
/sbin/modprobe name-of-module

Note that if the module in question requires options, then a place to put these is in /etc/modprobe.conf, because when modprobe runs it will read that configuration file and pick up any required options from there.

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 9 + 15 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: