Chinaunix首页 | 论坛 | 博客
  • 博客访问: 46499
  • 博文数量: 21
  • 博客积分: 1425
  • 博客等级: 上尉
  • 技术积分: 175
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-11 20:51
文章分类

全部博文(21)

文章存档

2013年(1)

2010年(12)

2009年(8)

我的朋友

分类: LINUX

2009-01-12 23:34:04

安装内核源码

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

阅读(4285) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~