Home > loader > how to load kernel module in linux

how to load kernel module in linux

Release time:2023-06-29 10:08:06 Page View: author:Yuxuan
When it comes to Linux, kernel modules refer to small pieces of code that can be loaded and unloaded from the operating system. Kernel modules are a great way to extend the functionality of the Linux kernel and allow you to add support for new hardware, filesystems, or network protocols without having to recompile the entire kernel. In this article, we will discuss how to load a kernel module in Linux.

Checking if the Kernel Module is Installed

Before loading a kernel module, you should check if the module is already installed on your system. You can do this by running the following command:

lsmod | grep module-name

This will check if the module \"module-name\" is installed. If the module is installed, you will see its name, size, and a list of other modules that depend on it. If the module is not installed, you will see an empty output.

Loading the Kernel Module

To load a kernel module, you should use the \"modprobe\" command. For example, if you want to load the \"nvidia\" module, you can run the following command:

sudo modprobe nvidia

This will load the \"nvidia\" module and all its dependencies. You should use \"sudo\" to run this command as the root user as loading a kernel module requires administrative privileges.

Unloading the Kernel Module

If you no longer need a kernel module, you can unload it from your system using the \"rmmod\" command. For example, to unload the \"nvidia\" module, you can run the following command:

sudo rmmod nvidia

This will unload the \"nvidia\" module and all its dependencies. Again, you should use \"sudo\" to run this command as the root user.

Automatically Loading the Kernel Module on Boot

If you want to automatically load a kernel module when your system boots up, you should add the module name to the \"modules\" file. This file is located at \"/etc/modules\" and you can edit it using any text editor. For example, if you want to automatically load the \"nvidia\" module when your system boots up, you can add the following line to the file:

nvidia

Then save the file and reboot your system. The \"nvidia\" module will be automatically loaded during the boot process.

Conclusion

In this article, we have discussed how to load a kernel module in Linux. Kernel modules are a great way to extend the functionality of the Linux kernel and add support for new hardware, filesystems, or network protocols without having to recompile the entire kernel. By loading and unloading kernel modules on demand, you can save memory and system resources and improve the performance of your system.
THE END

Not satisfied with the results?