免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 932 | 回复: 0
打印 上一主题 下一主题

Debian编译内核源码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-12 23:34 |只看该作者 |倒序浏览

安装内核源码
apt-cache search kernel-source
uname -r
内核源文件:
apt-get install linux-tree-xxxx
apt-get install linux-source-xxxx
内核头文件:
apt-get install linux-headers-xxxx
内核编译程序:
apt-get install linux-kbuild-xxxx
内核镜像做成deb的工具
apt-get install kernel-package
制做initrd镜像
apt-get install initrd-tools
编译内核:
make-kpkg --initrd --revision=custom.1.0 kernel_image
Debian kernel-image文件的名字格式如下:
kernel-image-(kernel-version)(--append-to-version)_(--revision)_(architecture).deb
如果我们使用了--append-to-version,我们就不需要担心apt-get会试着更新我们的内核了
安装内核:
dpkg -i ../linux-image-2.6.18-subarchitecture_custom.1.0_s390.deb

kernel-tree-x.x.x (或2.6.12以后是linux-tree-x.x.x)
这个包依赖两个包:kernel-source-x.x.x 和 kernel-patch-debian-x.x.x
这两个包就分别是源代码和debian的补丁。
编写内核模块
编写了一个内核模块程序,源代码如下:
    /* hello.c */
    #include
    #include
    #include
    static int hello_init(void)
    {
    printk(KERN_ALERT "Hello, linux kernel module\n");
    return 0;
    }
    static void hello_exit(void)
    {
    printk(KERN_ALERT "Goodbye, I've created a linux kernel module sucessfully\n");
    }
    module_init(hello_init);
    module_exit(hello_exit);
    MODULE_LICENSE("GPL");
    你需要这此源程序编写一个makefile,内容如下:
    #Makefile for hello.c file
    #
    KERNEL_DIR:=/usr/src/linux
    obj-m:=hello.o
    default:
    $(MAKE) -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
    clean:
    $(RM) .*.cmd *.mod.c *.o *.ko -r .tmp
   KERNEL_DIR是指内核源代码头文件所在目录的上一级目录,通常就是指内核源代码目录。
    编写好makefile后就可以输入make命令生成hello.ko内核模块了,然后你可以用:
    insmode hello.ko
    命令来加入内核模块,然后用:
    rmmod hello
    来删除内核模块。
删除旧的内核
1. 对着/boot/grub/menu.lst里的内容删去你不要的。最后再把/boot/grub/menu.lst里相应的项目删掉。 包括    /lib/modules/2.6.24-xxxx
/boot/vmlinuz-2.6.24-xxxx
/boot/initrd-2.6.24-xxxx
/boot/System.map-2.6.24-xxxx
2. dpkg --get-selections | grep linux    查看自己系统安装了多少内核   sudo apt-get remove linux-image-2.6.24-XXX   sudo apt-get remove linux-headers-2.6.24-XXX



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/91168/showart_1794319.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP