如何重新编译单个内核模块?
通常内核源代码存储在/usr/src/linux-2.6.x/
中。 为了避免在修改模块的源代码时重新编译整个内核,如何重新编译该模块?
Usually kernel source are stored in /usr/src/linux-2.6.x/
.
To avoid to recompile the entire kernel if I modify a module's source, how can I recompile just that module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
切换到源代码树的根目录并运行以下命令:
并安装已编译的模块:
注意:正如 lunakid 提到的,后一个命令可能不会构建模块首先,所以要小心。
Switch to the root directory of your source tree and run the following command:
And to install the compiled module:
Note: As lunakid mentions, the latter command might not build the module first, so be careful.
从内核版本 3.xx 和 4.xx 开始,过程变得更加复杂(但有希望,所以继续阅读):
make distclean
如果您不仅克隆了新源,还用于在并仅将与需要构建的模块相关的源文件(从内核源或其他地方)复制到此新文件夹中
/boot/config-`uname -r`
文件(例如:/boot/config-4.8.0-46-generic)进入内核源文件夹文件.config并运行make oldconfig
。如果模块属于内核源代码,请通过调用make menuconfig
来验证它是否已启用,方法是搜索该模块并在必要时应用字母“M”make kernelversion
验证它是否与uname -r
完全匹配)make script
makeprepare
和makemodules_prepare
必须在实际模块构建之前执行/usr/src/linux-headers-`uname -r`/Module.symvers
(例如: /usr/src/linux-headers-3.13.0-117-generic/Module.symvers)进入为模块编译准备的新创建的模块源文件文件夹(一个额外的)。obj-y +=.o
或者如果源代码很复杂,请使用 < a href="https://www.kernel.org/doc/Documentation/kbuild/modules.txt" rel="noreferrer">heremake 构建模块的正确时机 - C <内核源码路径> M=the_module_directory
(示例:make -C . M=extra/
)modprobe --dump-modversion.ko
验证 CRC模块导出 API 与 Module.symvers 中的相应值之间的匹配。如果失败,请使用命令modinfo.ko
来方案如下:
则解决 所有更改,使用
git tag -a强制发布标签移至您的修改之上-f 命令。然后从步骤 8 重建模块
since kernel versions 3.x.x and 4.x.x the procedure gets more complicated (but there is a hope, so keep reading):
make distclean
if you haven't just cloned a new source but used to build other modules beforeand copy only source files (from the kernel source or somewhere else) related to the module needed to be build into this new folder
/boot/config-`uname -r`
file (example: /boot/config-4.8.0-46-generic) into kernel source folder file .config and runmake oldconfig
. if the module belongs to the kernel source, verify if it has been enabled by callingmake menuconfig
, by searching for the module and applying letter 'M' if necessarymake kernelversion
if it matches exactly theuname -r
one)make scripts
make prepare
andmake modules_prepare
has to be executed prior to the actual module build/usr/src/linux-headers-`uname -r`/Module.symvers
(example: /usr/src/linux-headers-3.13.0-117-generic/Module.symvers) into the newly created module source files folder prepared for the module compilation (the one extra in example).obj-y += <module_source_file_name>.o
or if the source code is complicated, use the guidance from heremake -C <kernel source path> M=the_module_directory
(example:make -C . M=extra/
)modprobe --dump-modversion <module_name>.ko
to verify CRC match between module exporting API and corresponding values in Module.symvers. in case of failure use commandmodinfo <module_name>.ko
insteadthe solution would be following:
commit all your changes, force release tag to shift above your modifications with the
git tag -a <tag version> -f
command. then rebuild your modules from step 8您可以将模块名称或模块目录的路径传递给 make 作为参数。
You can pass the path to the module name or module directory to make as parameter.
如果您仅编辑 drivers/net/ethernet/intel/e1000/e1000_main.c 文件中的代码
构建模块。
安装模块。
In case you have edited just code in drivers/net/ethernet/intel/e1000/e1000_main.c file
Build the module.
Install the module.
https://askubuntu.com/questions/515407/how-recipe-仅构建一个内核模块
https://askubuntu.com/questions/515407/how-recipe-to-build-only-one-kernel-module
我无法发表评论。因此,要完成 Niklas B. 针对
kernel-5.15
系列的回答,请切换到源代码树的根目录并运行以下命令。
modules_install
重新安装所有驱动程序。我不知道是否可以/建议复制您的驱动程序。使用
rtl8xxxu
驱动程序进行测试。I can't comment. So to complete the answer from Niklas B. for
kernel-5.15
seriesSwitch to the root directory of your source tree and run the following commands.
modules_install
re-install all drivers. I don't know if it's possible / advisable to just copy your driver.Tested with
rtl8xxxu
driver.