How to Load and Unload Kernel Modules in Linux

Modules in Linux A kernel module is a software that can be loaded into or unloaded from the kernel upon call for, without necessarily recompiling it (the kernel) or rebooting the system, and is intended to enhance the functionality of the kernel.

In general software program phrases, modules are greater or much less like plugins to a software inclusive of WordPress. Plugins offer means to extend software program functionality, without them, builders would ought to build a unmarried massive software with all functionalities integrated in a package. If new functionalities are wanted, they would need to be introduced in new versions of a software program.

Likewise with out modules, the kernel would need to be constructed with all functionalities included immediately into the kernel image. This could imply having larger kernels, and gadget directors might need to recompile the kernel each time a new functionality is needed.

An easy instance of a module is a tool driving force – which enables the kernel to get admission to a hardware component/device linked to the machine.

List All Loaded Kernel Modules in Linux

In Linux, all modules quit with them. Ko extension and they are normally loaded mechanically because the hardware is detected at system boot. However, a gadget administrator can control the modules the use of certain commands.

To list all presently loaded modules in Linux, we are able to use the lsmod (listing modules) command which reads the contents of /proc/modules like this.

Module                  Size  Used by
rfcomm                 69632  2
pci_stub               16384  1
vboxpci                24576  0
vboxnetadp             28672  0
vboxnetflt             28672  0
vboxdrv               454656  3 vboxnetadp,vboxnetflt,vboxpci
bnep                   20480  2
rtsx_usb_ms            20480  0
memstick               20480  1 rtsx_usb_ms
btusb                  45056  0
uvcvideo               90112  0
btrtl                  16384  1 btusb
btbcm                  16384  1 btusb
videobuf2_vmalloc      16384  1 uvcvideo
btintel                16384  1 btusb
videobuf2_memops       16384  1 videobuf2_vmalloc
bluetooth             520192  29 bnep,btbcm,btrtl,btusb,rfcomm,btintel
videobuf2_v4l2         28672  1 uvcvideo
videobuf2_core         36864  2 uvcvideo,videobuf2_v4l2
v4l2_common            16384  1 videobuf2_v4l2
videodev              176128  4 uvcvideo,v4l2_common,videobuf2_core,videobuf2_v4l2
intel_rapl             20480  0
x86_pkg_temp_thermal    16384  0
media                  24576  2 uvcvideo,videodev
....

How to Load and Unload (Remove) Kernel Modules in Linux

To load a kernel module, we can use the insmod (insert module) command. Here, we have to specify the full path of the module. The command below will insert the SpeedStep-lib.ko module.

# insmod /lib/modules/4.4.0-21-generic/kernel/drivers/cpufreq/speedstep-lib.ko 

To dump a kernel module, we use the rmmod (cast off module) command. The following instance will unload or do away with the SpeedStep-lib.Ko module.

# rmmod /lib/modules/4.4.0-21-generic/kernel/drivers/cpufreq/speedstep-lib.ko 

How to Manage Kernel Modules Using modprobe Command

Modprobe is an sensible command for listing, putting as well as removing modules from the kernel. It searches inside the module listing /lib/modules/$(uname -r) for all of the modules and related documents, however excludes opportunity configuration files in the /and so on/modprobe.D directory.

Here, you don’t want the absolute path of a module; that is the benefit of the usage of modprobe over the preceding instructions.

To insert a module, clearly provide its name as follows.

# modprobe speedstep-lib

To do away with a module, use the -r flag like this.

# modprobe -r speedstep-lib

Note: Under modprobe, automatic underscore conversion is achieved, so there’s no distinction between _ and – even as entering module names.

For more user data and alternatives, examine thru the modprobe guy page.

# man modprobe

Do not forget about to check out:

1.How to Change Kernel Runtime Parameters in a Persistent and Non-Persistent Way 2. How to Install or Upgrade to Latest Kernel Version in CentOS 7 3.How to Upgrade Kernel to Latest Version in Ubuntu