insmod command in Linux with examples

insmod command in Linux systems is used to insert modules into the kernel. Linux is an Operating System which 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...]

Options:

  • 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
    

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

Examples:

  • 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:

  • 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
    

  • 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"
    



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.