升級Linux作業系統核心奮鬥記

升級linux核心奮鬥記

我的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 成功了。