繁体   English   中英

针对正在运行的内核构建外部模块

[英]Build external modules against a running kernel

我正在尝试为Ubuntu服务器构建最新的Linux加密驱动程序。 Ubuntu服务器具有正在运行的内核,安装了Extras和标头。 但是,加密模块的源代码来自Torvald的GitHub(而非Ubuntu)。

我也在内核文档Building External Modules中工作 我用以下命令克隆了最新的内核:

git clone --depth=1 https://github.com/torvalds/linux.git 

然后:

cd linux

下一个:

$ make -C /usr/src/linux-headers-4.2.0-34 M=$PWD crypto
make: Entering directory '/usr/src/linux-headers-4.2.0-34'

  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.

make: Nothing to be done for 'crypto'.
make: Leaving directory '/usr/src/linux-headers-4.2.0-34'

和:

$ find /usr/src -name 'autoconf.h'
/usr/src/linux-headers-4.2.0-34-generic/include/generated/autoconf.h
$ find /usr/src -name 'auto.conf'
/usr/src/linux-headers-4.2.0-34-generic/include/config/auto.conf

和这个:

$ find /usr/src -type d -name 'build'
/usr/src/linux-headers-4.2.0-34/tools/build
/usr/src/linux-headers-4.2.0-34-generic/include/config/build

尝试使用build目录将导致以下结果:

$ make -C /usr/src/linux-headers-4.2.0-34/tools/build M=$PWD crypto
make: Entering directory '/usr/src/linux-headers-4.2.0-34/tools/build'
make: *** No rule to make target 'crypto'.  Stop.
make: Leaving directory '/usr/src/linux-headers-4.2.0-34/tools/build'

我显然缺少明显的东西。 这并不奇怪,因为我几乎不了解kbuild。 我在/usr/src有一个退出的配置和源,在$PWD/crypto有新文件。 我不清楚为什么我要为现有配置生成新配置。

如何针对其他人提供的正在运行的内核更新内核加密模块?

实际上,这里有两件事要注意:

正在运行的内核版本是否与我们使用的源代码相同?
由于先前编译的内核可能不具有在最新版本中可能使用的所有依赖项,而使用最新内核源代码编译外部模块可能取决于代码的任何部分,而这些代码仅在最新版本中存在。 因此,建议使用我们正在使用外部模块的最新版本内核。

二,用于内核编译的.config文件
您可以将其从文件系统的/boot/config(current-version)*复制到内核源顶层目录中的.config 当前版本,我们可以从uname -r获得它

因此,过程将是如果运行版本(使用命令uname -r检查)与下载的源不相等,则您需要编译并使用新内核,或者下载与运行内核相同的内核版本。 对于内核编译,请使用引导目录中存在的配置文件,如上所述进行复制。

然后,您可以采用一种正常的方式来编译外部模块,并将其加载到正在运行的内核中,而不会出现任何问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM