QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1382|回复: 5

linux-2.6.x内核(转贴)

[复制链接]
发表于 2004-5-20 19:10:45 | 显示全部楼层 |阅读模式
The Guide of Upgrading to linux kernel 2.6.x

Author: Rongkai Zhan
date: 2004-3-14

前言: linux-2.6.x内核发布后, 坛子里的兄弟们肯定都迫不及待地要升级原有的2.4.x内核. 但是由于与2.6.x内核配套的系统程序并没有相应的来得及更新, 升级过程会碰到很多问题, 因此觉得有必要把我的经验与大家share一下:-) XD们以后碰到类似问题时, 请先阅读本文, 而不要一上来就盲目发帖.

ps, you are welcome to fix me.

1. 备份重要的数据

这是个好习惯,就不用多说了:-)

2. 下载最新的2.6.x内核源码包

这个当然要到官方网站www.kernel.org或者它的mirror站点去下载了, 最好别到那些unknown的网站去下, 因为那些源码包有可能被恶意做了手脚. 最新的linux-2.6.4.tar.bz2源码包大概有33M左右. 下载的时候可以泡杯coffee, 然后点根烟......

在/usr/src/目录下解开源码包, 得到源代码目录/usr/src/linux-2.6.4/. 在对kernel做任何事情之前, 建议你先看一下它的README文件和Documentation/Changes文件, 从中你会得到不少有用的信息. 这些信息会让你在随后的升级过程避免很多不必要的麻烦.

在文档Documentation/Changes中给出了欲成功地升级到kernel-2.6.x所需的最小系统软件要求, 比如对于kernel-2.6.4是这样的:

o Gnu C 2.95.3 # gcc --version
o Gnu make 3.79.1 # make --version
o binutils 2.12 # ld -v
o util-linux 2.10o # fdformat --version
o module-init-tools 0.9.10 # depmod -V
o e2fsprogs 1.29 # tune2fs
o jfsutils 1.1.3 # fsck.jfs -V
o reiserfsprogs 3.6.3 # reiserfsck -V 2>&1|grep reiserfsprogs
o xfsprogs 2.6.0 # xfs_db -V
o pcmcia-cs 3.1.21 # cardmgr -V
o quota-tools 3.09 # quota -V
o PPP 2.4.0 # pppd --version
o isdn4k-utils 3.1pre1 # isdnctrl 2>&1|grep version
o nfs-utils 1.0.5 # showmount --version
o procps 3.2.0 # ps --version
o oprofile 0.5.3 # oprofiled --version

对于RH8/9的用户而言, 上述要求基本上都能满足. 大概只有两个程序需要更新: modutils工具包和mkinitrd程序.

3. 安装module-init-tools-3.0.tar.gz工具包

linux-2.6.x内核的module处理过程有所改变(很多原先在用户态下由modutils处理的工作都放到内核里去完成了), 因此2.4.x下的modutils工具包已经不在适合新的2.6.x内核, 必需将其升级到module-init-tools工具包. 该工具包的最新版本是3.0(ps, 该工具包的版本从0.9.15一下跳到3.0, 其跨度之大...hoho). 可以下载module-init-tools-3.0.tar.gz源码包的地方有两个:

o Rusty's Linux Kernel Page: http://www.kernel.org/pub/linux/kernel/people/rusty/modules/module-init-tools-3.0.tar.gz
o http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.0.tar.gz

接下来, 按照下列步骤安装module-init-tools工具包:

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

命令"make moveold"将把系统原来的modutils工具程序改名为"*.old"(比如,lsmod.old等等). NOTE! 这是非常重要的一步, 千万不要省略. 这将使得你可以继续使用原有的linux-2.4.x系统, 因为在2.4.x系统下, 新的module-init-tools工具包实际上是倚赖原来"*.old"程序来加载内核模块. 如果忘记了这一步也不要紧张, 可以先下载并安装原来的modutils程序包, 然后按照上面的步骤重来一遍就可以了.

新的module-init-tools工具包不再使用原来的/etc/modules.conf配置文件了, 而是使用新的配置文件/etc/modprobe.conf. 因此必需用命令"./generate-modprobe.conf /etc/modprobe.conf"来生成新的配置文件/etc/modprobe.conf. 但是令人不爽的是, 这个生成的新配置文件存在BUG, 下面我们将会提到.

4. 更新mkinitrd程序

可以到站点http://people.redhat.com/arjanv/2.6/RPMS.kernel/去下载最新的mkinitrd- 3.5.15.1-2.i386.rpm包. 由于mkinitrd程序包依赖于device-mapper包, 而device-mapper包又倚赖于lvm2包, 因此你还要同时下载device-mapper-1.00.07-1.i386.rpm包和lvm2-2.00.08-2.i386.rpm包.

5. 配置,编译和安装linux-2.6.x内核

新内核在Makefile方面的改动很大, "make menuconfig"和"make xconfig"继续存在, 但是"make xconfig"被改写了, 不再使用原来的Tcl/Tk语言, 而是基于QT库了. 新增加了"make gconfig", 它是基于GTK库的. "make xconfig"和"make gconfig"比原来更强大而且更易于使用了. 但不幸的是, 它们好像还不太稳定......因此, 还是使用我最喜欢的"make menuconfig"吧:-)

关于新内核的配置想提几点:

o 关于"Loadable Module support"选项, 一定要选上"Module unloading"和"Automatic kernel module loading"这两个选项.
o 关于"Processor type and features"选项, 一定要选上"Preemptible Kernel"选项, 这是2.6.x内核优于2.4.x内核的重要原因之一.
o 关于"Block Devices"的配置, 一定要选上对loopback和ramdisk的支持.
o 关于"Multi-device support(RAID and LVM)", 要选上"device mapper".
o 关于"Input device support", 记得要选上"Keyboards"和"Mice"的支持.
o 关于"Graphics support", 要选上对frame buffer的支持.
o 关于ALSA, 要选上"OSS API emulation"选项. OSS可以不用了.
o 关于USB, 能选的都选上吧:-)
o 关于文件系统, 选上常用的那几种就可以了. 如果要体验sysfs的话, 要选上对sysfs的支持.

配制好内核后, 就可以直接编译了, "make dep"这一步已经显示地需要了.

# make bzImage
# make modules
# make modules_install
# make install

上面的命令"make install"将: (1)把压缩内核映象拷贝到/boot目录下, 并创建相应的System.map符号链接; (2)修改bootloader的配置文件; (3)调用mkinitrd程序创建内核的initrd映象. 对于GRUB而言, 将在/boot/grub/grub.conf配置文件增加如下类似的配置行:

title Red Hat Linux (2.6.4)
root(hd0, 1)
kernel /boot/vmlinuz-2.6.4 ro root=LABEL=/
initrd /boot/initrd-2.6.4.img

不幸的是, 新内核并不识别"root=LABEL=/"这个启动参数. 如果现在你就重新启动新内核的话, 将发生kernel panic错误. 因此, 必需把这个"root=LABEL=/"启动参数去掉, 就OK了.(如果是安装2.6.6的内核应该没有问题的.)

到这里, 你已经可以重启机器, 用kernel-2.6.4启动了. 当然, 多半你不会成功, 不是没鼠标就是没键盘:-)

6. 支持Hotplug

当然, 首先要在内核配置时配置了HOTPLUG的支持. 然后, 由于/proc/ksyms改名为/proc/kallsyms, 所以必需修改启动脚本/etc/rc.sysinit. 为了兼容原有的linux-2.4.x系统, 可以加上下面几行:

#
# ----- KERNEL 2.6.x support ------
# This is for compatibility between kernel-2.4.x and kernel-2.6.x
#
UNAME=`uname -r`
KERNELVER=${UNAME:0:3}
if [ "$KERNELVER" = "2.6" ]; then
#
# This is kernel-2.6.x
#
KSYMS=/proc/kallsyms
else
#
# This is kernel-2.4.x
#
KSYMS=/proc/ksyms
fi

然后, 把rc.sysinit文件中所有出现/proc/ksyms的地方都换成"$KSYMS"变量引用. 配置好后, 还必需下载hotplug的用户态辅助工具包:http: //www.kernel.org/pub/linux/utils/kernel/hotplug/hotplug-2004_03_11.tar.gz. 解开这个包以后, 直接"make install"就可以了. 它将产生/etc/hotplug/配置目录.

7. 体验sysfs

首先, 创建目录/sys:

# mkdir /sys

然后, 按照下列步骤修改启动脚本/etc/rc.sysinit文件:

o 找到行: mount -f /proc", 在下面增加:

if [ "$KERNELVER" = "2.6" ]; then
mount -f /sys
fi

o 找到行: action $"Mounting proc filesystem: " mount -n -t proc /proc /proc, 在其下面增加这样一行:

#
# Mount /sys for kernel-2.6.x
#
if [ "$KERNELVER" = "2.6" ]; then
action $"Mounting sysfs filesystem: " mount -n -t sysfs /sys /sys
fi

接下来, 在/etc/fstab文件中, 加入这样一行:

none /sys sysfs defaults 0 0

最后, 修改/etc/init.d/halt脚本中的halt_get_remaining函数:

将:
awk '$2 ~ /^\/$|^\/proc|^\/dev/{next}
改为:
awk '$2 ~ /^\/$|^\/proc|^\/sys|^\/dev/{next}

8. 支持USB设备

linux-2.6.x的USB驱动模块的名字已经改变了, 所以由此引起的问题多多......, 对应于USB-2.0的host控制器的内核模块名字仍然是ehci-hcd, 对应USB-1.1的host控制器的内核模块名字已经从usb-ohci改为ochi-hcd, 对应于通用USB host控制器的内核模块名字已经从usb-uhci该为uhci-hcd.

然而不幸的是, 在安装module-init-tools程序包时生成的/etc/modprobe.conf配置文件却仍然使用usb-ohci这个名字. 例如:

alias usb-controller usb-ohci
alias usb-controller1 ehci-hcd

因此, 要把它改为:

alias usb-controller ohci-hcd
alias usb-controller1 ehci-hcd

如果不做这样的修改, 那么使用USB-1.1 host控制器的机器在启动内核的时候将着不到相应的驱动模块.

支持USB键盘的模块名字也从keybdev变为usbkbd, 支持USB鼠标的模块名字也从mousedev改为usbmouse. 因此, 我们必需修改启动脚本/etc/rc.sysinit文件. 同时为了兼容原有的2.4.x系统, 我们在脚本的一开始定义两个变量:

#
# ----- KERNEL 2.6.x support ------
# This is for compatibility between kernel-2.4.x and kernel-2.6.x
#
UNAME=`uname -r`
KERNELVER=${UNAME:0:3}
if [ "$KERNELVER" = "2.6" ]; then
#
# This is kernel-2.6.x
#
KSYMS=/proc/kallsyms
KEYBDEV_NAME=usbkbd
MOUSEDEV_NAME=usbmouse
else
#
# This is kernel-2.4.x
#
KSYMS=/proc/ksyms
KEYBDEV_NAME=keybdev
MOUSEDEV_NAME=mousedev
fi

然后, 把/etc/rc.sysinit脚本文件中出现keybdev和mousedev的地方都改为$KEYBDEV_NAME和$MOUSEDEV_NAME. 把脚本文件/etc/rc.sysinit中的needusbstorage部分从:

needusbstorage=
if [ $usb = "1" ]; then
needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /proc/bus/usb/devices 2>/dev/null`
LC_ALL=C grep 'hid' /proc/bus/usb/drivers || action $"Initializing USB HID interface: " modprobe hid 2> /dev/null

action $"Initializing USB keyboard: " modprobe $KEYBDEV_NAME 2> /dev/null
action $"Initializing USB mouse: " modprobe $MOUSEDEV_NAME 2> /dev/null
fi

改为:

needusbstorage=
if [ $usb = "1" ]; then
if [ "$KERNELVER" = "2.6" ]; then
needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /sys/bus/usb/devices 2>/dev/null`
LC_ALL=C grep 'hid' /sys/bus/usb/drivers || action $"Initializing USB HID interface: " modprobe hid 2> /dev/null
else
needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /proc/bus/usb/devices 2>/dev/null`
LC_ALL=C grep 'hid' /proc/bus/usb/drivers || action $"Initializing USB HID interface: " modprobe hid 2> /dev/null
fi
action $"Initializing USB keyboard: " modprobe $KEYBDEV_NAME 2> /dev/null
action $"Initializing USB mouse: " modprobe $MOUSEDEV_NAME 2> /dev/null
fi

好了, 到此为止, 我们应该可以重新启动机器了, 赶快去体验最新的kernel-2.6.4吧:-)

9. 其它

o 关于在linux-2.6.x系统上不能正常使用RPM命令的问题, 请参阅文档[2]和[6].
o 关于声卡的问题, 可以参阅参考文档[2]和[6].
o 关于在linux-2.6.x系统上运行vmware的问题, 请参阅参考文档[2]和[6].

10. 参考文档

[1] Kernel 2.6.x, the new breed: http://linuxbooks.pananix.com/kernel2.6.html
[2] Upgrading RH9 to 2.6.0-test4: http://www.fearthecow.net/index.pl?section=guest&page=kernel
[3] HowTo Upgrade To The 2.6 Kernel: http://kerneltrap.org/node/view/799
[4] Building Linux Kernel 2.6 on Red Hat 8: http://www.sabalsoftware.com/article_buildingKernel26OnRedhat8.php
[5] Migrating to Linux kernel 2.6 on recent Redhat systems: http://linux-sxs.org/upgrading/migration26.html
[6] Migrating to Linux Kernel 2.6: http://thomer.com/linux/migrate-to-2.6.html
发表于 2004-5-20 21:18:42 | 显示全部楼层
Thanks.
I am agreeable to see the notice. But  i cant download the soft from the site. So, i expecte  t o set up the soft by video disk shortly by your caution.
回复

使用道具 举报

发表于 2004-5-22 14:32:52 | 显示全部楼层
几点小错误给你更正一下,因为我发现照你的装确实能装好,不过还存在很多问题。呵呵~
第一个错误:
o 找到行: action $"Mounting proc filesystem: " mount -n -t proc /proc /proc, 在其下面增加这样一行:

#
# Mount /sys for kernel-2.6.x
#
if [ "$KERNELVER" = "2.6" ]; then
action $"Mounting sysfs filesystem: " mount -n -t sysfs /sys /sys             <<---这里应该是 mount -n -t sysfs sysfs /sys   另外后双引号也就是mount前面一定要有空格,否则这个程序不能运行。
fi

错误2:
alias usb-controller usb-ohci
alias usb-controller1 ehci-hcd



基本就两个错误了,我也没什么水平,不然也不会照你的文章做了,不过有错误还是应该指出的对不?
因此, 要把它改为:

alias usb-controller ohci-hcd
alias usb-controller1 ehci-hcd
_______________________________
这里反了,应该是:
alias usb-controller ehci_hcd
alias usb-controller1 ohci_hcd
回复

使用道具 举报

发表于 2004-5-22 23:33:19 | 显示全部楼层
Attention:

In addition,

1. there's no "hid" module any more in 2.6.6 kernels,

it had been changed to "usbhid".

2. in my machine, no "mousedev" and "keybdev" found. Perhaps "hid" or "usbhid" does the job.

3. Devices driven by OHCI are rarely today, while there are many UHCI devices. so

   alias usb-controller ehci-hcd
   alias usb-controller1 uhci-hcd

will be better and reliable.

For reference only!!
回复

使用道具 举报

发表于 2004-5-22 23:35:11 | 显示全部楼层
What does so called "sysfs" do?

Any introductions?
回复

使用道具 举报

发表于 2004-5-23 00:02:01 | 显示全部楼层
[quote=""]o 关于USB, 能选的都选上吧


compiling the2.6.x kernel from 2.4.x kernel is a painful try.

from my point of view, USB support selections must be probed very carefully.

I suggest to look into these concerned online help for each selection when compiling, particularly for USB support.

( Considering that this article was tranformed from other author from other site, the fault is not yours. Nevertheless, it really be of some help to us.  I must say, we have a long run to go. )
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-10-2 00:28 , Processed in 0.089864 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表