insmod Command in Linux



The insmod command in Linux inserts a module into the Linux kernel. Modules are pieces of code, typically device drivers or system extensions, that can be loaded and unloaded to add functionality to the kernel without rebooting.

The insmod provides low-level access to load modules, its lack of dependency management and error-checking limits its utility in everyday scenarios, making modprobe the smarter choice for users.

Table of Contents

Here is a comprehensive guide to the options available with the insmod command −

Syntax of insmod Command

The syntax of the insmod command is as follows −

insmod [filename] [module-parameters]

In the above syntax, the [filename] is used to specify the module file, which is a .ko file. The [module-parameters] option is used to specify parameters related to the module, which the module developer defines.

insmod Command Options

The options of the insmod command are listed below −

Flags Options Description
-V --version To display the command version
-h --help To display help related to the command

Examples of insmod Command in Linux

This section demonstrates the usage of the insmod command in Linux with the examples −

Loading Module into Kernel

To insert or load a module into the kernel use the insmod command in the following way −

sudo insmod ip_module.ko

In the above command, the ip_module.ko is a module file. Note that the insmod command requires sudo privileges.

Handling Module Dependencies

The insmod command does not handle module dependencies. If one module depends on another, the dependent module must be loaded first using insmod. For example, ip_module.ko depends on the network.ko module. First, load the network.ko module.

sudo insmod network.ko

To verify whether this module is loaded or not, use the lsmod command with the module name −

lsmod | grep network

Next load the main module, ip_module.ko using insmod command −

sudo insmod ip_module.ko

Displaying Help

To display help related to the insmod command, use the -h or --help option −

insmod -h
insmod Command in Linux1

Displaying Command Version

To display the insmod command version, use the -V or --version option −

insmod -V
insmod Command in Linux2

Limitations of insmod Command

The limitations of the insmod command are listed below −

  • The insmod command does not handle the dependencies very efficiently. The dependent module needs to be added manually.
  • The insmod command directly inserts the module into the kernel without checking for conflicts with existing modules. It can only be used when it is sure that the module will not conflict with the existing modules.

It is recommended to use the modprobe command instead of insmod due to the drawbacks mentioned above. The modprobe command efficiently handles the dependencies and checks for module conflicts.

Conclusion

The insmod command in Linux is used to insert modules into the kernel. However, it lacks dependency management and error checking, making it less practical compared to modprobe, which handles dependencies and avoids potential conflicts between modules.

While insmod can load modules with specified parameters, it requires manual handling of dependencies and does not verify conflicts with existing modules, making it more suitable for specialized tasks where such issues are controlled. In general, modprobe is the recommended tool due to its enhanced capabilities.

In this tutorial, we explained the insmod command, its syntax, options, and usage in Linux with examples.

Advertisements