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

查看:110
本文介绍了为不同的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 :

  • 构建内核
  • 构建模块和固件
  • 构建标头 将以上所有内容移动到适当的位置(如果您要在其上开发模块的机器与之不同)
  • building kernel
  • building modules and firmware
  • building headers Moving all of above things in appropriate location (if your machine is not same on which you are going to develop module)

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

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天全站免登陆