Chinaunix首页 | 论坛 | 博客
  • 博客访问: 114369
  • 博文数量: 24
  • 博客积分: 1226
  • 博客等级: 中尉
  • 技术积分: 320
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-11 20:47
文章分类

全部博文(24)

文章存档

2011年(2)

2010年(4)

2009年(5)

2008年(13)

我的朋友

分类: LINUX

2010-03-03 19:13:19

1. 源码准备

       这个没有什么好说的,到去下载就是。我这里下载的是linux-2.4.26.tar.bz2,将其放到/usr/src目录下面,使用下面的方法解压缩:
 
[root@localhost root]# cd /usr/src
[root@localhost src]# tar vxfj linux-2.4.26.tar.bz2
 
       解压缩完成后得到linux-2.4.26目录。喜欢图形界面的朋友可以不用这样,我在gnome下执行鼠标右键弹出菜单命令“解压缩到这里…”也能达到同样的目的,不过经常出错。

2. 工具准备

       我所使用的两个内核版本跨度不大,所以没有特别安装什么工具,如果是升级到2.6.x版本会需要一些而外的工具。

3. 配置内核

       这是编译内核最麻烦的地方了,我们将要面临一大堆驱动模块的配置选项,对于我这样的菜鸟就头晕了,开始时傻呼呼的按照网站上的一些资料介绍,执行make menuconfig或make xconfig,结果碰得“头破血流”。
       在redhat9下执行make xconfig,会提示需要qt,在我看来make menuconfig是最好用的,不过在此之前不需要着急。  内核配置的结果是在源码的顶级目录下生成一个.config文件,其中当然是保存了各种配置项的设定值,如果不想在那么多的似懂非懂的选项中选择的话,先执行下面的操作:
 
[root@localhost src]# cd /usr/src/linux-2.4.26
[root@localhost linux-2.4.26]# cp /boot/config-2.4.20-8 .config
 
       在redhat9安装完成后,/boot/config-2.4.20-8就是我们所需要的.config文件,只要将其复制到源码目录并改名成.config就可以了,这样,在执行下面的操作就能得到当前系统的配置,如果需要增加驱动模块,只需要作少量修改就可以了。(注意,如果使用ls的话,结果中我们看不到.config文件,加上选项 ls –al就可以了。)
 
[root@localhost linux-2.4.26]# make menuconfig
[root@localhost linux-2.4.26]# make dep
[root@localhost linux-2.4.26]# make clean

4. 编译内核

[root@localhost linux-2.4.26]# 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'

5. 安装模块

[root@localhost linux-2.4.26]# make modules
[root@localhost linux-2.4.26]# make modules_install
在make modules_install执行完成后,如果成功了,你将会在/lib/modules目录下看到2.4.26。

6. 启动设置

[root@localhost linux-2.4.26]# cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.26
[root@localhost linux-2.4.26]# cp .config /boot/config-2.4.26
[root@localhost linux-2.4.26]# cp System.map /boot/System.map-2.4.26
[root@localhost linux-2.4.26]# mkinitrd /boot/initrd-2.4.26.img 2.4.26
       很多资料上介绍了手工生成ramdisk的过程,mkinitrd可以帮我们完成这个稍微复杂的过程,如果这个操作执行成功,mkinitrd会在/boot目录下生成initrd-2.4.26.img文件。
 
[root@localhost linux-2.4.26]# 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
 
我安装redhat9时选择的是grub,所以需要改变grub.config中的设置。
[root@localhost boot]# cd grub
[root@localhost grub]# vi grub.conf
    用vi打开/boot/grub/grub.conf文件,我的grub内容如下:(注意:要把default改为1,然后在最后加上几行)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 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/hda2
#          initrd /initrd-version.img
#boot=/dev/hda
default=1
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.4.20-8)
       root (hd0,0)
       kernel /vmlinuz-2.4.20-8 ro root=LABEL=/
       initrd /initrd-2.4.20-8.img
title Red Hat Linux (2.4.26)
        root (hd0,0)
        kernel /vmlinuz-2.4.26 ro root=LABEL=/
        initrd /initrd-2.4.26.img
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       这里有一点需要注意,整个启动设置可以使用一个命令make install来完成,不过会有很多问题,对grub.conf文件的设置就是其中之一。

7. 重启

[root@localhost grub]# reboot
 
    但愿你也成功!
命令清单如下:
[root@localhost root]# cd /usr/src
[root@localhost src]# tar vxfj linux-2.4.26.tar.bz2
[root@localhost src]# cd /usr/src/linux -2.4.26
[root@localhost linux-2.4.26]# cp /boot/config-2.4.20-8 .config
[root@localhost linux-2.4.26]# make menuconfig
[root@localhost linux-2.4.26]# make dep
[root@localhost linux-2.4.26]# make clean
[root@localhost linux-2.4.26]# make bzImage
[root@localhost linux-2.4.26]# make modules
[root@localhost linux-2.4.26]# make modules_install
[root@localhost linux-2.4.26]# cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.26
[root@localhost linux-2.4.26]# cp .config /boot/config-2.4.26
[root@localhost linux-2.4.26]# cp System.map /boot/System.map-2.4.26
[root@localhost linux-2.4.26]# mkinitrd /boot/initrd-2.4.26.img 2.4.26
[root@localhost linux-2.4.26]# 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
 
                                            转自 往事如风
阅读(1726) | 评论(0) | 转发(0) |
0

上一篇:天书夜谈笔记

下一篇:内核2.4.20到2.6.20.1

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