[原创]Fedora5编译升级内核版本(更新完毕)

发布者:仙果
发布于:2009-08-06 14:23
作者:仙果
声明:本文系原创,转载请注明出处
开始:
      因工作需要,需要升级linux内核版本,系统为Fedora5 ,内核版本为2.6.15,需要升级为2.6.20,这个过程大概花了一个星期的时间,从一点不了解linxu内核,到升级成功,也经历了不少困难,都是从google上搜索得来的。以下是整个过程
      一。安装linux虚拟机
      linux虚拟机版本为Fedora5 ,内核版本为2.6.15,从网络上下载得来,大小为3.02 GB ,下载地址好像找不到了,大家去可以google搜索,就是下载需要花费点时间
    安装过程没什么需要注意的地方,大家按照正常安装过程即可安装完毕,下图是安装过程中的界面:



正在安装中ing
以下图片是是安装完成并显示内核版本


二。下载内核源码
       下载地址为:http://archives.fedoraproject.org/pub/archive/fedora/linux/core/updates/5/SRPMS/
有很多选项,找到2.6.20,
kernel-2.6.20-1.2320.fc5.src.rpm                   21-Jun-2007 18:48   45M  RPM Package
大小为45M,貌似还有点大
三。安装。。。重要
[shabi004@localhost ~]$ su root
口令:
[root@localhost shabi004]# cd Desktop/
[root@localhost Desktop]# ls
kernel-2.6.20-1.2320.fc5.src.rpm
[root@localhost Desktop]# rpm -ivh kernel-2.6.20-1.2320.fc5.src.rpm


出现提示:
warning: group brewbuilder does not exist - using root

不用理会,继续即可。
[root@localhost Desktop]# cd ..
[root@localhost shabi004]# cd ..
[root@localhost home]# cd ..
[root@localhost /]# cd usr/src/redhat/
[root@localhost redhat]# ls
BUILD  RPMS  SOURCES  SPECS  SRPMS
[root@localhost redhat]# cd SPECS
[root@localhost SPECS]# ls
kernel-2.6.spec
[root@localhost SPECS]# rpmbuild -bp --target i686 kernel-2.6.spec

这个过程大概会持续10分钟的样子,依照计算机配置而定,查看的话会发现有一些警告,不用理会,继续即可

[root@localhost SPECS]# cd ..
[root@localhost redhat]# cd BUILD/
[root@localhost BUILD]# ls
kernel-2.6.20
[root@localhost BUILD]# cd kernel-2.6.20/
[root@localhost kernel-2.6.20]# ls
Config.mk  linux-2.6.20.i686  vanilla  xen
[root@localhost kernel-2.6.20]# cd linux-2.6.20.i686/
[root@localhost linux-2.6.20.i686]# ls
arch     CREDITS        fs       Kbuild       Makefile  REPORTING-BUGS  usr
block    crypto         include  kernel       mm        scripts
configs  Documentation  init     lib          net       security
COPYING  drivers        ipc      MAINTAINERS  README    sound
[root@localhost linux-2.6.20.i686]#


接下来就是最重要的,配置内核,命令是
make menuconfig

会弹出一个GUI选框,你可以选择内核支持模块,比如CPU,网卡,文件系统类型,驱动等等许多内容,具体设置依照硬件环境进行设置,我会把一些有用的资料以附件的形式发在文后。
如图所示:

出现:
  │ │        Load an Alternate Configuration File                         │ │
  │ │        Save an Alternate Configuration File  


在这个地方进行保存,保存配置好的内核模块等等
接下来,会出现
.config界面,ENTER 回车,按OK即可
exit 退出 内核配置界面

[root@localhost linux-2.6.20.i686]# make menuconfig
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
  HOSTCC  scripts/kconfig/lxdialog/textbox.o
  HOSTCC  scripts/kconfig/lxdialog/util.o
  HOSTCC  scripts/kconfig/lxdialog/yesno.o
  HOSTCC  scripts/kconfig/mconf.o
  HOSTLD  scripts/kconfig/mconf
scripts/kconfig/mconf arch/i386/Kconfig


*** End of Linux kernel configuration.
*** Execute 'make' to build the kernel or try 'make help'.

开始下一步,需要使用到的命令是

make dep
make
make bzImage
make modules
make modules_install
make install

其中:
第一个命令make dep实际上读取配置过程生成的配置文件,来创建对应于配置的依赖关系树,从而决定哪些需要编译而那些不需要;make zImage和make bzImage则实现完全编译内核,二者生成的内核都是使用gzip压缩的,只要使用一个就够了,它们的区别在于使用make bzImage可以生成大一点的内核。建议大家使用make bzImage命令。

  后面三个命令只有在你进行配置的过程中,在回答Enable loadable module support (CONFIG_MODULES)时选了"Yes"才是必要的,make modules和make modules_install分别生成相应的模块和把模块拷贝到需要的目录中

使用make这个命令的时候,花费的 时间比较长,需要耐心等待,中间会产生一些警告信息,不用理会即可
执行到
[root@localhost linux-2.6.20.i686]# make install
sh /usr/src/redhat/BUILD/kernel-2.6.20/linux-2.6.20.i686/arch/i386/boot/install.sh 2.6.20-prep arch/i386/boot/bzImage System.map "/boot"


这里好像内核已经升级完毕了,由于Fedora5是有Grub引导的,需要确认下
使用命令如下:
[root@localhost shabi004]# cd ..
[root@localhost home]# cd ..
[root@localhost /]# cd boot
[root@localhost boot]# ls
config-2.6.15-1.2054_FC5      System.map-2.6.15-1.2054_FC5
grub                          System.map-2.6.20-prep
initrd-2.6.15-1.2054_FC5.img  vmlinuz
initrd-2.6.20-prep.img        vmlinuz-2.6.15-1.2054_FC5
lost+found                    vmlinuz-2.6.20-prep
System.map
[root@localhost boot]# cd grub
[root@localhost grub]# ls
device.map     grub.conf         minix_stage1_5     stage2
e2fs_stage1_5  iso9660_stage1_5  reiserfs_stage1_5  ufs2_stage1_5
fat_stage1_5   jfs_stage1_5      splash.xpm.gz      vstafs_stage1_5
ffs_stage1_5   menu.lst          stage1             xfs_stage1_5
[root@localhost grub]# vi grup.conf


显示:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
#          initrd /initrd-version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.20-prep)
        root (hd0,0)
        kernel /vmlinuz-2.6.20-prep ro root=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.20-prep.img
title Fedora Core (2.6.15-1.2054_FC5)
        root (hd0,0)
        kernel /vmlinuz-2.6.15-1.2054_FC5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.15-1.2054_FC5.img
~
"grub.conf" 21L, 770C


关于其中的解释,由于自己的水平有限,也解释不清楚,还请大家去google下就可以得到完整答案。这里我只说自己懂得:
title Fedora Core (2.6.20-prep): 内核启动版本
root (hd0,0):hd*表示第几个硬盘,比如本例就是第一块硬盘,后面的*表示所第一个分区,本例为第一块一硬盘,第一个分区。

现在重启系统,在重启时按任意键进入grub引导界面
如图:


选择对应的2.6.20进入系统
[shabi004@localhost Desktop]$ uname -a
Linux localhost 2.6.20-prep #1 Thu Aug 6 17:39:48 CST 2009 i686 i686 i386 GNU/Linux


到此:此次升级内核算是完成了。

四:总结:完成内核升级的过程算是经过千辛万苦,自己也是小白中的菜鸟,在牛人看来无非就是几行命令,对自己来说就是很难了,总结下整个过程,学到了很多东西,最起码得到的是不在对linux系统存在有恐惧感,下一步自己的目标就是调试,自己一定能够成功!

附:在这个过程中自己在网上查找了一些资料,以附件的方式发上来,以备像我这样的菜鸟来查阅!
上传的附件:

声明:该文观点仅代表作者本人,转载请注明来自看雪