通常内核源代码存储在/usr/src/linux-2.6.x/
。
如果我修改了一个模块的源代码,为避免重新编译整个内核,该如何只重新编译这个模块呢?
通常内核源代码存储在/usr/src/linux-2.6.x/
。
如果我修改了一个模块的源代码,为避免重新编译整个内核,该如何只重新编译这个模块呢?
进入你的源代码根目录并运行以下命令:
$ make modules SUBDIRS=drivers/the_module_directory
并安装编译好的模块:
$ make modules_install SUBDIRS=drivers/the_module_directory
注意: 正如lunakid所提到的那样,后面的命令可能不会先构建模块,所以请小心。
自从内核版本 3.x.x 和 4.x.x 以来,该过程变得更加复杂(但仍有希望,继续阅读):
make distclean
/boot/config-`uname -r`
文件(例如:/boot/config-4.8.0-46-generic)复制到内核源码文件夹中的 .config 文件中,并运行 make oldconfig
。如果该模块属于内核源码,请通过调用 make menuconfig
并搜索模块来验证是否已启用该模块,必要时应用字母 'M'make kernelversion
验证它是否与 uname -r
完全匹配)make scripts
生成脚本make prepare
和 make modules_prepare
/usr/src/linux-headers-`uname -r`/Module.symvers
(例如:/usr/src/linux-headers-3.13.0-117-generic/Module.symvers) 到为模块编译准备的新创建的模块源码文件夹(例如:示例中的 extra)中。obj-y += <module_source_file_name>.o
,如果源代码很复杂,可以使用这里的指导make -C <kernel source path> M=the_module_directory
进行模块构建(例如:make -C . M=extra/
)modprobe --dump-modversion <module_name>.ko
验证导出API的模块和Module.symvers中对应值的CRC匹配。如果失败,请改用命令modinfo <module_name>.ko
解决方案如下:
提交所有更改,使用git tag -a <tag version> -f
命令强制发布标签以将其移动到您的修改之上。然后从步骤8重新构建您的模块。
make path/to/the/module/itself.ko
make path/to/the/module/directory/
如果您只编辑了drivers/net/ethernet/intel/e1000/e1000_main.c文件中的代码
构建该模块。
make scripts prepare modules_prepare
make -C . M=drivers/net/ethernet/intel/e1000
安装模块。
cp drivers/net/ethernet/intel/e1000/e1000.ko /lib/modules/5.1.15/kernel/drivers/net/ethernet/intel/e1000/e1000.ko
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules_install
https://askubuntu.com/questions/515407/how-recipe-to-build-only-one-kernel-module
SUBDIRS
相对于当前工作目录应该是非常清晰的 :P - Niklas B.make modules_install SUBDIRS=...
即可。那几乎肯定是下一步,可能不会立即简单(即使看起来是这样,在我花费几分钟搜索无果后... :))。谢谢,干杯! - Sz.