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
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.
-
- 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)
- To see a list of all the modules currently available on your system, use the following command to list the contents of the
-
- 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
- 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.
-
- 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
- Install module into the running kernel while also resolving module dependencies.
# modprobe kernel-module-name
- Rebuild the module dependency database using
/lib/modules/$(uname -r)/modules.dep
.# depmod -a
- Install a module into the running kernel by using the following command. Note that this command will not resolve module dependencies automatically.
-
- 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
- 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
- Display all modules currently loaded into the kernel.
# lsmod
- 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
- 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.