How to Load and Unload Kernel Modules in Linux

When we install Linux Like operating system at that time Linux kernel install most of device driver’s modules and after the installation it also allows us to install new device drivers as modules using the commands modprobe and insmod.

Normally kernel modules are loaded automatically but sometimes you need to install the additional modules as being manual . For instance you want to install device drivers of storage device and etc. For this there are some commands some of them are listed below.

lsmod command

lsmod stand for ‘list module‘. As the name suggests this command will list currently loaded kernel modules on your system.

[root@linuxtechi ~]# lsmod

lsmod-command-output

If you want to find a specific module. This can be network driver module (e1000) then you can do via grep command.

[root@linuxtechi ~]# lsmod | grep e1000

lsmod-grep-linux

modinfo command

modinfo stand for ‘module information‘. This command will show the information about a kernel module. For instance you want to view the information regarding network driver module:

[root@linuxtechi ~]# modinfo e1000

modinfo-command-output-linux

Output of modinfo command clearly show version of this module, description which is showing the manufacture factory, license is GPL and other important information.

modprobe command

modprobe command is used to add and remove module from the kernel. Linux maintains kernel module directory under ‘/lib/modules/’uname -r’/kernel/drivers/‘ and configuration files(except for additional configuration file in /etc/modprobe.d/). If we want to look at kernel drivers then run the beneath command.

[root@linuxtechi ~]# ls /lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/

linux-kernel-modules-list

If we need to add i8k kernel module which this module is using for “accessing SMM BIOS on Dell laptops

[root@linuxtechi ~]# modprobe i8k

if output of this command is being any error, then you can use ‘–quite‘ option, with this flag or option  modprobe will not print error messages.

Note : Most of the time we use modprobe command to install kernel module though insmod is also used for loading the kernel module in linux.

Remove a Kernel Module

-r option in modprobe command is used to remove a kernel module. Let’s assume we want to remove the floppy module.

[root@linuxtechi ~]# modprobe -r floppy
[root@linuxtechi ~]#

Here we remove floppy module from kernel after that you type

[root@linuxtechi ~]# lsmod | grep floppy

and you should see nothing. If you want to add this module again you can type

[root@linuxtechi ~]# modprobe floppy

At some point of time we may get issues while loading the modules or modules not loaded properly. To overcome these errors we can add or load modules forcefully using ‘–force’ option ( -f) in the modprobe command.

[root@linuxtechi ~]# modprobe -f floppy

If we still face problems or errors while loading the modules, then this time we must do debugging.By enabling debugging we can find exact error or issue before or after installing the modules. In other words debugging is equivalent of dry-run of loading modules.

-n’ option in the modprobe command can enable this type of debugging. This option will force modprobe command to perform all module loading steps except the final one.

[root@linuxtechi ~]# modprobe -vn 'module_name'

We can also see dependency of the module with using ‘–show-depends‘ in the modprobe command, example is shown below

[root@linuxtechi ~]# modprobe --show-depends e1000
insmod /lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/net/ethernet/intel/e1000/e1000.ko
[root@linuxtechi ~]#

That’s all for this article. I hope you got an idea how to list, install and remove kernel module in Linux.

Share Now!

1 thought on “How to Load and Unload Kernel Modules in Linux”

Leave a Reply to Fatikhan Cancel reply