insmod command in Linux with examples
Last Updated :
10 Oct, 2024
insmod command in Linux systems is used to insert modules into the kernel. Linux is an Operating System that allows the user to load kernel modules on run time to extend the kernel functionalities. LKMs(Loadable Kernel Modules) are usually used to add support for new hardware (as device drivers) and/or filesystems, or for adding system calls. This command here inserts the kernel object file (.ko) into the kernel with/without arguments, along with a few additional options.
Syntax
insmod [file name] [module-options...]
where,
- filename: The path or name of the kernel object file (.ko) that you want to insert.
- module-options: These are optional arguments that can be passed to the module if it supports parameters. The specific arguments depend on how the module is written.
Key Options for the insmod Command
1. insmod command with help option
The insmod command throws an error if no options, filename or arguments are passed. So, when we use the -h option, it gives the general syntax along with the various options that can be used with the insmod command.
insmod -h

2. insmod command with version option
This is used to view the version of the insmod command.
insmod -V

Examples of Using the insmod Command
1. insmod + file name
This command is used to insert the LKM file (.ko) into the Linux Kernel. The working directory is changed to the one with the LKM file, and then the command is executed. Root privilege is needed to run this instruction.
Note: The LKM file used here is present in the desktop(which is the working directory), and doesn't take any arguments, and prints a message to the system log. This message can be viewed by using the dmesg command.
sudo insmod geeksforgeeks.ko
Example:

2. insmod + file directory + file name
Like the previous command, insmod works when you specify the file directory along with the LKM file's name. This is illustrated below.
Example:
sudo insmod /home/mukkesh/Desktop/geeksforgeeks.ko

3. Passing parameters to the module using insmod
LKM files can have parameters/arguments passed to them through the insmod command. These arguments essentially act as inputs for the LKMs. Depending on how the LKM is written, the arguments are used.
Note:The LKM used here takes the string parameter "user" and prints a message which includes the passed parameter.
Example:
sudo insmod geeks4geeks.ko user="Mukkesh"

Conclusion
The insmod command is a powerful tool for managing Loadable Kernel Modules (LKMs) in Linux. It provides direct control over which modules are inserted into the kernel, making it ideal for developers and advanced users who need to test or customize kernel functionality. While insmod gives fine-grained control, it requires manual handling of module dependencies. For most users, modprobe is a more convenient alternative as it automates the management of module dependencies.
Similar Reads
hostnamectl command in Linux with Examples hostnamectl command provides a proper API used to control Linux system hostname and change its related settings. The command also helps to change the hostname without actually locating and editing the /etc/hostname file on a given system. Syntax: hostnamectl [OPTIONS...] COMMAND .... Where COMMAND c
2 min read
htop command in Linux with examples htop command in Linux system is a command line utility that allows the user to interactively monitor the systemâs vital resources or serverâs processes in real-time. htop is a newer program compared to top command, and it offers many improvements over top command. htop supports mouse operation, uses
4 min read
hwclock command in Linux with examples hwclock also called Real Time Clock (RTC), is a utility for accessing the hardware clock. The hardware clock is independent of the OS(operating system) you use and works even when the machine is shut down. The hardware clock is also called a BIOS clock. A user can also change the date and time of th
3 min read
iconv command in Linux with Examples The iconv command is used to convert some text in one encoding into another encoding. If no input file is provided then it reads from standard input. Similarly, if no output file is given then it writes to standard output. If no from-encoding or to-encoding is provided then it uses current local's c
3 min read
id command in Linux with examples The 'id' command in Linux is a powerful tool used to display user and group names along with their numeric IDs (User ID - UID or Group ID - GID) of the current user or any specified user on the system. This command is particularly useful for system administrators and users who need to verify user id
3 min read
if command in linux with examples if command in Linux is used for conditional execution in shell scripts.The if command is essential for writing scripts that perform different actions based on different conditions.if COMMANDS list is executed, if its status is true, then the then COMMANDS list is executed. Otherwise, each elif COMMA
4 min read
ifconfig Command Knowing your IP address is fundamental for network administration, troubleshooting, and various Linux system tasks. In this article, we will explore several methods to find your IP address in a Linux environment. Whether you are a seasoned Linux user or just getting started, understanding these meth
10 min read
iftop command in Linux with Examples The 'iftop' command is a powerful network analysis tool used by system administrators to monitor real-time bandwidth usage on network interfaces. It provides a quick and detailed overview of networking activities, helping diagnose network issues by identifying which applications or processes are con
4 min read
ifup command in Linux with Examples The 'ifup' command in Linux is essential for managing network interfaces, allowing them to transmit and receive data by bringing them up. This command is typically used in conjunction with network configuration files, specifically '/etc/network/interfaces', which contain the necessary definitions fo
3 min read
import command in Linux with Examples import command in Linux system is used for capturing a screenshot for any of the active pages we have and it gives the output as an image file. You can capture a single window if you want or you can take the entire screen or you can take a screenshot of any rectangular portion of the screen. Here, w
4 min read