redhat9(内核版本2.4.20-8)编译内核到版本(2.4.26)


1. 前言
在我写这篇文章的时候,还是一个linux的初学者,经历了n次失败后的成功当然是兴奋的,于是很想把她写下来。
我的操作系统是Redhat9,其内核版本为2.4.20-8 ,需要升级到2.4.26,采用全新的2.4.26内核源码进行升级,主要的参考资料是《The Linux Kernel HOWTO》,另外还有一些参考资料我想就不提了,免得误导象我一样的初学者。
接下来有三个部分,“步骤索引”、“步骤说明”和“附录”,“步骤索引”真实的记录了我成功升级内核的步骤,“步骤说明”将对“步骤索引”一些注意事项进行说明,“附录”摘录自《The Linux Kernel HOWTO》的相关部分。
2. 步骤索引
[root@localhost src]# tar vxfj linux-2.4.26.tar.bz2
[root@localhost src]# ln Cs linux2.4.26 linux
[root@localhost src]# cd /usr/src/linux
[root@localhost linux]# cp /boot/config-2.4.20-8 .config
[root@localhost linux]# make menuconfig
[root@localhost linux]# make dep
[root@localhost linux]# make clean
[root@localhost linux]# make bzImage
[root@localhost linux]# make modules
[root@localhost linux]# make modules_install
[root@localhost linux]# cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.26
[root@localhost linux]# cp .config /boot/config-2.4.26
[root@localhost linux]# cp System.map /boot/System.map-2.4.26
[root@localhost linux]# mkinitrd /boot/initrd-2.4.26.img 2.4.26
[root@localhost linux]# cd /boot
[root@localhost boot]# rm -f System.map vmlinuz
[root@localhost boot]# ln -s System.map-2.4.26 System.map
[root@localhost boot]# ln -s vmlinuz-2.4.26 vmlinuz
[root@localhost boot]# cd grub
[root@localhost grub]# vi grub.conf
[root@localhost grub]# reboot
3. 步骤说明
源码的升级,我将其归纳为源码准备、工具准备、配置内核、编译内核、安装模块、启动设置和重启7个步骤。我是以root的身份登录的,所以省略了用户切换的过程。
3.1. 源码准备
这个没有什么好说的,到 www.kernel.org去下载就是。我这里下载的是linux-2.4.26.tar.bz2,将其放到/usr/src目录下面,使用下面的方法解压缩:
[root@localhost src]# cd /usr/src
[root@localhost src]# tar vxfj linux-2.4.26.tar.bz2
[root@localhost src]# ln Cs linux2.4.26 linux
解压缩完成后得到linux-2.4.26目录。喜欢图形界面的朋友可以不用这样,我在gnome下执行鼠标右键弹出菜单命令“解压缩到这里…”也能达到同样的目的,不过经常出错。
3.2. 工具准备
我所使用的两个内核版本跨度不大,所以没有特别安装什么工具,如果是升级到2.6.x版本会需要一些而外的工具。
3.3. 配置内核
这是编译内核最麻烦的地方了,我们将要面临一大堆驱动模块的配置选项,对于我这样的菜鸟就头晕了,开始时傻呼呼的按照网站上的一些资料介绍,执行make menuconfig或make xconfig,结果碰得“头破血流”。
在redhat9下执行make xconfig,会提示需要qt,在我看来make menuconfig是最好用的,不过在此之前不需要着急。 内核配置的结果是在源码的顶级目录下生成一个.config文件,其中当然是保存了各种配置项的设定值,如果不想在那么多的似懂非懂的选项中选择的话,先执行下面的操作:
[root@localhost src]# cd /usr/src/linux
[root@localhost linux]# cp /boot/config-2.4.20-8 .config
在redhat9安装完成后,/boot/config-2.4.20-8就是我们所需要的.config文件,只要将其复制到源码目录并改名成.config就可以了,这样,在执行下面的操作就能得到当前系统的配置,如果需要增加驱动模块,只需要作少量修改就可以了。(注意,如果使用ls的话,结果中我们看不到.config文件,加上选项 ls Cal就可以了。)
[root@localhost linux]# make menuconfig
[root@localhost linux]# make dep
[root@localhost linux]# make clean
关于.config文件的说明请参考附录.config部分。

3.4. 编译内核
[root@localhost linux]# make bzImage
当你看到类似以下信息,说明编译成功了
tools/build -b bbootsect bsetup compressed/bvmlinux.out CURRENT > bzImage
Root device is (3, 8)
Boot sector 512 bytes.
Setup is 4886 bytes.
System is 917 kB
make[1]: Leaving directory `/usr/src/linux-2.4.26/arch/i386/boot'
3.5. 安装模块
[root@localhost linux]# make modules
[root@localhost linux]# make modules_install
在make modules_install执行完成后,如果成功了,你将会在/lib/modules目录下看到2.4.26。

3.6. 启动设置
[root@localhost linux]# cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.26
[root@localhost linux]# cp .config /boot/config-2.4.26
[root@localhost linux]# cp System.map /boot/System.map-2.4.26
[root@localhost linux]# mkinitrd /boot/initrd-2.4.26.img 2.4.26
很多资料上介绍了手工生成ramdisk的过程,mkinitrd可以帮我们完成这个稍微复杂的过程,如果这个操作执行成功,mkinitrd会在/boot目录下生成initrd-2.4.26.img文件。
[root@localhost linux]# cd /boot
[root@localhost boot]# rm -f System.map vmlinuz
[root@localhost boot]# ln -s System.map-2.4.26 System.map
[root@localhost boot]# ln -s vmlinuz-2.4.26 vmlinuz

关于bzImage和System.map请参考附录。

我安装redhat9时选择的是grub,所以需要改变grub.config中的设置。
[root@localhost boot]# cd grub
[root@localhost grub]# vi grub.conf
用vi打开/boot/grub/grub.conf文件,找到下面的两行,将其注释,并增加下面的内容。
# kernel /boot/vmlinuz-2.4.20-8 ro root=LABEL=/
# initrd /boot/initrd-2.4.20-8.img
kernel /boot/vmlinuz ro root=/dev/hda8
initrd /boot/initrd-2.4.26.img
root指定/挂载点的位置,如果不知道,可以使用df命令查看。
这里有一点需要注意,整个启动设置可以使用一个命令make install来完成,不过会有很多问题,对grub.conf文件的设置就是其中之一,make install修改的grub.conf文件仍然使用”LABEL”符号,而这个符号在2.4.26的内核下已经不起作用了。

3.7. 重启
[root@localhost grub]# reboot
但愿你也成功!
4. 总结
网上的资料虽然丰富,但多数不系统,也没有随着环境的升级而得到及时的更正,很多时候找下来的资料都不知道实用于那个版本的操作系统或内核。举个小例子,在 www.kernel.org官方网站上有一个readme文件,其中说明如何编译内核,其中有这么几步操作:
cd include
rm Crf asm linux scsi
ln Cs asm-i386 asm
ln Cs linux linux
ln Cs scsi scsi

如果执行了这些操作,在编译2.4.26的内核时会出现错误。
在没有人指导的情况下,最好能找比较系统点的资料,或者到书店买本书。我就是这样,多亏找到了《The Linux Kernel HOWTO》才使得我成功编译内核,否则还不知道要失败多少次呢。
5. 附录
.config
Everytime you compile and install the kernel image in /boot, you should also copy the corresponding config
file to /boot area, for documentation and future reference. Do NOT touch or edit these files!!
bzImage
The bzImage is the compressed kernel image created with command 'make bzImage' during kernel compile. It
important to note that bzImage is not compressed with bzip2 !! The name bz in bzImage is misleading!! It
stands for "Big Zimage". The "b" in bzImage is "big". Both zImage and bzImage are compressed with gzip.
The kernel includes a mini−gunzip to uncompress the kernel and boot into it. The difference is that the old
zImage uncompresses the kernel into low memory (the first 640k), and bzImage uncompresses the kernel into
high memory (over 1M). The only problem is that there are a very few machines where bzImage is known to
have problems (because the machines are buggy). The bzImage actually boots faster, but other than that,
there's no difference in the way the system *runs*. The rule is that if all drivers cannot fit into the zImage,
then you need to modularize more.
If the kernel is small, it will work as both a zImage and a bzImage, and the booted system runs the same way.
A big kernel will work as a bzImage, but not as a zImage. Both bootimages are gzipped, (bzImage is not
bzipped as the name would suggest), but are put together and loaded differently, that allows the kernel to load
in higher address space, that does not limit it to lower memory in the pathetic intel architecture. So why have
both? Backward compatability. Some older lilos and loadlins don't handle the bzImage format. Note, they
*boot* differently, but *run* the same. There is a lot of misinformation given out about what a bzImage file is
(mostly about it being bzip2ed).
System.map
System.map is a "phone directory" list of function in a particular build of a kernel. It is typically a symlink to
the System.map of the currently running kernel. If you use the wrong (or no) System.map, debugging crashes
is harder, but has no other effects. Without System.map, you may face minor annoyance messages.
Do NOT touch the System.map files.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值