Linux 中的 Modprobe 命令——初学者指南

在本文中,我们将了解 Linux 中的 modprobe 命令。 Linux 内核本质上是模块化的,这意味着任何最终用户都可以通过删除或添加某个模块来删除内核的功能或添加内核的功能。 这是 modprobe 命令派上用场的地方,它可以轻松添加或删除内核模块。

在 Ubuntu 20.04LTS 上安装英特尔显卡驱动程序的步骤

什么是内核模块?

内核模块是一个目标文件,其中包含可以根据需要加载和卸载到内核的代码。 加载后,它将扩展内核功能,而无需重新启动内核本身。

这样,开发人员不必为所有服务和功能编写单一代码。 将 Linux 内核视为一个巨大的乐高结构,您可以在其上轻松添加另一个乐高积木(模块)。

设备驱动程序是内核模块的一个很好的例子。

您设备上的所有内核模块都存储在 /lib/modules . 您可以使用以下命令列出它们。

find /lib/modules/$(uname -r)/kernel/ | grep ".ko" | more  

要查看当前加载了哪些模块,您可以使用 lsmod

modprobe 命令是做什么用的?

模组探针 命令用于加载(添加)和卸载(删除)内核模块。 它在 /lib/module/$(uname -r)

如何使用 modprobe 加载模块?

您可以使用以下命令加载内核模块。

sudo modprobe <kernel module name>hideep.ko 

运行此命令后,您可以使用以下命令验证模块是否已加载

lsmod | grep <kernel module name> 

如果此命令返回任何内容,则表示模块已加载。

加载内核模块

在这里,我加载了 hideep 模块,它是触摸屏的设备驱动程序。

如何卸载模块?

内核模块可以使用 -r modprobe 中的标志。

sudo modprobe -r <kernel module name> 

再次验证内核模块是否已卸载,可以运行

lsmod | grep <kernel module name> 

它不应该返回任何东西。

卸载内核模块

modprobe 中的有用标志

就像我们使用 -r 删除模块的标志,modprobe 有许多其他标志用于其他目的。 下面列出了一些重要的。

-a : This flag allows you to add multiple modules at once 
一次加载多个模块
--show-depends : This lists all the dependencies of a module 
显示内核模块的依赖关系
-v : If you want to know about what the program is doing in every single step, you can use this command. 
Modprobe 详细
--first-time : Usually if you try to add a module which is already loaded or remove a module which is already unloaded, modprobe will do nothing. However when we use this flag, modprobe will fail. This is good for debugging purposes and to verify wheather a module has already been loaded/unloaded.  
第一次 Modprobe

结论

有时,当您搜索所有互联网以尝试修复一个驱动程序问题或声音问题时,许多教程会要求您在 Linux 中加载/卸载驱动程序模块。 好了,现在您知道如何使用 modprobe 轻松完成了。 请参阅此处以了解有关 modprobe 和内核模块的更多信息。 谢谢你,继续探索。