Howto: Linux Add Remove a Linux Kernel Modules / Drivers

by Vivek Gite on January 24, 2007 · 11 comments

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

Linux systems comes with 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.

=> 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 aka modules

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

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

boot   initrd  misc           modules.ccwmap  modules.ieee1394map  modules.isapnpmap  modules.symbols  source
build  kernel  modules.alias  modules.dep     modules.inputmap     modules.pcimap     modules.usbmap

Task: Add a Module (driver) Called foo

Type the command as root user:
# modprobe foo

Task: List All Loaded Modules

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

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

Featured Articles:

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

{ 11 comments… read them below or add one }

1 Lakshman June 14, 2008

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.

Reply

2 Todd Weaver June 16, 2009
3 Teryaki July 14, 2009

Thanks alot for this, very helpful for teh newbz.

Reply

4 hamza September 12, 2009

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

Reply

5 vikas March 7, 2010

thank tou

Reply

6 ss June 17, 2010

thanks

Reply

7 santhosh kumar k June 28, 2011

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

Reply

8 prakash June 28, 2011

Thanks a lot for the info…:) :)

Reply

9 peter August 23, 2011

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 .
Regards…

Reply

10 Kingston January 2, 2012

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!

Reply

11 Vivek Gite January 2, 2012

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!

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="">




Previous post:

Next post: