红联Linux门户
Linux帮助

升级Linux内核奋斗记

发布时间:2006-02-26 00:32:22来源:红联作者:yo
我的PIII Dell机运行着内核2.4.的RedHat,自从Linux内核2.6发布以来一直想把该系统升级到内核2.6。经过一番艰辛万苦,终于成功了。为了体验一下在Linux下编写多线程程序的步骤,又更新GCC和C语言库。在此愿和各位朋友共享这段经历,共享这段成果。
(可能有记录错误,仅供参考)。
具体步骤包括以下内容:
1,升级内核的具体步骤
2,更新GCC
3,使用glibc2.3.5
4,使用NPTL线程进行编程

在此之前,先简要地介绍一下Linux内核2.6所做的改进及新增功能
Linux2.6主要在以下的10个方面作了很大的改进,简单概括如下,有关详细情况,请参阅相关资料。
1)通过改善并行处理能力和采用POSIX线程等,提高了系统的处理能力,从而Linux真正具备大型信息系统所要求性能。
2)通过改善文件系统的输出/输入能力和提高对大容量内存的利用效率,使得Linux能够更胜任大型信息系统中的数据处理。
3)加强了对数据库应用程序的支持。
4)提高了抗系统高负荷时能力。
5)提高了系统的可用性,包括对不停机时备份和不停机时更换硬件功能的支持。
6)强化了对网络的支持,增加了对Ipv6, SCTP, IPSec,等的支持。
7)通过增加访问控制和内核暗号化技术,提高了系统的安全性。
8)强化了对电源的管理。
9)强化了对嵌入式CPU和系统的支持。
10)添加了更多的硬件驱动程序。

一.升级内核
1, 下载linux-2.6.3.tar.bz2(可以是更新的版本)到/usr/src
bzcat linux-2.6.3.tar.bz2 | tar xvf -
cd linux-2.6.3
阅读README及Changes 文件,确认必须的工具软件。因为不是笔记本电脑和笔记本电脑有关的软件可以忽略。
发现module-init-tools需要更新。
2,下载module-init-tools-0.9.13.tar.bz2
bzcat module-init-tools-0.9.13.tar.bz2 | tar xvf -
cd module-init-tools-0.9.13
./configure --prefix=/usr/local/module-init
make
make moveold
make install
/usr/local/module-init/sbin/generate-modpobe.conf > /etc/modprobe.conf
成功。
3, 编译Linux内核
cd /usr/src/linux-2.6.3
make menuconfig
一看太麻烦了,而且许多选项不知所云。退出该程序。
执行make oldconfig,对kernel2.6新增的不熟悉的选项作不选或为缺省。
make bzImage
make modules modules_install
pwd
/usr/src/linux-2.6.3
mv arch/i386/boot/bzImage /boot/bzImage2.6.3
mv System.map /boot/System.map-2.6.3
cd /boot
mv System.map oldSystem.map
ln -s System.map-2.6.3 System.map
4,建立sys目录
mkdir /sys
5, 修改相关文件,增加对sys的支持
在/etc/rc.d/rc.sysinit文件增加对sys的支持。
1) 找到mount -f /proc的行,在其下面,增加 mount -f /sys
2) 找到 action $ “Mounting proc filesystem:” mount -n -t proc /proc /proc 在其下面,增加
action $ “Mounting sysfs filesystem:” mount -n -t sysfs /sys /sys
3) 把文件中的 ksyms 改成 kallsyms
在/etc/fstab文件中,增加一行
none /sys sysfs defaults 0 0
在/etc/rc.d/init.d/halt中,增加对sys的支持
把 awk ‘$2 ~/^/$ | ^/proc | ^/dev / {next} 变为
awk ‘$2 ~/^/$ | ^/proc | ^/sys | ^/dev / {next}
6,启动
修改/etc/lilo.conf, 增加下面的设置

image=/boot/bzImange2.6.3
label=Linux2.6.3
read-only
root=/dev/hda3(由自己的PC设置决定)
成功。

二,更新GCC (因为gcc2.95.3无法编译glibc-2.3.5)
下载gcc-3.4.4.tar.bz2
bzcat gcc-3.4.4.tar.bz2 | tar xvf -
cd gcc-3.4.4
./configure -prefix=/usr/local/gcc344 -enable-shared -enable-threads -enable-threads=posix -enable-languages=c,c++,f77
make bootstrap (因为使用CFLAGS选项时,出错了,所以省略)
make install
ln -s /usr/local/gcc344/bin/gcc /usr/bin/gcc

三,使用glibc-2.3.5
1)、通过调查发现要编译glibc-2.3.5,要求binutils在2.13以上。所以必须安装binutils-2.14
下载binutils-2.14.tar.gz
tar zxpvf binutils-2.14.tar.gz
mkdir binutils-build
cd binutils-build
../binutils-2.14/configure -prefix=/usr -enable-shared
make tooldir=/usr
make check
make tooldir=/usr install
cp ../binutils-2.14/include/libiberty.h /usr/include
2) 安装glibc-2.3.5
下载 glibc-2.3.5.tar.gz 和 glibc-2.3.5-fix_test-1.patch
tar zxpvf glibc-2.3.5.tar.gz
patch -Np1 -i ../glibc-2.3.5-fix_test-1.path
mkdir glibc-build
cd glibc-build
../glibc-2.3.5/configure -prefix=/usr/local/glibc235 -enable-add-ons=linuxthreads -enable-kernel=2.6.0 (若安装在/usr目录下,很危险,可能会损坏你的系统)
make
make check (必须执行的一步)
make localedata /install-locales (对应各国文字)
mkdir /usr/man/man3(man的安装路径)
make -C ../glibc-2.3.5/linuxthreads/man install
上面的安装完成以后,最好把/usr/local/glibc235/lib和/usr/local/glibc235/include加入到系统的路径中,这样在编译程序时,就不必指定库和header文件的路径了。

四、使用NPTL进行线程编程
#include
#include
#include
#include
void thread_fun(void * arg);
char message[] = “I am created thread”;
int main() {
int rnt;
pthread_t new_thread;
void *thread_result;
rnt=pthread_create(&new_thread,NULL, thread_fun, (void*) message);
if (rnt != 0) {
perrer (“thread creation failed”);
exit(EXIT_FAILURE);
}
printf(“Waiting for other thread to finish…
”);
rnt = pthread_join(new_thread, &thread_result);
if (rnt != 0) {
perrer (“thread join failed”);
exit(EXIT_FAILURE);
}
printf(“Thread join, it returned %s
”, (char*) thread_result);
printf(“message now %s
”, message);
exit(EXIT_SUCCESS);
}
void *thread_fun (void * arg) {
printf(“the new thread is running. Argument was %s
”,(char*)arg);
sleep(3);
strcpy(message, “Bye”);
pthread_exit(“Thank you for the test”);
}
编译
gcc -D_REENTRANT test_thread.c -o test_thread -lpthread
./test_thread
成功了。
文章评论

共有 0 条评论