Howto: Linux Add or Remove a Linux Kernel Modules / Drivers

How do I add or remove hardware device driver (module) from running Linux kernel?

Linux systems comes with the modprobe command, to add and remove modules from the Linux Kernel. Please note that:

=> Under MS-Windows you use term device driver for modules.

=> Under Linux you use term modules for device drivers.

Tutorial details
Difficulty level Advanced
Root privileges Yes
Requirements modprobe/lsmod/modinfo utilities
Est. reading time N/A
=> The Linux kernel has a modular design.

=> At boot time, only a minimal resident kernel is loaded into memory.

=> If you add new hardware you need to add driver i.e. modules.

=> The modprobe command intelligently adds or removes a module from the Linux kernel

=> Usually, all Linux kernel modules (drivers) are stored in the module directory located that /lib/modules/$(uname -r) directory. To see current modules, type:
$ ls /lib/modules/$(uname -r)

build                modules.ccwmap       modules.order
initrd               modules.dep          modules.pcimap
kernel               modules.dep.bin      modules.seriomap
misc                 modules.devname      modules.softdep
modules.alias        modules.ieee1394map  modules.symbols
modules.alias.bin    modules.inputmap     modules.symbols.bin
modules.builtin      modules.isapnpmap    modules.usbmap
modules.builtin.bin  modules.ofmap        updates

Use the following command to list all drivers for various devices:
$ ls /lib/modules/$(uname -r)/kernel/drivers/
Sample outputs:

Fig.01: Device drivers on my Linux based system

Task: Add a Module (driver) Called foo

Type the following command as root user:
# modprobe foo
In this example, I am loading a module called i8k, enter:
# modprobe -v i8k
Sample outputs:

insmod /lib/modules/3.5.0-30-generic/kernel/drivers/char/i8k.ko 

Find out info about loaded module

You need to use the modinfo command to see information about a Linux Kernel module. The syntax is:
# modinfo -v {module-name-here}
# modinfo i8k

Sample outputs:

Fig.02: Displaying information about a Linux Kernel module called i8k

Task: List all loaded modules

Use the lsmod command to show the status of modules in the Linux Kernel:
# lsmod
Sample outputs:

Module                  Size  Used by
smbfs                  75465  0
md5                     5953  1
ipv6                  284193  10
ipt_TOS                 4033  2
iptable_mangle          4545  1
ip_conntrack_ftp       74801  0
ip_conntrack_irc       74033  0
ipt_REJECT              8897  43
ipt_LOG                 8513  2
ipt_limit               4033  6
iptable_filter          4673  1
ipt_multiport           3521  4
ipt_state               3393  16
ip_conntrack           54297  3 ip_conntrack_ftp,ip_conntrack_irc,ipt_state
ip_tables              21825  8 ipt_TOS,iptable_mangle,ipt_REJECT,ipt_LOG,ipt_limit,iptable_filter,ipt_multiport,ipt_state
i2c_dev                13889  0
i2c_core               28865  1 i2c_dev
dm_mirror              32721  0
dm_mod                 68609  1 dm_mirror
button                  9313  0
battery                11465  0
ac                      6985  0
ohci_hcd               24529  0
ehci_hcd               33989  0
tg3                   109381  0
floppy                 66065  0
ext3                  137937  2
jbd                    69105  1 ext3
sata_svw               10053  3
libata                 78345  1 sata_svw
sd_mod                 19393  4
scsi_mod              141457  2 libata,sd_mod

Task: Remove a module called foo

Pass the -r option to modprobe command to remove a module, type:
# modprobe -r foo
You can also use the rmmod command, which is simple program to remove a module from the Linux Kernel:
# rmmod foo

Recommended readings
  • man pages – modinfo, lsmod, insmod, and modprobe

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

🐧 23 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
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 glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep 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
23 comments… add one
  • Lakshman Jun 14, 2008 @ 9:33

    when the system is rebooted the module inside the kernel will not be present.But i want the modules to be seen permenently.what should i do.

  • Todd Weaver Jun 16, 2009 @ 14:18
  • Teryaki Jul 14, 2009 @ 19:23

    Thanks alot for this, very helpful for teh newbz.

  • hamza Sep 12, 2009 @ 12:30

    Thank’s first for the helpfull command , where can i get the new modules other then my OS,

  • vikas Mar 7, 2010 @ 16:09

    thank tou

  • ss Jun 17, 2010 @ 17:50


  • santhosh kumar k Jun 28, 2011 @ 7:21

    how to build linux kernel module with new device driver module during build

  • prakash Jun 28, 2011 @ 9:29

    Thanks a lot for the info…:) :)

  • peter Aug 23, 2011 @ 6:08

    Hi there…
    I am trying to remove TCP IP from a linux kernel, and want to recompile the LINUX kernel. But being a novice with the administrations of the linux (UBUNTU 10.4), I know a little about it. Agter recompilation can I again design mu own TCPIP using the C language code?
    Guys please help me out…waiting for the reply .

  • Kingston Jan 2, 2012 @ 20:22

    Thanks for this very short but very clear information. That helps me to understand the concept (of add or remove module on Linux) very much.

    One question remain: how do we check to know what modules are available to add on a existing system?

    Thank you in advance!

    • 🐧 nixCraft Jan 2, 2012 @ 20:56

      One question remain: how do we check to know what modules are available to add on a existing system?

      cd to /lib/modules/$(uname -r) directory and you can see the list of available modules (run as root):

      cd /lib/modules/$(uname -r)
      ls -l

      The following will list all drives

      find /lib/modules/$(uname -r) -type f -iname "*.ko"

      To find out more info about a module called foo:

      modinfo foo

      Hope this helps!

  • Bahador Feb 8, 2012 @ 6:59

    thanks for your comments, I am trying to write a printer driver for linux, what should I do?

    Please help me on this task.

  • Atul Mar 13, 2012 @ 19:04

    Does anyone knows step by step guide for how to install ip_conntrack support into kernel Linux linux #1 SMP Wed Nov 23 13:57:33 UTC 2011 i686 i686 i386 GNU/Linux

  • Chinmaya May 2, 2012 @ 10:08

    I am unable to remove the following modules after issuing the commands.
    $ rmmod usbhid and
    $rmmod hid..

    After issuing the commands the modules are not shown in “lsmod” but as soon as a device is added they again get loaded.

    Any suggestions…

  • Martin Jan 7, 2013 @ 2:25

    thanks, very clear article.

  • Bishisht Bhatta May 23, 2013 @ 4:52

    Hello there. I have an old computer Celeron, 128MB RAM and 28MB of VGA. What I want to do is keep the drivers that are needed for my system. Like if I use the Realtek Chipset for Network Card why should the Atheros driver be present on the system? Is there any way to accomplish this task?

  • z666zz666 Jul 16, 2013 @ 21:08

    I have a serious problem, my Linux does not have these comands:
    …etc… and also has not a lot of typical commands

    And there is no /dev/loop*

    And mount -o loop blablabla bleble say incorrect option, does not undertand loop.

    Of course, all problem seem that Kernel has no loop device support.

    How can i fix it?

    Please have in mind Kernel is on ROM (a chip not writteable), it is not a flasheable chip, i can not modify it on any way, … read only memory chip!!

    I wish if it could be possible to add loop device support at run time as a module…

    But it does not have modprobe command… neither a lot of clasic Linux commands… so i got to fail.

    Need some help, i am not an expert.

    Step 1: try to create /dev/loop0 (it does not exists) with mknod but mknod command not found

    Try to add such coomands with apt-get, wget, etc… all says such commands not exists

    I am getting mad…

    Please note it is an ARM processor based, and Kernel is on a ReadOnly chip not flashable.

    Thanks in advance for any help… i am getting really mad…

  • King Jul 19, 2013 @ 2:11

    If I were you, rather than finding Linux Kernel modulos to have “uname”, “modprobe”, “man” recovered (maybe you have played around some kernel rebuild and screwed up some basic binaries?), I will re-install the entire Linux OS from scratch. You can download CentOS (Red Hat) or SUSE, Fedora or whatever Linux to have all these basic utilities included.

  • Jeff waters Jul 22, 2015 @ 14:05

    trying to add slcan module to kernel 2.6.32-504.30.3.el6.i686 but having problems with the following response … question is how to get it added

    FATAL: Module slcan not found.

  • Nikunj Dec 23, 2015 @ 20:44

    Thank you so much…

  • favour Jan 9, 2016 @ 19:51

    i want to know how many mouldes in linus and brief explanation of them.i will glad if my question is been answered.

  • Sergio Dec 6, 2017 @ 1:18

    thanks bro

  • raviteja Sep 24, 2020 @ 13:40

    hi all,
    iam unable to remove nvme module in primary drive(ssd) by using
    following comment:
    rmmod nvme

    anyone can help me

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