LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: Dopilas

怎样才能加载成功啊?

[复制链接]
 楼主| 发表于 2004-4-9 15:04:46 | 显示全部楼层
我刚才做了:
cd /usr/src/linux/include
rm -f -r asm-i386

想把链接删除,结果把asm-i386删除了,是不是很严重啊?
越来月糟糕了 ...
 楼主| 发表于 2004-4-9 15:06:31 | 显示全部楼层
以上都是以事情时间先后顺序做的,现在我该怎么办啊?:help :help :help
发表于 2004-4-9 17:34:28 | 显示全部楼层
重新安装内核源代码,从头做起。
发表于 2004-4-9 18:10:54 | 显示全部楼层
我是按上面说的做了连接,编译、加载都没问题,
你把程序里的#include ...都改成相对路径试试
发表于 2004-4-10 17:25:06 | 显示全部楼层
将version.h中的版本号从2.4.20改成2.4.20-8
就OK了
 楼主| 发表于 2004-4-12 02:37:33 | 显示全部楼层
非常感谢各位的帮助!

我重装了系统,改用 linux-mandrake 9.2 了,内核是2.4.22

-------------------------------------------------------------
改写上面头文件的路径为:
#include <linux/kernel.h> /*We'ar doing kernelwork*/
#include <linux/module.h> /*Specifically a module*/
---------------------------------------------------------------

--------------------------------------------------------------
结果是:
[root@localhost myfirewall]# gcc -c  helloag.c
[root@localhost myfirewall]# /sbin/insmod helloag.o
helloag.o: couldn't find the kernel version the module was compiled for
[root@localhost myfirewall]#
-------------------------------------------------------------------

我装的是光盘版的mandrake, 系统 /usr/src目录下没有源代码,其他地方也没有, 只有包含头文件的/usr/include/linux 目录.

哪位帮帮忙,按顺序给我讲一下怎样操作才能加载成功?

kj501版主,我按照你的意思重装了系统,然后怎样从头做起啊?...呵呵

libinary版主,非常感谢你的回复,希望你再帮我一次,我现在的内核是2.4.22了
我想要的是顺序的步骤(最好是直接从终端的拷贝),多谢!! 真的非常感谢了!!
版主们真尽责啊!

luoyong兄弟,你的建议如果能够成功就非常省事了,可惜看到贴子时我已经换了系统,但我还是试了一下,把version.h中的2.4.22改成2.4.20和2.4.20-8结果都是
[root@localhost myfirewall]# gcc -c  helloag.c
[root@localhost myfirewall]# /sbin/insmod helloag.o
helloag.o: couldn't find the kernel version the module was compiled for
[root@localhost myfirewall]#
 楼主| 发表于 2004-4-12 03:01:27 | 显示全部楼层
---------------------------------------------------
//helloag.c

//It is copied from a book

#include <linux/kernel.h> /*We'ar doing kernel work*/
#include <linux/module.h> /*Specifically a module*/

/*Deal with CONFIG_MODVERSIONS>*/

#if CONFIG_MODVERSIONS==1
#define <linux/modversions.h>
#endif

/*Initialize the module*/
int init_module()
{
        printk("Hello. World _ this is the kernel speaking\n");

        /* If we returned a non zero value, it means that
         * init_module failed and the kernel module can't be loaded*/

        return 0;
}

/*cleanup - undid whatever init_module did */
void cleanup_module()
{
        printk("Short is the file of the kernel module\n");
}
---------------------------------------------------------------
 楼主| 发表于 2004-4-12 20:15:56 | 显示全部楼层
首先在/usr/include/linux/version.h里把2.4.22改为2.4.22-10mdk
然后调整了头文件的次序:
--------------------------------------------------
#define MODULE
#include <linux/module.h>
#define __KERNEL__
#include <linux/kernel.h>
nt init_module(void) {
     printk("<1>Hello World\n");
     return 0;
}
void cleanup_module(void) {
     printk(KERN_ALERT "Goodbye world 1.\n");
}
------------------------------------------------------------

然后:
[root@localhost myfirewall]# gcc -c helloag.c
[root@localhost myfirewall]# /sbin/insmod helloag.o
Warning: loading helloag.o will taint the kernel: no license
  See http://www.tux.org/lkml/#export-tainted for information about tainted modules
Module helloag loaded, with warnings
[root@localhost myfirewall]# dmesg | tail -1
Hello World
[root@localhost myfirewall]# /sbin/rmmod helloag
[root@localhost myfirewall]# dmesg | tail -1
Goodbye world 1.
[root@localhost myfirewall]#

终于演示出来了!多谢各位帮助!非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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