原创 升级Redhat Linux 9.0内核到2.6.18★★★★★

2011-6-14 21:12 2212 8 8 分类: MCU/ 嵌入式
这篇文章比较详细,对于操作中的目录等信息交代清楚。
 
申明:这篇也是转别人的,找不到原来的东家了。知道的给我说下,我注明出来!我实验通过了。
 
一、准备工作
首先说明,下面带#号的行都是要输入的命令行,且本文提到的所有命令行都在终端里输入。启动Linux系统,并用根用户登录,进入终端模式下。
1、查看Linux内核版本# uname -a
如果屏幕显示的是2.6.x,说明你的已经是2.6的内核,也用不着看下文了,该干什么干什么去吧!如果显示的是2.4.x,那恭喜你,闯关通过,赶快进行下一步。
2、下载2.6内核源码
下载地址:http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2
3、下载内核升级工具
(1)下载module-init-tools-3.2.tar.bz2
http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.2.tar.bz2
(2)下载mkinitrd-4.1.18-2.i386.rpm
http://ayo.freshrpms.net/Fedora/linux/3/i386/RPMS.core/mkinitrd-4.1.18-2.i386.rpm
(3)下载lvm2-2.00.25-1.01.i386.rpm
http://ayo.freshrpms.net/Fedora/linux/3/i386/RPMS.core/lvm2-2.00.25-1.01.i386.rpm
(4)下载device-mapper-1.00.19-2.i386.rpm
http://ayo.freshrpms.net/Fedora/linux/3/i386/RPMS.core/device-mapper-1.00.19-2.i386.rpm
二、配置工作
好啦,2.6内核和4个升级工具都下载完了(少一个也不行,如果没有下载齐全,请不要尝试下面的步骤,升级是不会成功的),下面回到Linux系统中开始配置工作吧。
4、将下载好的内核源码包和4个升级工具都拷贝到/usr/src文件夹下。怎么拷贝就不用我教了吧~~~~不会拷贝的去撞墙吧!~~呵呵!
5、拷贝完毕,开始解压新内核,具体操作请依次执行以下命令:
# cd /usr/src (进入到/usr/src目录下,如果已经在/usr/src目录下,可不执行该命令)
# rm –rf linux (删除linux文件夹。值得一提的是,如果内核先前从未编译过,则没有这个文件夹,此命令行可略过)
# tar jvxf linux-2.6.18.tar.bz2 (解压新内核)
# ln -s linux-2.6.18 linux (重新生成linux文件夹)
6、安装module-init-tools工具
在/usr/src目录下,依次执行下列命令:
# tar jvxf module-init-tools-3.2.tar.bz2 (解压module-init-tools)
# cd module-init-tools-3.2 (由/usr/src目录进入module-init-tools目录下)
#./configure --prefix=/
# make moveold
# make all install
#./generate-modprobe.conf /etc/modprobe.conf
7、安装另外三个升级工具
回到/usr/src目录下,依次执行下列3个命令来安装另外三个升级工具:
# rpm -ivh --nodeps mkinitrd-4.1.18-2.i386.rpm (注意,这里一定要加入--nodeps参数,下同)
# rpm -ivh --nodeps lvm2-2.00.25-1.01.i386.rpm
# rpm -ivh --nodeps device-mapper-1.00.19-2.i386.rpm
如果不更新以上几个升级包,在后面编译内核时会提示以下错误:
mkinitrd failed
make[1]: *** [install] Error 1
make: *** [install] Error 2
8、配置内核选项。有点繁琐,~~希望一次成功哦~~。
# cd linux-2.6.18 (进入到/usr/src/linux-2.6.18目录下)
# 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 frame. buffer devices”;
Device Drivers --->USB support --->选上“USB Mass Storage support”(如果是在实环境中,想要更多USB支持,就全选吧。我的是在虚拟机中,用不着了)
Device Drivers --->;Network device support --->Ethernet (10 or 100Mbit) ---><*> AMD PCnet32 PCI 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.18内核,你会发现你的出错信息就是上面三种了~~~哈!)
(4)如果你在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.18目录下,执行以下命令即可编译。编译需要一段时间,给自己倒杯茶耐心等候吧!
# 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.18子目录,里面存放着新内核的所有可加载模块。
# make install (安装新内核)
注意:
make install的时候可能会出现如下错误信息:
No module BusLogic found for kernel 2.4.12
mkinitrd failed
此问题一般只出现在SCSI硬盘+VMWARE+REDHAT架构中,因为BusLogic被编译进了内核而不是一个module的形式(2.4内核的Buslogic模块即使静态编译进内核也不行)。解决方式是直接将BusLogic.o文件复制过去:
# cp /usr/src/linux-2.6.18/drivers/scsi/BusLogic.o /lib/modules/2.6.18/kernel/drivers/scsi
不过别忘记,复制过后再执行一下make install。这一步若卡住了,下面的都无法进行。
四、启动新内核
10、将新内核和System.map文件拷贝到/boot目录下,依次执行以下命令:
# cp /usr/src/linux-2.6.18/arch/i386/boot/bzImage /boot/vmlinuz-2.6.18
# cp /usr/src/linux-2.6.18/System.map /boot/System.map-2.6.18
# cd /boot (进入boot目录)
# rm –rf System.map (删除原来的连接)
# ln –s System.map-2.6.18 System.map (重新建立连接)
11、修改Grub启动管理器
如果没有错误的话, 下面开始修改grub配置文件(不要告诉我你用的lilo)
在/boot目录下,执行以下命令:
# new-kernel-pkg --mkinitrd --depmod --install 2.6.18 (这时候你的/boot下会生成一个initrd-2.4.18.img,并且你的grub.conf文件也作了相应更改)
# df (查看根目录在那个分区,下一步要用到。注意,这里根分区不时boot的那个50M的分区,而一般是你最大的那个分区,也就是“/”,千万不要搞错哦。我的为 /dev/hda2)
# vi /grub/grub.conf
进入grub.conf文件,找到如下信息:
default=1
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.6.18)
root (hd0,0)
kernel /vmlinuz-2.6.18 ro root= LABEL=/
initrd /initrd-2.6.18.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.18)
root (hd0,0)
kernel /vmlinuz-2.6.18 ro root=/dev/hda2(=/dev/hda2可能不用加!!!!)
initrd /initrd-2.6.18.img
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
12,OK,大功告成!赶快重启,看看升级后的2.6内核吧。
根据以上内容重启后有如下问题:
A 不能上网
#vi /etc/modules.config
修改第一行如下:
alias eth0 pcnet32
重新激活网卡就行了。
=================================================================================

Linux-2.4.20-8级内核到Linux-2.6.13实战:

首先,在编译之前,要做以下几个准备工作:

1、  下载module-init-tools-3.1.tar.bz2,

下载地址:http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/

下载完后进行如下操作:

tar –zxvf module-init-tools-3.1.tar.bz2

./configure --prefix=/
        make moveold
        make all install
        ./generate-modprobe.conf /etc/modprobe.conf

2、  下载mkinitrd-4.1.18-2.i386.rpm

下载地址:http://ayo.freshrpms.net/fedora/linux/3/i386/RPMS.core/mkinitrd-4.1.18-2.i386.rpm

 

3、  下载lvm2-2.00.25-1.01.i386.rpmdevice-mapper-1.00.19-2.i386.rpm

下载地址:http://ayo.freshrpms.net/fedora/linux/3/i386/RPMS.core/lvm2-2.00.25-1.01.i386.rpm

http://ayo.freshrpms.net/fedora/linux/3/i386/RPMS.core/device-mapper-1.00.19-2.i386.rpm

4、  删除旧的软件,方法如下

rpm –e  (旧的软件名,这里是软件名,不是软件包,mkinitrd-4.1.18-2) --nodeps

接下来两步和上面一样,把旧的lvmdevice-mapper删掉,记住,这里要加――nodeps参数,不然是删不掉的[*浏览了很多的资料,发现都是没有提及这一步的,都说使用――nodeps强制安装就可以,可我装的时候却出现了错误,所以大家可以先省略这一步,先做第五步,出了问题再做一下第4步]

5、  如果已执行了第四步,直接使用rpm –ivh package-name

如果未执行第四步,使用rpm –ivh package-name ――nodeps

6OK编译前的准备工作做好了,如果不更新以上几个包在make install时会提示以下错误:mkinitrd failed
        make[1]: *** [install] Error 1
        make: *** [install] Error 2

7、现在可以编译了吧!!NO,还得去下内核呢!http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.13.tar.gz

8、把下载的tarCP/usr/src目录下,并使用tar –zxvf linux-2.6.13.tar.gz

9cd /usr/src/linux-2.6.13

10、好了,万事俱备!!哦,对了,忘了提醒一点了,请确保你有足够的磁盘空间,具体要求多少空间我不知道,记得大一点的好,有一次编译到最后就提示空间不足

11OK,接下来就正式开始make了:

  #make menuconfig

    使用这个命令后会打开一个编译对话框,以后的事就你自己慢慢去发挥吧,我也是新手,对那里面的东西也不是很熟悉,大家可以到网上去找一下关于那方面的资料,但是针对于在vmware5.0中做的朋友来说,以下几点是要特别注意的

ADevice Drivers  --->SCSI device support  ---><*>   SCSI disk support

Device Drivers  --->SCSI device support  --->SCSI low-level drivers  --->

<*> BusLogic SCSI support,如果这几项不选,等编译完成后重启后会发现系统会提示:No module BusLogic found for kernel的错误,然后死掉

   BDevice Drivers  ---> Fusion MPT device support  ---><M> Fusion MPT (base + ScsiHost) drivers<M>   Fusion MPT misc device (ioctl) driver(这个要不要,不确定)
注意:只能选模块方式,直接编译进内核,就出错,不知道为什么,这个浪费了我好多时间才找到,编译了几十次的成果。

出错信息如下:No module mptbase found for kernel vmware(*我使用默认方式并没有出现这个提示,这一段是一个网友所述,不知为何!)

   CDevice Drivers  ---> USB support  ---><*>   USB Mass Storage support
Device Drivers  ---> Networking support  --->Ethernet (10 or 100Mbit)  ---> <*>   AMD PCnet32 PCI support
(*这两段也是从那位网友那CP来的,不知这个USB不设会不会启不来,第二段是设置网卡的,VMWARE是使用AMD PCnet32的)

   D:还有一点切记,把所有的有关ext3Ext3 journalling file system support, Ext3 Security LabelsJBD (ext3) debugging support等等)的选项都编译到内核里面去,记住,是内核<*>不是模块<M>,否则重启系统后会提示:Mount: error 19 mounting ext3

   E:差不多了,还有其它的一些什么自己看看吧,或者上网搜一下,介绍一个不错的网站http://www.chinaunix.net/jh/4/484867.html

12make modules_install

13make install

14OK,这样就行了,init 6你的系统,会发现在重启后,在引导的时候会有两个不同内核的系统可选,我们当然要选刚编译的系统啦。

15、哈哈,好了,不管这个刚编译的系统有哪些不足或是缺陷的地方,但确实是成功了啊,当然,在编译对话框里面还有很多的东东要我们去学习,

16、没什么了,呵呵,如果按以上方法不成功,那就是你人品问题了-_-呵呵,开个玩笑,成功是要付出代价的,永不放弃的人才会成功。

 

======================================================================

How to Compile 2.6 kernel for RedHat 9/8

http://www.linuxquestions.org/linux/answers/Applications_GUI_Multimedia/How_to_Compile_2_6_kernel_for_RedHat_9_8

 

How to Compile 2.6 kernel for RedHat 9/8
Mike Chirico
Last Updated: Wed Mar 24 09:12:06 EST 2004

The latest version of this document

grey_loader.gif

can be found at:
http://prdownloads.sourceforge.net/souptonuts/README_26.txt?download

For configs ref:
http://sourceforge.net/project/showfiles.php?group_id=79320&package_id=1...



STEP 1:

Download the latest version of the kernel and any patches.
This documentation is done with
linux-2.6.3, but look for
later versions.
http://www.kernel.org/pub/linux/kernel/v2.6/

Also take a look at
http://www.codemonkey.org.uk/post-halloween-2.5.txt This has
some useful hints on some of the changes needed.



STEP 2:

Download the latest version of module-init-tools
"module-init-tools-3.0.tar.gz" and
"modutils-2.4.21-23.src.rpm"

http://www.kernel.org/pub/linux/kernel/people/rusty/modules/module-init-...
http://www.kernel.org/pub/linux/kernel/people/rusty/modules/modutils-2.4...



STEP 3:

Install module-init-tools. This will replace depmod
[/sbin/depmod] and other tools.

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



STEP 4:

Install modutils-2.4.21-23.src.rpm. You may get warnings
about user rusty and group rusty not existing. Also, yes,
you'll have to force the install. If you don't do these steps
for both Redhat 9 and Redhat 8, you'll have problems with the
make modules_install.

rpm -i modutils-2.4.21-23.src.rpm
rpmbuild -bb /usr/src/redhat/SPECS/modutils.spec
rpm -Fi /usr/src/redhat/RPMS/i386/modutils-2.4.21-23.i386.rpm



STEP 5:

Install and configure the kernel. Do NOT use the /usr/src/linux
area! Reference the README. I put my files in /home/src/kernel/

gunzip linux-2.6.3.tar.gz tar -xvf linux-2.6.3.tar cd
linux-2.6.3

If you have patches install these now:

bzip2 -dc ../patch-2.6.xx.bz2 | patch -p1



STEP 6:

Copy the appropriate /usr/src/linux-2.4/configs
[kernel-2.4.20-i686.config, kernel-2.4.20-i686-smp.config]
to .config in whatever directory you are installing. In my
case it's /home/src/kernel/linux-2.6.3

cp /usr/src/linux-2.4/configs/kernel-2.4.20-i686.config \
/home/src/kernel/linux-2.6.3/.config

If you don't have the source configs, you can download them
from here:

https://sourceforge.net/project/showfiles.php?group_id=79320&package_id=...

I've also included a file config2.6-chirico which was a 2.6
version for some of my systems. This isn't a bad reference if
you run into trouble.



STEP 7:

Assuming you copied the appropriate kernel-2.4 config to
.config, run the following which will run through necessary
questions for the 2.6 kernel. Or, you might want to use the
config2.6-chirico...this has already been run through make
oldconfig on my system, and I've answered the necessary questions
for a general system.

make oldconfig



STEP 8:

This is very important. Make sure you're .config has the
following in it CONFIG_EXT3_FS=y You'll run into the following
error if you leave this =m instead of =y:

pivotroot: pivot_root(/sysroot,/sysroot/initrd) failed

This is because Redhat 9.0 and 8.0 use the ext3 filesystem
for /boot ...



STEP 9:

Edit the Makefile and add changes to the Extraversion is needed.
Patches will update these values as well.

VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 3
EXTRAVERSION = -skim-ch6



STEP 10:

make bzImage



STEP 11:

make modules



STEP 12:

make modules_install



STEP 13:

make install

If you come across errors here, what version of "depmod" is
being picked up in your path?

Also, if you get a module not found, say the following:
No module aic7xxx found for kernel 2.6.x
Then, in /lib/modules/2.6.x/kernel/
drivers/scsi/aic7xxx/
cp aic7xxx.ko aic7xxx.o

insmod should look for aic7xxx.ko ;but , it looks for aic7xxx.o

If you still have trouble, make the following change in the
.config
CONFIG_BLK_DEV_SD=y
and go back to STEP 10.

You also may want to ref
kernel-2.6.3-i686-smp-chirico-aic7xxx.config
in
http://prdownloads.sourceforge.net/souptonuts/configs-0.3.tar.gz?downloa...



STEP 14:

mkdir /sys



STEP 15:

/etc/rc.sysinit needs to be modified. Look for the following
line:

action $"Mounting proc filesystem: " mount -n -t proc /proc /proc

and after this line enter the following:

action $"Mounting sysfs filesystem: " mount -t sysfs none /sys

Here's my /etc/rc.sysinit for reference:

http://prdownloads.sourceforge.net/souptonuts/rc.sysinit.txt?download



Be very careful at this step. Backup the /etc/rc.sysinit file.

Thomer [http://thomer.com/linux/migrate-to-2.6.
html ] also added
changes to /etc/fstab. I only had to do STEP 16 below.



STEP 16:

Add the following to /etc/fstab for usb support.

/proc/bus/usb /proc/bus/usb usbdevfs defaults 0 0



STEP 17 (CHECKING EVERYTHING):

Check the following:

a. The new image file should be installed on boot and there
should be sym link to it. My latest kernel is 2.6.3-skim-ch6,
and I got the "-skim-ch6" from the values I put in the Makefile,
so I see the following:

/boot
vmlinuz -> vmlinuz-2.6.3-skim-ch6
System.map -> System.map-2.6.3-skim-ch6

/boot/grub/grub.conf Should have been automatically
updated from make.

In /boot/grub/grub.conf change "default=0" to boot
with the new kernel. Here's an example of my
grub.conf:


# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to
# root (hd0,2)
# kernel /vmlinuz-version ro root=/dev/hda6
# initrd /initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,2)/grub/splash.xpm.gz
title
Red Hat Linux (2.6.3-skim-ch6)
root (hd0,2)
kernel /vmlinuz-2.6.3-skim-ch6 ro root=LABEL=/
initrd /initrd-2.6.3-skim-ch6.img


b. The directory /sys exists

c. You added the mount command for sys in /etc/rc.sysinit

d. CONFIG_EXT3_FS=y was used in the .config

e. Run /sbin/lsmod or cat /proc/modules to make
sure a 2.4 kernel module wasn't forgotten. Also
look at "$cat /proc/iomem"



STEP 18 (DEVELOP YOUR OWN 2.6 MODULES):

You're done with the 2.6 build. So learn how to develop
2.6 kernel modules. First, checkout the following article

http://lwn.net/Articles/driver-porting/

Then, take a look at the following sample code, which shows how
to create /proc entries for communicating with the kernel and writing
out to any available tty device.

http://prdownloads.sourceforge.net/souptonuts/procreadwrite.0.0.1a.tar.g...




REFERENCES:

http://www.codemonkey.org.uk/post-halloween-2.5.txt
http://kerneltrap.org/node/view/799
http://thomer.com/linux/migrate-to-2.6.html
http://www.kernel.org/

http://bugzilla.kernel.org/
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&group=linux....
http://linuxdevices.com/articles/AT3855888078.html

http://prdownloads.sourceforge.net/souptonuts/README_26.txt?download
http://prdownloads.sourceforge.net/souptonuts/rc.sysinit.txt?download
http://prdownloads.sourceforge.net/souptonuts/configs-0.3.tar.gz?downloa...
https://sourceforge.net/forum/forum.php?forum_id=353715

http://www.redhat.com/software/rhel/kernel26/
http://www.tldp.org/HOWTO/KernelAnalysis-HOWTO.html
http://www-124.ibm.com/linux/projects/?topic_id=2

KERNEL DRIVER DEVELOPMENT IN 2.6:

Excellent (series of articles):
http://lwn.net/Articles/driver-porting/

Here's my sample program:
http://prdownloads.sourceforge.net/cpearls/procreadwrite.0.0.1a.tar.gz?d...

Good but dated for 2.4 kernel:
http://www.oreilly.com/catalog/linuxdrive2/

http://linuxdevices.com/articles/AT4389927951.html
http://linuxdevices.com/articles/AT5793467888.html

文章评论0条评论)

登录后参与讨论
我要评论
0
8
关闭 站长推荐上一条 /2 下一条