为不同的 linux 版本构建内核模块 [英] Building kernel modules for different linux version

查看:33
本文介绍了为不同的 linux 版本构建内核模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编写内核模块的新手,因此很少遇到非技术问题.

I am new to writing kernel modules, so facing few non-technical problems.

因为为特定内核版本(比如 3.0.0-10,10 是补丁号)创建内核模块需要相同版本的内核头文件,所以看起来直接安装内核头文件并从那里开始开发.但是补丁内核版本的内核头文件不可用.因为我有一个来宾内核 vmlinuz-3.0.0-10 在机器上运行并且在下载内核头文件时它说找不到.

Since for creating kernel module for a specific kernel version ( say 3.0.0-10, 10 is patch number) requires same version kernel headers, so it looks straight to install kernel headers and start development over there. But kernel headers for patched kernel version are not available. As I have a guest kernel vmlinuz-3.0.0-10 running in machine and upon downloading kernel headers it says not found.

  • 另一种方法是获取该特定内核的源代码,但同样的问题是修补内核的相同源代码不可用(无需获取 linux-kernel-3.0.0-10 甚至 linux 的源代码-kernel-3.0.0 和第 10 个补丁).在某些情况下,可以获得运行内核的源代码,但并非总是如此.

  • other approach is to get the source for that specific kernel, but again problem is same source for patched kernel is not available ( its not necessary to get sources of linux-kernel-3.0.0-10 or even linux-kernel-3.0.0 and 10th patch). In some situation it is possible to get source of running kernel, but not always possible.

另一种是构建运行内核以外的内核,并将构建的内核放入机器中.但它需要构建该内核的模块,这是一个耗时且占用空间的过程.

another is to build kernel other than the running kernel and place built kernel in the machine. But it requires to build the modules of that kernel that is time-consuming and space-consuming process.

所以问这个问题的目的是了解内核驱动程序开发人员的偏好.还有其他选择吗?

So intention of asking this is to know what are the preferences of kernel driver developers. Are there other alternatives ?

是否可以在一个版本中编译内核模块并在另一个版本中运行(虽然它会出错,但是否有任何解决方法?)

Is it possible to compile kernel module in one version and run in another version ( though it is going to give error, but are there any workaround for this ?)

推荐答案

因此,构建新内核不是一个好的选择,因为它需要:

So, building a new kernel is not a good option as it will require :

  • 构建内核
  • 构建模块和固件
  • 构建标题将上述所有东西移动到适当的位置(如果您的机器与您要开发模块的机器不同)

因此,如果您有用于运行系统的内核头文件,那么您无需下载任何内核版本的源代码,并且在使用模块的同时

So if you have kernel headers for running system then you dont need to download a source code for any kernel version, and while making module use

make -C /lib/modules/kernel-headers-x.y.z/build M=`pwd` modules

您的模块将准备就绪.

如果有更好的答案,我会毫不犹豫地接受.

If there would be better answers, i will not hesitate to accept any of them.

这篇关于为不同的 linux 版本构建内核模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆