ubuntu系統內核替換


此處將內核由高版本替換成低版本。替換前的系統為ubuntu 12.04 kernel 3.8.0. 替換后的內核版本為2.6.35.

首先下載需要替換的內核文件,下載鏈接:https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.35.tar.gz

下載完成后開始進行解壓

$ sudo tar -zxf linux-2.6.35.tar.gz /usr/src

現在開始進行替換,步驟如下:

1)安裝必要的軟件包。在正式替換之前先安裝幾個必要的軟件包:

$ sudo apt-get install build-essential kernel-package libncurses5-dev libqt3-headers

各個包的主要作用如下:

  build-essential: 基本的編程庫(gcc, make等)

  kernel-package: Debian 系統里生成 kernel-image 的一些配置文件和工具

  libncurses5-dev: make menuconfig要調用的

  libqt3-headers: make xconfig要調用的

其他的工具在升級過程中可以根據提示安裝。

 

2)解壓。將已經下載的linux-2.6.35.tar.gz拷貝到/usr/src目錄下,然后解壓到/usr/src/linux-2.6.35目錄下。

 

3)拷貝原有配置文件。把正在使用中的內核配置文件/usr/src/linux-headers-3.8.0-29-generic/.config 拷到/usr/src/linux-2.6.35目錄下

$ sudo cp /usr/src/linux-headers-3.8.0-29-generic/.config /usr/src/linux-2.6.35

 

4)導入配置文件。運行以下命令:

$ cd /usr/src/linux-2.6.35

$ sudo make menuconfig

 

//*************可能出現的問題*************

問題:提示unable to find the ncurses libraries

解決方案:sudo apt-get install ncurses-dev

*************///

這時,終端會彈出一個配置界面,注意主菜單最后有兩項:

load a kernel configuration...

save a kernel configuration...

先選第一項 load ....,意思是,利用當前的內核配置詳單來設置將要編譯的內核,然后選save這一項保存,最后退出配置界面。

 

5)開始編譯,依次輸入以下命令:

$ sudo make mrproper   //清除以前曾經編譯過的舊文件,如果你是第一次編譯,可不執行。

$ sudo make              //編譯,此過程需要較長時間。

//*************可能出現的問題*************

問題1:gcc: error: elf_i386: no such file or directory

解決方案:

在文件:/usr/src/linux-2.6.35/arch/x86/vdso/Makefile中:

replace "-m elf_x86_64" by "-m64" on the line starting with VDSO_LDFLAGS_vdso.lds

replace "-m elf_x86" by "-m32" on the line starting with VDSO_LDFLAGS_vdso32.lds

問題2:error: duplicate member ‘page’

解決方案:

打開文件drivers/net/igbvf/igbvf.h,然后將129行的代碼注釋掉即可。

struct page *page                  //將此代碼刪除或注釋掉

**************************//

$ sudo make install     

$ sudo make modules  //編譯模塊

//*************可能出現的問題*************

問題:modpost: found 96 section mismatch(es).

       ‘make CONFIG_DEBUG_SECTION_MISMATCH=Y’

解決方案:

       sudo make CONFIG_DEBUG_SECTION_MISMATCH=y

**************************//

$ sudo make modules_install  //安裝模塊

 

6)最后創建initrd文件:

# mkinitramfs -o /boot/initrd.img-2.6.35

 

7)更新grub引導列表

$ sudo update-grub

$ sudo gedit /boot/grub/grub.cfg

將Code3拷貝至Code1和Code2之間,即將Ubuntu, with Linux 2.6.35啟動項拷貝至最前面,這樣在重啟時系統會自動選擇第一個作為默認啟動,於是就能進入內核為Linux 2.6.35的系統。

Code1

if [ "${linux_gfx_mode}" != "text" ]; then load_video; fi

Code2

menuentry 'Ubuntu, with Linux 3.8.0-29-generic' --class ubuntu --class gnu-linux --class gnu --class os {

    recordfail

    gfxmode $linux_gfx_mode

    insmod gzio

    insmod part_msdos

    insmod ext2

    set root='(hd0,msdos1)'

    search --no-floppy --fs-uuid --set=root a5208505-6372-4e32-b5f8-8b554b2a0b85

    linux    /boot/vmlinuz-3.8.0-29-generic root=UUID=a5208505-6372-4e32-b5f8-8b554b2a0b85 ro   quiet splash $vt_handoff

    initrd    /boot/initrd.img-3.8.0-29-generic

}

Code3:

menuentry 'Ubuntu, with Linux 2.6.35' --class ubuntu --class gnu-linux --class gnu --class os {

    recordfail

    gfxmode $linux_gfx_mode

    insmod gzio

    insmod part_msdos

    insmod ext2

    set root='(hd0,msdos1)'

    search --no-floppy --fs-uuid --set=root a5208505-6372-4e32-b5f8-8b554b2a0b85

    linux    /boot/vmlinuz-2.6.35 root=UUID=a5208505-6372-4e32-b5f8-8b554b2a0b85 ro quiet splash $vt_handoff

    initrd    /boot/initrd.img-2.6.35

}

 

可能出現的問題:

問題一:在重啟后可能會出現如下問題:

warning: can't open directory /lib/modules/2.6.34/modules.dep, no such files or directory

解決方案:

這時,可以先從舊內核中進入系統,然后執行以下命令:

$ su root         //獲得root權限

# cd /boot

# cp initrd.img-2.6.35 initrd-2.6.35.old              //備份原有文件

# depmod –a                                             //檢查所有模塊

# update-initramfs –k 2.6.35 –c

# cd /tmp

# gzip –dc /boot/initrd.img-2.6.35| cpio –id

# touch lib/modules/2.6.35/modules.dep

# find ./ | cpio –H newc –o > /boot/initrd.img-2.6.35.new

# gzip /boot/initrd.img-2.6.35.new

# cd /boot

# mv initrd.img-2.6.35.new.gz initrd.img-2.6.35

 

此部分的參考鏈接:

http://kpjack.blog.51cto.com/627289/318296/

內核替換更多介紹:

http://www.2cto.com/os/201312/265425.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM