博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单独编译某个内核模块
阅读量:7236 次
发布时间:2019-06-29

本文共 2463 字,大约阅读时间需要 8 分钟。

hot3.png

对开发内核驱动和文件系统的人来说,经常需要编译某个内核模块。 当然从编译角度,有built-in kernel module和external kernel module之分。 怎么编译一个外部内核模块,google一下“hello world kernel module Makefile”吧。 这里我说下编译内核自带模块的坑... 我用的是SUSE Linux

  1. 安装源代码包和开发包

    #zypper in kernel-source kernel-devel

    开发包里面放的是头文件和Makefile文件,用RPM命令来查看下:

    # rpm -qa|grep kernel-develkernel-devel-4.1.27-27.1.noarch# rpm -ql kernel-devel-4.1.27-24.1.noarch|more/usr/share/doc/packages/kernel-source-4.1.27-24/usr/share/doc/packages/kernel-source-4.1.27-24/README.SUSE/usr/share/doc/packages/kernel-source-4.1.27-24/config-options.changes.txt/usr/src/linux/usr/src/linux-4.1.27-24/usr/src/linux-4.1.27-24/Documentation/usr/src/linux-4.1.27-24/Documentation/DocBook/usr/src/linux-4.1.27-24/Documentation/DocBook/Makefile....

     

  2. 重要参考文件

#ls -l /usr/src/linux/README.SUSE

lrwxrwxrwx 1 root root 61 Dec 31 10:41 /usr/src/linux/README.SUSE -> ../../share/doc/packages/kernel-source-3.12.49-11/README.SUSE

这个文档介绍编译内核以及模块所需的软件包,概念,方法和步骤。 基本上也适用于其他Linux发型版。

贴出相关的一段:

The second method involves the following steps:  (1)  Install the kernel-devel package.  (2)  Install the kernel-$FLAVOR-devel package. This is necessary for       symbol version information (CONFIG_MODVERSIONS).  (3)  Compile the module(s) by changing into the module source directory       and typing ``make -C /usr/src/linux-obj/$ARCH/$FLAVOR M=$(pwd)''.       Substitute $ARCH and $FLAVOR with the architecture and flavor       for which to build the module(s).       If the installed kernel sources match the running kernel, you       can build modules for the running kernel by using the path       /lib/modules/$(uname -r)/build as the -C option in the above       command. (build is a symlink to /usr/src/linux-obj/$ARCH/$FLAVOR).  (4)  Install the module(s) with       ``make -C /usr/src/linux-obj/$ARCH/$FLAVOR M=$(pwd) modules_install''.

   3.坑

但是按照上面的步骤总是编译不出来.ko内核模块, 原因是当前的发行版默认没有打开ocfs2模块编译选项:

eric1211:/usr/src/linux/fs/ocfs2 # make -C /lib/modules/3.12.49-11-default/build M=`pwd` modulesmake: Entering directory '/usr/src/linux-3.12.49-11-obj/x86_64/default'make[1]: Entering directory `/usr/src/linux-3.12.49-11-obj/x86_64/default'  Building modules, stage 2.  MODPOST 0 modulesmake: Leaving directory '/usr/src/linux-3.12.49-11-obj/x86_64/default'

原因是配置文件默认没有选择OCFS2,所以要手动make menuconfig,把ocfs2选上, 再试就可以了。具体步骤:

  1. cd /usr/src/linux

  2. make menuconfig 选择ocfs2

  3. cd /usr/src/linux/fs/ocfs2

  4. make -C /lib/modules/`uname -r`/build M=`pwd` modules

转载于:https://my.oschina.net/u/2475751/blog/595244

你可能感兴趣的文章
新时代ITer们的思考及购书有奖活动
查看>>
微软邮件系统Exchange 2013系列(十)客户端和移动设备管理
查看>>
系统集成项目管理工程师软考辅导——3年真题透解与全真模拟
查看>>
以安装桌面体验功能为例来探索windows2012服务器管理器的新变化
查看>>
ubuntu安装与测试hadoop1.1.0版本
查看>>
运维开发实战考题:计算教育网站投票排名
查看>>
Lync 小技巧-54-Elastix IVR 转换Wav方法
查看>>
JAVAEE知识的系统性有多重要?再谈非线性学习方法
查看>>
Yii2 HOW-TO(3):调试工具yii2-debug和Xdebug(失败)
查看>>
PC上安装MAC X Lion
查看>>
大共享永久免费云服务器评测体验
查看>>
虚拟化基础架构Windows 2008篇之4-将Windows计算机加入到域
查看>>
about script engine on jdk 6 is mozilla rhino
查看>>
android之Apache Http初使用——向服务器发送请求
查看>>
nohup命令 使用方法详解
查看>>
Intent 和 Intent Filter
查看>>
Linux下MySQL的主从热备(自动同步)配置
查看>>
Windows 8 Consumer Preview版升级到 Release Preview 版后Metro应用(html5+JavaScript版)修改小结...
查看>>
编程珠玑:变位词程序的实现
查看>>
POJ 2987 Firing
查看>>