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

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

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, NICs and more.

Config file

Loading a kernel module is an essential task. You need to edit the file named /etc/modules or put a new config file in /etc/modules-load.d/ directory. Use any one of the methods 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. The file /etc/modules (or other files in /etc/modules-load.d/) 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
Append following lines:

Save and close the file. Reboot the system for testing purpose:\
# reboot
Another option is to load drivers without rebooting the system. Use the modprobe command:
# modprobe {driver-name}
# modprobe ide-cd
# modprobe ide-cd cdrom

Please note that if you are using Debian Linux or Ubuntu Linux use the file /etc/modules file instead of /etc/modules.conf (which works on on an older version of Red Hat/Fedora/CentOS Linux. These days it is better to use the directory /etc/modules-load.d/ on all Linux distros.

A note about modern Linux kernels

These days udev used for for automatic module handling. There is no need to put modules in any configuration file as udev takes care of it. However, sometimes you still need add an extra module during the boot process, or blacklist another one for your Linux laptop or server to function correctly. For example, kernel modules can be loaded during boot a boot in files under /etc/modules-load.d/. For example:
# cat /etc/modules-load.d/kvm.conf

Task: See what kernel modules are currently loaded

Type the lsmod command:
$ lsmod
$ lsmod | more
Sample outputs:

Fig.01: Obtaining information about currently loaded modules/drivers

Fig.01: Obtaining information about currently loaded modules/drivers

To get information about a module, run modinfo command

$ modinfo {module_name}
For example get info about a module named igb:
$ modinfo igb
Sample outputs:

Fig.02: Find information about a module

Fig.02: Find information about a module

To unload/remove a module

The syntax is as follows for the rmmod command $ sudo rmmod {module_name}
$ sudo modprobe -r {module_name}

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 21 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
21 comments… add one
  • Balakumar Sep 8, 2009 @ 9:55

    Try this method to load module at boot time

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

  • Yacob Hassidim Oct 9, 2011 @ 8:57

    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 Oct 19, 2011 @ 23:46

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

      • Yacob Hassidim Oct 23, 2011 @ 20:12

        Hello Dave,

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

        • SIFE Nov 3, 2011 @ 22:04

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

  • Steve Nov 18, 2011 @ 11:36

    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 Apr 7, 2015 @ 23:51

      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 Apr 12, 2015 @ 9:56

        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 Aug 8, 2012 @ 5:03

    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 Aug 9, 2012 @ 13:03

    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 Aug 9, 2012 @ 13:45

    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 Aug 9, 2012 @ 14:11

    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 Aug 9, 2012 @ 14:25

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

    • Shantanu Apr 4, 2013 @ 10:19

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

  • Bhargav Shah Aug 9, 2012 @ 17:59

    Thanks redjupiter. It worked with ubuntu 11.04.

  • redjupiter Aug 10, 2012 @ 9:04

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

  • Atul Jul 19, 2013 @ 6:40

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

  • Steve Jul 23, 2013 @ 10:16


    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 Jul 18, 2014 @ 0:31

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

  • chirkoot Mar 27, 2015 @ 15:20

    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:

  • KG Aug 6, 2017 @ 18:33

    You forgot to mention about unsupported modules file.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum