gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:38:31 25 4
gpt4 key购买 nike

我正在尝试为 Ubuntu 服务器构建最新的 Linux 加密驱动程序。 Ubuntu 服务器有一个正在运行的内核、附加组件和头文件。但是,加密模块的源代码来自 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 检查)不等于下载的源代码,那么您需要编译并使用新内核或下载与运行内核相同版本的内核。对于内核编译,使用引导目录中的配置文件,按上述方式复制它。

然后您可以继续以正常方式编译外部模块并使用运行中的内核加载它而不会出现任何问题。

关于linux - 针对正在运行的内核构建外部模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36240143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com