1、解压内核源码到目录文件 #tar xjvf linux-2.6.22.6.tar.bz2 -C /home/guoqian/test4-1-1/
#cd /home/guoqian/test4-1-1/linux-2.6.22.6 # make distclean
2、配置文件 # cp /boot/config-2.6.18-53.el5 /home/guoqian/test4-1-1/linux-2.6.22.6/.config
3、配置内核 #make menuconfig
4、编译内核 #make bzImage
出现
Root device is (253, 0)
Boot sector 512 bytes.
Setup is 7545 bytes.
System is 1794 kB
Kernel: arch/i386/boot/bzImage is ready (#1),内核已编译好!
5、内核模块编译 #make modules
6、内核模块安装 #make modules_install (会将编译好的内核模块从内核源代码目录copy至/lib/modules下)!
7、制作ramdisk #mkinitrd initrd-$version $version(eg:在Linux2.6.22.6.的上级目录执行 #mkinitrd -v /boot/initrd-2.6.22.6 2.6.22.6)
8、内核安装 #cp arch/x86/boot/bzIamge /boot/vmlinuz-$version(eg:cp /home/guoqian/test4-1-1/linux-2.6.22.6/arch/i386/boot/bzImage /boot/vmlinuz-2.6.22.6)
#cp $initrd /boot/
#修改 /etc/grub.conf 或menu.lst (eg:lrwxrwxrwx 1 root root 11 2013-03-06 menu.lst -> ./grub.conf)
修改好后重启查看是否成功!
9、编写内核模块程序及Makefile:
编译成功后出现文件下出现hello_module.c hello_module.ko hello_module.mod.c hello_module.mod.o hello_module.o Makefile Module.symvers
10、加载模块: #insmod hello_module.ko
# 可以 tail /var/log/messagesc查看打印出的信息
Dec 11 11:32:10 localhost kernel: Hello Mini2440 Module is installed !
11、查看 : lsmod 出现
Module Size Used by
hello_module 5632 0
可以看到模块已经加载成功!
12、卸载模块:rmmod hello_module
可以 tail /var/log/messagesc查看打印出的信息
Dec 11 11:37:10 localhost kernel: Goodbye Mini2440 module was removed
modprobe 加载一个模块到内核,它依据/lib/modules/<$version>/modules.dep
作者申明:MODULE_LICENSE()
模块作者:MODULE_AUTHOR()
模块描述:MODULE_DESCRIPTION()
模块别名:MODULE_ALIAS()
模块参数:module_param(name,type,perm) (name 为模块名称,type 为类型,perm为权限) eg:使用insmod param age=12 name=yukimura。
内核符号导出:/proc/kallsyms 记录内核中所有导出的符号的名字和地址。
在一个内核模块中写的函数如果要其他模块使用,你需要将内核符号导出! EXPORT_SYMBOL(函数名)。
EXPORT_SYMBOL_GPL(函数名) 只能用于包含GPL许可证的模块!
eg:#insmod calculate.ko
#insmod main.ko
# lsmod
Module Size Used by
main 5632 0
calculate 5760 1 main