【问题标题】:Build external modules against a running kernel针对正在运行的内核构建外部模块
【发布时间】:2016-07-14 09:38:57
【问题描述】:

我正在尝试为 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 有新文件。我不清楚为什么要为现有配置生成新配置。

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

【问题讨论】:

  • 这里:make -C /usr/src/linux-headers-4.2.0-34 M=$PWD crypto - 而不是 crypto 应该是 modules
  • 谢谢@Tsyvarev。这导致了同样的问题:ERROR: Kernel configuration is invalid. 它增加了一个新问题:cc1: fatal error: can’t open ‘kernel/bounds.s’ for writing: Permission denied compilation terminated.跨度>
  • 通常情况下,Linux内核应该在构建之前进行配置。没有kernel/bounds.s 通常表示这个问题。使用make menuconfigmake oldconfig或任何其他配置目标。
  • 谢谢@Tsyvarev。我猜Ubuntu已经配置了它,我只需要连接现有的配置。 can’t open ‘kernel/bounds.s’ - 看看Kbuild,这是开发人员有时会想出的愚蠢黑客之一。以下是关于聪明的评论:“我们使用内部 kbuild 规则来避免来自 make 的“是最新的”消息”。因此,为了避免 “是最新的” 消息,他们将其换成 “无法打开 'kernel/bounds.s' 进行写入......”跨度>
  • 您没有在问题帖子中写下您拥有wired in the existing configuration。你是怎么做到的?通过复制.config 文件?

标签: linux ubuntu build linux-kernel kernel-module


【解决方案1】:

其实这里有两件事需要关心:

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

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

因此,如果运行版本(使用命令 uname -r 检查)不等于下载的源,则需要编译并使用新内核或下载与运行内核相同版本的内核。对于内核编译,使用引导目录中的配置文件,按上述方式复制它。

然后你可以继续编译外部模块的正常方式,并在运行内核的情况下加载它,没有任何问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-09
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2011-12-10
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多