≡ Menu

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

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:

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)

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 20 comments… add one }

  • Balakumar September 8, 2009, 9:55 am

    Try this method to load module at boot time

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

  • Yacob Hassidim October 9, 2011, 8:57 am

    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?

    • Dave October 19, 2011, 11:46 pm

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

      • Yacob Hassidim October 23, 2011, 8:12 pm

        Hello Dave,

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

        • SIFE November 3, 2011, 10:04 pm

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

  • Steve November 18, 2011, 11:36 am

    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.

    • Rohan Shah April 7, 2015, 11:51 pm

      Thanks Steve,

      Your steps helped me. It works.
      I wanted to bring 8021q after every reboot.
      I added it in /etc/rc.local file.
      For me /etc/rc.d/rc.local doesn’t exist, I have Ubuntu 14.04 platform.

      • Steve April 12, 2015, 9:56 am

        Hi Rohan,

        I am glad that helped you.

        I use “linux from scratch”. That is a system in which the operating system is built step by step, not simply installed from some disk or web site. It takes a long time but can give some improvements in understanding and control.

        Different distributions tend to store files (including configuration files) in different places. It appears that with Ubuntu there is a configuration file called /etc/modules which lists the names of modules to be loaded at boot time. If so then that might be a better place to put the 8021q module name. rc.local tends to be used for “local” after thoughts – anything unusual that needs to be done for that one host. There is a web page that describes Ubuntu’s /etc/modules here:

        The use of the 8021q module for vlan’s in Ubuntu is described here:
        The section “Making it permanent”, which comes at the end of the article, seems to be relevant in your case. If that’s right then it might be tidier to do it that way than to use rc.local (even though it does work).

  • Bhargav Shah August 8, 2012, 5:03 am

    Hi all,
    i am new buddy to Linux module programming.I am facing same problem in loading a module at boot time in Ubuntu 11.04. Can any one tell me the perfect steps to load the module at the boot time.


  • redjupiter August 9, 2012, 1:03 pm

    same problem here. I did change /etc/modules, but where do I put the module object itself so moprob can find it?

    To put the question in another way, what are the default lcoation that modprobe look for modules?


  • Bhargav Shah August 9, 2012, 1:45 pm

    i i tried to put the .KO file with the all drivers .KO file.But that doesn’t worked.
    The other way to do this is configuring the Kconfig file and recompile the kernel.
    But i am not getting proper documentation.

  • redjupiter August 9, 2012, 2:11 pm

    I figured that out.

    add a line to /etc/modules for your module (without .ko)
    copy the module file to /lib/modules/

    sudo depmod -a
    reboot and it worked for me on Ubuntu 12.04

    • redjupiter58 August 9, 2012, 2:25 pm

      error. copy the module file to /lib/modules/

    • Shantanu April 4, 2013, 10:19 am

      This solution worked for me too on 12.04 . Thanks redjupiter.

  • Bhargav Shah August 9, 2012, 5:59 pm

    Thanks redjupiter. It worked with ubuntu 11.04.

  • redjupiter August 10, 2012, 9:04 am

    Glad it worked. one correction for others:
    copy the module file to /lib/modules/

  • Atul July 19, 2013, 6:40 am

    there is no /etc/modules…rather /etc/modprobe.conf is there…
    please suggest

  • Steve July 23, 2013, 10:16 am


    quite often there is no need for a modprobe configuration file. As I said before (see previous remark from November, 2011), modprobe is not invoked by that configuration file. Its just that if you need to provide it with additional information, then that can be done from the configuration file. The name used for the configuration file has changed a bit between different versions, and sometimes it is given as a file in a directory, modprobe.d. On my workstation (built from scratch) there is no modprobe configuration file. Its not needed.

    The critical thing usually is making the kernel aware of modules. To do this you have to put the module in the right place, and run depmod to update the module dependencies.

    Perhaps if you explained what you were trying to do, then it would be possible to provide a more specific explanation.

  • mdk July 18, 2014, 12:31 am

    I would like to add that some systems have the modules file in /etc/sysconfig/modules

  • chirkoot March 27, 2015, 3:20 pm

    To load a module by filename (i.e. one that is not installed in /lib/modules/$(uname -r)/):
    # insmod filename [args]

    To unload a module:
    # modprobe -r module_name

    Or, alternatively:
    # rmmod module_name

    Check this link for more info on how to work with modules:

Leave a Comment