编译一个单独的内核模块(于Debian / Ubuntu) [英] Compiling an individual kernel module (Debian/Ubuntu)

查看:326
本文介绍了编译一个单独的内核模块(于Debian / Ubuntu)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修改ELF加载器的内核实现一个Ubuntu 14.04发行。在下载使用来源:

I need to modify the ELF loader's kernel implementation of an Ubuntu 14.04 distribution. Having downloaded the sources using:

sudo apt-get source linux-image-$(uname -r)

我跑配置脚本:

make config

在根源树。输入请求的似乎无休止的顺序后,创建脚本生成内核(或一组模块)所需的config文件。我使用的内核版本是Linux-3.13.0,并且具有以下源代码树的布局:

in the root source tree. After a seemingly endless sequence of input requests, the script created the .config file needed to build the kernel(or a set of modules). The kernel version I am using is linux-3.13.0 and has the following source tree layout:

$ ls 
arch   COPYING  crypto         Documentation  dropped.txt  FileSystemMakefile  fs       init  Kbuild   kernel  MAINTAINERS  mm   README          samples  security   sound  ubuntu  virt
block  CREDITS  debian.master  drivers        elf.dat      firmware            include  ipc   Kconfig  lib     Makefile     net  REPORTING-BUGS  scripts  shortcuts  tools  usr

ELF引导器位于 /path/to/source/fs/binfmt_elf.c 。继这个问题,为了编译单个模块就足够了运行

The ELF loader is located in /path/to/source/fs/binfmt_elf.c. Following this question,in order to compile an individual module it is sufficient to run

make /path/to/module/directory. 

在这种情况下,这将是:

In this case that would be:

make ./path/to/source/fs

汇编是非常长;花费大约二十分钟(在虚拟机上),并在将模块位于同一目录中的输出被写入(默认)。我通过运行中的目标文件:

The compilation is quite lengthy; it takes about twenty minutes(on a virtual machine) and the output is written(by default) in the same directory in which the module is located. I've found the object files by running:

find . -name "*.o"

在/路径/要/来源/ FS。按名称过滤ELF引导器可以通过运行位于:

in /path/to/source/fs. Filtering by name the ELF loader can be located by running:

find . -name "*elf*.o"

在其书面(默认)的电流源:

In the current sources it is written(by default) in:

/path/to/source/fs/binfmt_elf.o

本教程中,我注意到内核模块有命名约定的 [模块名] ​​.ko ,以便从用户空间对象文件区分开。

Having gone through this tutorial, I've noticed that kernel modules have the naming convention [module_name].ko in order to distinguish them from user space object files.

我的问题是如何将新的(修改)ELF加载到鉴于当前ELF加载器present内核(如卸载它可能prevent二进制文件被执行)?

My question is how can I insert the new(modified) ELF loader into the kernel given that the current ELF loader is present(as unloading it may prevent binaries from being executed)?

推荐答案

什么你所描述的是不是真的编译一个内核模块,因为它就是通常所说的。你已经建立静态链接到内核的对象,也没有办法,你可以只是对象加载到运行的内核。

What you have described is not really compiling a "kernel module" as it is commonly referred to. You have built an object that is statically linked into the kernel and there is no way that you can load just that object into a running kernel.

内核模块通常是指可加载的内核模块(LKM)。建筑及加载FS作为LKM是你需要/想要什么。看看下面的HOWTO。按照构建所需的FS作为LKM。然后,只需更换一个LKM(.ko)文件,并重新启动(通常可以动态地删除和插入的LKM但不知道如何将影响有点像ELF FS根本 - 你可以,如果你第一次尝试rmmod的/ modprobe的没有重新启动IKE)。

"kernel module" usually refers to "loadable kernel module" (LKM). Building and loading the fs as an LKM is what you need/want. Take a look at the below HOWTO. Follow that to build the desired fs as an LKM. Then you can just replace that one LKM (.ko) file and reboot (normally you can dynamically remove and insert LKMs but not sure how that will affect something fundamental like the ELF fs - you can try rmmod/modprobe without a reboot first if you ike).

http://www.tldp.org/HOWTO/Module-HOWTO/ x73.html

这篇关于编译一个单独的内核模块(于Debian / Ubuntu)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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