Linux内核编译过程


1.下载http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.24.tar.bz2到/usr/src
2.
#cd /usr/src
#tar xjvf linux-2.6.24.tar.bz2
#cd linux-2.6.24
#make mrproper
#make menuconfig
#make clean
#make bzImage
#make modules
#make modules_install
#cp System.map System.map-2.6.24
#mkinitrd /boot/initrd-2.6.24.img 2.6.24
#vi /boot/grub/grub.conf

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
timeout=5
selinux=0
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.18-1.2798.fc6)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-1.2798.fc6 ro root=LABEL=/1
initrd /boot/initrd-2.6.18-1.2798.fc6.img
title Linux (2.6.24)
root (hd0,0)
kernel /boot/vmlinuz-2.6.24 ro root=LABEL=/1
initrd /boot/initrd-2.6.24.img

解释:
#make mrproper
如果是第一次编译可以不用执行这个命令,这个的目的是清除原先此目录下残留的.config和.o(object)文件,但是如果您已经编译过多次内核的话,这一步是一定要的,不然以后出现很多小问题

#make menuconfig
配置内核选项,编译内核的关键步骤。有四种方式
#make config(基于文本的最为传统的配置界面,不推荐使用)
#make menuconfig(基于文本选单的配置界面,字符终端下推荐使用)
#make xconfig(基于图形窗口模式的配置界面,Xwindow下推荐使用)
#make oldconfig(如果只想在原来内核配置的基础上修改一些小地方,会省去不少麻烦)
各选项的介绍可以参考这里http://www.mytiandi.com/html/53/n-11453.html,这是2.6.19的,与2.6.24有一些不同,只能作为参考。
在make menuconfig中,有的选择[],有的选择[M],有的选择[],*表示选中直接加载进kernel,而M则表示会在后面的make modules中编译成modules,以后随时可以通过insmod和modprobe调入内核。
很多文章说执行完make menuconfig后要执行make dep,但我在执行make dep时提示***Warning: make dep is unnecessary now.可能是新版内核不需要再执行make dep了

#make clean
清除一些不必要的文件,如果不执行有可能会导致在编译过程中出现错误

#make bzImage
根据选择的内核选项,生成内核文件。如果确定生成的内核文件在640K一下,也可以用make zImage,但还是推荐用make bzImage

#make modules
将在make menuconfig时所选择为M的选项,全部编译成模块并放在/usr/src/linux-2.4.24/

#make modules_install
将编译生成的模块安装到/lib/modules/2.6.24下

#cp System.map System.map-2.6.24
2.6.24标识内核的版本

#mkinitrd /boot/initrd-2.6.24.img 2.6.24
如果用的是 SCSI硬盘并且采用的是ext3分区格式的话,一定要制作initrd.img(因为SCSI卡的驱动包括在这个里边),如果使用的是IDE硬盘,可以 跳过这一步。2.6.24是/lib/modules/下的2.6.24,是make modules_install生成的

#vi /boot/grub/grub.conf
编辑grub.conf,插入
title Linux (2.6.24)
root (hd0,0)
kernel /boot/vmlinuz-2.6.24 ro root=LABEL=/1
initrd /boot/initrd-2.6.24.img
/boot/vmlinuz-2.6.24是新内核的路径
/boot/initrd-2.6.24.img是mkinitrd /boot/initrd-2.6.24.img 2.6.24生成的

重启,在grub启动时选择 Linux (2.6.24)即可用新内核启动系统,如果要修改默认的启动内核,将/boot/grub/grub.conf中的default=0改为1,具体参考grub.conf的配置。 

相关内容