青春修炼手册表情包:内核移植(redhat 9 2.4.20

来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 18:43:40
内核移植(redhat 9 2.4.20----》2.6.10)      朗读全文标签:linux内核 题记:最近,想要学习Linux驱动程序设计第三版(好书!!),需要一个2.6.10的内核,于是就想给原有的Redhat 9.0升级一下,耗时一个早上,终于升级成功了,多亏了网上一些大侠的文章,在这我再将我参考的两篇文章总结一下,希望能对大家有帮助。
1)下载一份内核源代码,我下的是linux-2.6.10.tar.bz2,你可在如下地址下载它或者是更新的版本.
http://www.kernel.org/pub/linux/kernel/v2.6/
2) 下载最新版本的module-init-tools( "module-init-tools-3.4.tar.gz" and "modutils-2.4.26-1.src.rpm")
http://www.kernel.org/pub/linux/kernel/people/jcm/module-init-tools/attic/module-init-tools-3.4.tar.gz
http://www.kernel.org/pub/linux/utils/kernel/modutils/v2.4/modutils-2.4.26-1.src.rpm
3)安装module-init-tools. 它会替代depmod [/sbin/depmod]和其他工具.
tar -zxvf module-init-tools-3.0.tar.gz
cd module-init-tools-3.0
./configure --prefix=/sbin
make
make install
./generate-modprobe.conf /etc/modprobe.conf
4)安装modutils-2.4.26-1.src.rpm. 你可能会看到"user rusty and group rusty not existing"的警告. 没关系,你只需强制安装就是了.如果你不对Redhat 9和Redhat 8做这几步, 你将会在"make modules_install"这一步时出现问题.
rpm -i modutils-2.4.26-1.src.rpm
rpmbuild -bb /usr/src/redhat/SPECS/modutils.spec
rpm -Fi /usr/src/redhat/RPMS/i386/modutils-2.4.26-1.i386.rpm
5)解压缩内核源代码.把下载的源代码包放到目录/usr/src下,然后
cd /usr/src
tar xvfj linux-2.6.10.tar.bz2
cd linux-2.6.10
二、配置工作
1、配置内核选项。有点繁琐,~~希望一次成功哦~~。
# cd linux-2.6.10  (进入到/usr/src/linux-2.6.10目录下)
# make mrproper  (该命令可确保源代码目录下没有不正确的.o文件)
# make menuconfig (配置内核各选项)
此时会出现一个图形界面,列出了所有的内核配置选项,有的选项下还有子选项,你可以用方向键来选择,用Y键来确定。经过我多次试验,大多数选项默认就行,以下几个选项必须选择(请认真核对下面每一个选项,否则编译很有可能前功尽弃):
(1)Loadable Module support选项中,选上“Module unloading”和“Automatic kernel module loading”这两项;
(2)Device Drivers--->Block Devices中选上“Loopback device support”;
     Device Drivers--->Multi-device support(RAID and LVM)处要选上“device mapper  support”;
     Device Drivers--->Graphics support,一定要选上“ Support for buffer devices”;
     Device Drivers  --->USB support  --->选上“USB Mass Storage support”(如果是在实环境中,想要更多USB支持,就全选吧。我的是在虚拟机中,用不着了)
     Device Drivers  --->;Network device support  --->Ethernet (10 or 100Mbit)  --->        <*> RealTek RTL-8139 C+ PCI Fast Ethernet Adapter support (EXPERIMENTAL) > 0  
  <*> RealTek RTL-8139 PCI Fast Ethernet Adapter support
(3)File system--->(以下9个选项是关于ext2和ext3文件系统配置,全部选上)
           Second extended fs support
           Ext2 extended attributes
           Ext2 POSIX Access Control Lists
           Ext2 Security Labels
           Ext3 journalling file system support
           Ext3 extended attributes
           Ext3 POSIX Access Control Lists
           Ext3 Security Labels
           JBB (ext3) debugging support
     File system--->DOS/FAT/NT Filesystems  --->选上“NTFS file system support”;
注意:
       ext2和ext3文件系统配置很重要,也是必需的,如果对Ext3、Ext2文件的支持直接编译进内核,在你reboot时机器就会当掉,出现如下错误信息:
          kernel panic : no init found ,try passing init = option to kernel.....
或者是:
          VFS:Cannot open root device "hdxy" or unknow-block(0,0)
          Please append a correct "root=" boot option
          kernel panic:VFS:Unable to mount root fs on unknown-block(0,0)
或者是:
          mount: error 19 mounting ext3
          pivotroot: pivot_root(/sysroot,/sysroot/initrd) failed: 2
          umount /initrd/proc fail: 2
          Freeing unused kernel memory: 244k freed
          Kernel panic – not syncing: No init found. Try passing init = option to kernel
(我的机器就是在重启之后出现第三种错误,进不去系统,郁闷死,只好重装了~~~如果依照本文做完所有步骤,当你重启Linux系统后,若不幸进不去2.6.10内核,你会发现你的出错信息就是上面三种了~~~哈!)
(4)3)声卡驱动 (这里我选择的是AC97的声卡)
  也要选择自己声卡对应的驱动编译进内核,比较普遍的声卡是i810_audio,以下就是这种声卡的配置,以供参考   Device Drivers --->   Sound --->   <*> Sound card support   Advanced Linux Sound Architecture --->   <*> Advanced Linux Sound Architecture                                                                                   <*> Sequencer support 4                                                                                 < > Sequencer dummy client                                                                                 <*> OSS Mixer API                                                                                 <*> OSS PCM (digital audio) API                                                                                      [*] OSS Sequencer API                                                                                <*> RTC Timer support MAGUM  PCI devices --->   <*> Intel i8x0/MX440, SiS 7012; Ali 5455; NForce Audio; AMD768/8111 PI  Open Sound System --->   < > Open Sound System (DEPRECATED)(5)如果你在vmware下编译内核,硬盘用的是scsi的,以下三个选项必选:
     Device Drivers ---><*>SCSI device support  (此项不选的话,下面两项就选择不上)
     Device Drivers ---><*>SCSI device support ---><*>SCSI disk support
     Device Drivers---><8>SCSI device support--->SCSI low-level drivers---><*>; BusLogic SCSI support
三、编译工作
OK,繁杂的配置工作完成了,至此,编译前的准备工作都做好了!
9、开始编译啦……
在/usr/src/linux-2.6.10目录下,执行以下命令即可编译。编译需要一段时间,给自己倒杯茶耐心等候吧!
# make dep  (建立编译时所需的从属文件。注意:如果内核从未编译过,此步可跳过)
# make clean  (清除内核编译的目标文件。注意:如果内核从未编译过,此步可跳过)
# make bzImage  (注意大小写。这一步才是真正编译内核)
    内核编译成功后,会在/usr/src/linux/arch/i386/boot目录中生成一个新内核的映像文件bzImage。如果用make  zImage编译,内核很大的话,系统会提示你使用make   bzImage命令来编译,所以我直接用make bzImage来编译。
# make modules  (编译可加载模块)
# make modules_install  (安装可加载模块)
  安装成功后,系统会在/lib/modules目录下生成一个2.6.10子目录,里面存放着新内核的所有可加载模块。
# make install  (安装新内核)
注意:
        make install的时候可能会出现如下错误信息:
        No module BusLogic found for kernel 2.4.20
        mkinitrd failed
此问题一般只出现在SCSI硬盘+VMWARE+REDHAT架构中,因为BusLogic被编译进了内核而不是一个module的形式(2.4内核的Buslogic模块即使静态编译进内核也不行)。解决方式是直接将BusLogic.o文件复制过去:
# cp /usr/src/linux-2.6.10/drivers/scsi/BusLogic.o  /lib/modules/2.6.10/kernel/drivers/scsi
不过别忘记,复制过后再执行一下make install。
四、启动新内核
10、将新内核和System.map文件拷贝到/boot目录下,依次执行以下命令:    
# cp  /usr/src/linux-2.6.10/arch/i386/boot/bzImage   /boot/vmlinuz-2.6.10    
# cp  /usr/src/linux-2.6.10/System.map   /boot/System.map-2.6.10    
# cd  /boot  (进入boot目录)
# rm –rf  System.map  (删除原来的连接)    
# ln –s System.map-2.6.10  System.map   (重新建立连接)    
11、修改Grub启动管理器
如果没有错误的话, 下面开始修改grub配置文件(不要告诉我你用的lilo)
在/boot目录下,执行以下命令:
# new-kernel-pkg --mkinitrd --depmod --install 2.6.10 (这时候你的/boot下会生成一个initrd-2.4.18.img,并且你的grub.conf文件也作了相应更改)
# df  (查看根目录在那个分区,下一步要用到。注意,这里根分区一般是你最大的那个分区,也就是“/”,千万不要搞错哦。我的为 /dev/hda7)
# vi /boot/grub/grub.conf 
进入grub.conf文件,找到如下信息:
default=1
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.6.10)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.10 ro root= LABEL=/
        initrd /boot/initrd-2.6.10.img
做两处修改:
(1) 将default=1改为default=0(不改的话也可以,只不过重启之后会默认进入2.4内核)
(2) 将kernel行的“LABEL=/”换成根目录所在的分区(上一步查看的就是)
此步很重要,修改错误将可能导致进不去系统,我把我修改后的grub.conf文件列出来,不明之处,可以对照修改:
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.6.10)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.10 ro root=/dev/hda7
        initrd /boot/initrd-2.6.10.img
title Red Hat Linux (2.4.20-8)
        root (hd0,0)
        kernel /boot/vmlinuz-2.4.20-8 ro root=LABEL=/
        initrd /boot/initrd-2.4.20-8.img
12,OK,大功告成!赶快重启,看看升级后的2.6内核吧~~~~