您的位置:首页 > 其它

Debian编译内核源码

2013-05-16 22:31 489 查看
安装内核源码

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 <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
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

阅读(1632) | 评论(0) | 转发(0) |

0
上一篇:转:GAS 的AT&T的语法规则

下一篇:一篇气死了99名老师的中学生作文

相关热门文章

Linux内核源码分析--内核启动...

37600 ティファニー ネックレ...

Linux内核源码分析--内核启动...

epoll的优点

使用LSM实现自己的访问控制...

linux 常见服务端口

什么是shell

linux socket的bug??

linux的线程是否受到了保护?...

一个适用于windows和linux的抓...

shell将变量当命令执行问题【...

深入理解Linux网络技术内幕-设...

高性能网络I/O框架-netmap源码...

深入理解Linux网络技术内幕-...

Linux下bin文件的安装

给主人留下些什么吧!~~

评论热议
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: