Basic Linux Kernel commands for module administration

The kernel of a Linux system is the core that everything else in the operating system relies on. The functionality of the kernel can be extended by adding modules to it by use of a specific Linux kernel commands. As such, a user can fine tune their kernel settings by enabling or disabling modules. This level of granular control is one of the many reasons why users love Linux in the first place.

In this guide, we’ll go over some of the most essential kernel module administration commands on Linux. Knowing these commands will help you understand the components that have been loaded into your system’s kernel, and will also allow you to load, reload, or unload modules in the system kernel.

In this tutorial you will learn:

  • How to administer kernel modules on Linux with commands

Managing kernel modules on Linux

Managing kernel modules on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Linux kernel module administration commands



Check out some of the commands below to administer the kernel of your Linux system. Some, but not all, of these commands will require root privileges.

    1. To see a list of all the modules currently available on your system, use the following command to list the contents of the /lib/modules directory. Linux distros are made up of a staggering number of components, so you should expect a lot of output.
      # ls -R /lib/modules/$(uname -r)
      

Viewing all of the modules available on our system

Viewing all of the modules available on our system
    1. Use the following command syntax to display information for a particular module. Of course, replace the name below with the real name of an actual module on your system.
      # modinfo /path/to/module.ko
      

Viewing detailed information about a kernel module

Viewing detailed information about a kernel module by using to following Linux kernel commands:
    1. Install a module into the running kernel by using the following command. Note that this command will not resolve module dependencies automatically.
      # insmod kernel-module-name
      
    2. Install module into the running kernel while also resolving module dependencies.
      # modprobe kernel-module-name
      
    3. Rebuild the module dependency database using /lib/modules/$(uname -r)/modules.dep.
      # depmod -a
      


    1. Some modules are only designed to be loaded into a particular version of a kernel. When trying to load these modules into a kernel of a different version, you’ll get an error. However, you can bypass this red tape and force insmod to load a module even if it’s built for a different kernel version by using the --force option in your command.
      # insmod --force kernel-module-name
      
    2. Display insmod commands to load module and its dependencies. This command is useful when modprobe gives up due to a dependency problem.
      # modprobe -n -v kernel-module-name
      
    3. Display all modules currently loaded into the kernel.
      # lsmod
      

Viewing the modules that are currently loaded into the running kernel

Viewing the modules that are currently loaded into the running kernel
  1. Remove a module from a running kernel with the rmmod command.
    # rmmod kernel-module-name
    

Closing Thoughts



In this guide, we saw various commands that can be used to manage the kernel modules on a Linux system. Knowing these commands will come in handy when troubleshooting hardware components or software that relies on certain modules to function. Now you know how to load or remove modules from the kernel, as well as retrieve information about the modules on your system.



Comments and Discussions
Linux Forum