Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Ubuntu 編譯核心全流程:從換源到 update-grub2,含常見錯誤排除

1. 修改 Ubuntu 的更新源

sudo gedit /etc/apt/sources.list

2. 編譯核心

(1)切到 /usr/src/,解壓下載好的核心原始碼。

(2)清理殘留產物(首次編譯可略):

make mrproper

(3)進入設定選單:

make menuconfig

若跳錯誤,通常是缺 ncurses 開發套件:

sudo apt-get install libncurses5-dev
sudo apt-cache search <檔名>

我當時遇到相依性衝突:

The following packages have unmet dependencies:
libncurses5-dev : Depends: libncurses5 (= 5.9-4) but 5.9-10ubuntu1 is to be installed
Depends: libtinfo-dev (= 5.9-4) but it is not going to be installed
Depends: ncurses-bin (= 5.9-4) but 5.9-10ubuntu1 is to be installed

解法是到 packages.ubuntu.com 直接下載 libncurses5、libtinfo-dev 與 ncurses-bin 的 5.9-4 版本,再用 dpkg 手動安裝。

(4)編譯核心映像(-j 後接 CPU 數):

make bzImage -jn

(5)編譯模組:

make modules

(6)安裝模組:

make modules_install

(7)安裝核心:

make install

3. 製作 initrd 並更新 GRUB2

sudo mkinitramfs 3.19.3 -o /boot/initrd.img-3.19.3
sudo update-grub2

4. 編譯 2.6.38 核心的錯誤排除

遇到這則組語錯誤:

arch/x86/kernel/entry_32.S: Assembler messages:
arch/x86/kernel/entry_32.S:1422: Error: .size expression for apf_page_fault does not evaluate to a constant
make[2]: *** [arch/x86/kernel/entry_32.o] Error 1
make[1]: *** [arch/x86/kernel] Error 2
make: *** [arch/x86] Error 2

原因是 .size 使用的符號名稱與 ENTRY 標籤不一致,把兩處 END 的參數改成對應的標籤即可:

--- entry_32.S.original
+++ entry_32.S
@@ -343,7 +343,7 @@
     # int/exception return?
     jne work_pending
     jmp restore_all
-END(ret_from_exception)
+END(resume_userspace)
 
 #ifdef CONFIG_PREEMPT
 ENTRY(resume_kernel)
@@ -1413,7 +1413,7 @@
     CFI_ADJUST_CFA_OFFSET 4
     jmp error_code
     CFI_ENDPROC
-END(apf_page_fault)
+END(async_page_fault)
 
 #endif

這個問題源自核心版本與編譯工具鏈(新版 binutils 對 .size 表達式的檢查更嚴格)不相容,新版核心已修正,若只是要快速通過,改這兩行是最省事的作法。

Copyright © Linux教程網 All Rights Reserved