编译Linux内核

一、下载 linux 内核源代码

1.0  www.kernel.com 下载源代码

2.0  将下载的源程序解压到 /usr/src 内

二、下载工具

2.0  下载 build-essential:apt-get install build-essential

2.1  下载 libqt3-header:apt-get install libqt3-header

2.2  下载 gcc:apt-get install gcc

备注:如果不下载,后面的 make xconfig 将提示:没有规则可以创建

三、配置并编译

进入 /usr/src 目录,以下操作都是在该目录下进行:

3.0  make xconfig 配置 linux 内核信息,如果需要在嵌入式中装 linux 这点很重要。

详见:http://lamp.linux.gov.cn/Linux/kernel_options.html 讲解了内核配置

3.1  make clean (当源被重新编译需要执行)

3.2  make

3.3 make modules_install

3.4 cp /arch/i386/boot/bzImage /boot/vmlinuz-<version>

3.5  cp System.map /boot/System.map

3.6   mkinitramfs -o /boot/initrd.img-<version> <version>

3.7 修改 /boot/grub/grub.cfg

Reboot 

 

四、遇到问题

4.0  No rule to make target `xxx‘. 没有规则可以创建目标** ”解释为:

This means that make decided it needed to build a target, but then couldn’t find any instructions in the makefile on how to do that, either explicit or implicit (including in the default rules database).

If you want that file to be built, you will need to add a rule to your makefile describing how that target can be built. Other possible sources of this problem are typos in the makefile (if that filename is wrong) or a corrupted source tree (if that file is not supposed to be built, but rather only a prerequisite).

4.1  bzImage (中间 I 是大写的 i,不是小写的 L)很多人都写错了

4.2 如果发现自己的 /boot/grub 内没有 menu.lst ,修改 grub.conf 也是一样的

4.3  重启后遇到“Could not load /lib/modules/2.6.39.4/modules.dep ”但实际进去看后,该文件存在,这是因为 initrd.img-<version> 没有生成好,删除原来的文件 initrd.img-<version> update-initrdramfs –c –k 2.6.39.4 重新生成

4.4  中间make xconfig提示没有规则创建 xconfig这是因为 libqt3-header 没有安装,需要先更新源文件服务器,apt-get update 更新源文件,再下载即可

4.5 mkinitrd 是 RedHat 独有的,在编译其他内核时,应该采用 mkinitramfs 命令

五、参考

5.0 http://www.sudu.cn/info/html/edu/20080428/302845.html  内容不错,就是内核老了点

5.1  http://www.linuxforums.org/forum/kernel/55612-mini-howto-compile-linux-kernel-2-6-a.html  这里讲的更详细一些,并且给出了最小配置

5.2  http://www.linuxsir.org/bbs/showthread.php?t=363346 

       http://helloyesyes.iteye.com/blog/1084899 这两个都是 debian 内核编译方法

5.3  http://skpsun.blog.163.com/blog/static/276005520091455245426/

编译Linux内核》上有4条评论

回复 柳青 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据