a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 97|回复: 0

[综合辅导] Linux认证:在用户空间加载和卸载驱动

[复制链接]
发表于 2012-8-4 12:07:07 | 显示全部楼层 |阅读模式
经由过程以下呼吁加载膳缦沔编译生成的模块:引用-beyes:/home/beyes/C/kernel # insmod ./hello.ko   注重的是,如不美观使用在图形系统下的虚拟终端,那不会看到输出信息,可是这些信息一般被保留在 /var/log/messages 文件里:引用-beyes:/home/beyes/C/kernel # cat /var/log/messages | grep hello Aug  7 01:55:35 linux-beyes kernel: hello linux kernel
0 ]" w3 t6 H8 _, t# ~( l7 e4 Z  卸载模块使用 rmmod 呼吁:引用rmmod hello
# r9 {) s/ ~8 U0 b. t) C  卸载模块时,如不美观是是在图形系统下的虚拟终端,那么退出信息同样保留在 /var/log/messages 文件里:引用linux-beyes:/home/beyes/C/kernel # cat /var/log/messages | grep bye Aug  7 02:02:56 linux-beyes kernel: bye……lwave from the kernel如不美观编译时呈现:引用ERROR: Kernel configuration is invalid. include/linux/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it.
, B  z1 J$ z! K! i4 b' i; U  可以考试考试:引用make oldconfig make prepare% ~( J. O, s& h; D: ?7 @
  make oldconfig    : 基于已有的。config进行设置装备摆设, 若有新的符号, 它将询问用户。  P7 C  g/ m5 O% y$ O( W
  这时辰再编译,可能会呈现:引用/bin/sh: scripts/mod/modpost: 没有阿谁文件或目录make: *** 错误 127 make: *** 错误 2' {$ k+ c" i  t" h% c
  再使用下面呼吁:引用make scripts
6 g2 C) f2 c8 X. M" M1 t  最后编译成功。  f. Z- C, |" l- X8 [" s
  如不美观呈现引用insmod:error inserting 'hello.ko': -1 Invalid module format
: X$ A6 ^. }; k3 i0 d* ?+ T; N  错误,则查看日志文件tail /var/log/messages 文件,若是提醒 "no symbol version for module_layout" 错误,则使用以下语句编译:引用make -C /lib/modules/`uname -r`/build M=`pwd` modules
% {  k) i  Y* ?/ y3 m. \  而不是直接在 -C 参数后填上 /usr/src/linux-.2.6.xxx 这样的路径直接指向内核源码树,因为按照错误提醒,应该是找不到 modules.symbols 文件所致。4 E9 Z. P- }9 l
  关于 /lib/modules 目录的声名:
, A. Z. Z/ d- Q  该目录包含了内核模块及其他文件。 注重, modules一一般会有多个目录: 系统自带的内核模块在这里, 你编译自己的内核模块后, 它们也会被安装到这里。 分歧的目录由内核版本号来区分。 即modules里目录的名称是内核版本号。 (使用$ uname -r 可知当前系统内核所用的模块位于哪个目录)。( B3 A" m+ v* g) x7 M. `" X4 i
  /lib/modules//build储存为该版本的内核编译新模块所需的文件。 搜罗Makefile, .config, module.symVers(模块符号信息), 内核头文件(位于include/, include/asm/中)
9 P5 n" f* d) _  N, |; s) @3 D6 A  /lib/modules//kernel储存内核方针文件(以。ko为后缀)。 它的目录组织和内核源代码中kernel的目录组织不异。9 S. `& W( ^" C; h$ y7 F$ V  a& I: x
  /lib/modules//中:modules.alias       : 模块别军号说。 模块加载工具使用它来加载响应的模块。
3 d- v, g8 M; W  modules.dep        : 界说了模块间的依靠关系。
3 p! L- Q! j5 G  modules.symbols : 指定符号属于哪个模块。
8 G' }0 A1 m1 |. u  这些文件都是文本文件, 可以查看它们。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-21 11:21 , Processed in 0.209850 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表