Howto: Linux add remove a Linux kernel modules / drivers

by Vivek Gite · 5 comments

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

A. Linux comes with modprobe command to add and remove modules from the Linux Kernel.

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

=> Under Linux you use term modules

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

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

=> Usually modules stored in the module directory /lib/modules/$(uname -r)
$ 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 called foo

Type the command as root user:
# modprobe foo

Task: List all loaded modules

Use 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 -r option to modprobe command to remove a module
# modprobe -r foo
You can also use rmmod command, which is simple program to remove a module from the Linux Kernel
# rmmod foo

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 5 comments… read them below or add one }

1 Lakshman 06.14.08 at 9:33 am

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.

2 Todd Weaver 06.16.09 at 2:18 pm
3 Teryaki 07.14.09 at 7:23 pm

Thanks alot for this, very helpful for teh newbz.

4 hamza 09.12.09 at 12:30 pm

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

5 vikas 03.07.10 at 4:09 pm

thank tou

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All