Linux內核編譯

嘗試編譯下Linux-kernel 4.14.14,使用Ubuntu 16.04 64位 系統。
Linux內核官網: https://www.kernel.org/
內核下載鏈接: https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.14.tar.xz

Linux-kernel官網

kernel-4.14.14 內核文件約96MB,解壓後得到linux-4.14.14目錄約900MB。在終端中切換到解壓後的linux-4.14.14文件目錄,執行下面的命令:

1. .config

複製一份當前系統編譯時的配置,在/usr/src目錄下

$ ls /usr/src/
linux-headers-4.10.0-35          linux-headers-4.8.0-36          
linux-headers-4.10.0-35-generic  linux-headers-4.8.0-36-generic

其中,在 linux-headers-*-generic目錄下存在 .config文件,複製一份到linux-4.14.14目錄下

linux-4.14.14$ cp /usr/src/linux-headers-4.10.0-35-generic/.config .

2. 編譯配置

可能出現的問題

$ make menuconfig 
 *** Unable to find the ncurses libraries or the
 *** required header files.
 *** 'make menuconfig' requires the ncurses libraries.
 *** 
 *** Install ncurses (ncurses-devel) and try again.
 *** 
scripts/kconfig/Makefile:202: recipe for target 'scripts/kconfig/dochecklxdialog' failed
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
Makefile:543: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2

編譯出了問題,提示缺少ncurses相關的庫,安裝就好

# 提示找不到ncurses-devel包
# sudo apt-get install ncurses-devel

sudo apt-get install libncurses5-dev

安裝好之後,重新執行,選擇[load]–>[OK]–>[Save]–>[OK]–>[EXIT]–>[EXIT]

$ make menuconfig    
  HOSTCC  scripts/kconfig/mconf.o
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
  HOSTCC  scripts/kconfig/lxdialog/util.o
  HOSTCC  scripts/kconfig/lxdialog/inputbox.o
  HOSTCC  scripts/kconfig/lxdialog/textbox.o
  HOSTCC  scripts/kconfig/lxdialog/yesno.o
  HOSTCC  scripts/kconfig/lxdialog/menubox.o
  HOSTLD  scripts/kconfig/mconf
scripts/kconfig/mconf  Kconfig

配置完結果

make-menuconfig

3. 編譯內核

編譯啓動映像

編譯的過程比較耗時,-jN部分, N越大,編譯速度越快,當然,不要超過自己機器的上限。設置爲256,整個內核編譯只需要花費大概10min左右。

make bzImage -j256

可能遇到的2個問題:

Makefile:942: *** "Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel".  Stop.

缺少相應的庫,安裝即可:sudo apt-get install libelf-dev

fatal error: openssl/opensslv.h: No such file or directory 

沒有安裝openssl的,需要先安裝openssl: sudo apt-get install libssl-dev

編譯模塊

直接執行 make modules -j256


4. 安裝內核

安裝內核的過程就快的很多了,這和一般的軟件安裝包的安裝軟件 是相似的。

先安裝模塊

root # make modules_install

再安裝內核

root # make install

完成安裝之後,會在/boot內生成對應的內核相關文件,重啓之後,在啓動引導頁面,會讓我們選擇啓動的內核,這時我們可以選擇是當前默認的4.10內核還是剛剛編譯安裝的更新的4.14內核。


5. 更改啓動grub

grub就是管理Ubuntu系統啓動的一個程序,我們編譯好的內核要設置爲缺省運行項,修改對應的grub,其實也很簡單。
查看當前:

$ cat /proc/version  
Linux version 4.10.0-35-generic (buildd@lcy01-33) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017

$cat /boot/grub/grub.cfg | grep 4.10
....

[未實操]

mkinitramfs 4.14.14 -o /boot/initrd.img-4.14.14
update-grub2

update-grub2命令會幫我們自動修改grub

參考:
[*]http://www.linuxidc.com/Linux/2016-04/129955.htm
[*]http://blog.51cto.com/191226139/2059117
[*]http://blog.csdn.net/u010889616/article/details/47868887

http://blog.csdn.net/qq_33044095/article/details/52645387
http://blog.csdn.net/crazycoder8848/article/details/44131735
http://blog.csdn.net/qq_34247099/article/details/50949720

編譯問題:
http://blog.csdn.net/chenbang110/article/details/7794989
http://blog.csdn.net/nefuyang/article/details/8735133
http://blog.csdn.net/xxxxxx91116/article/details/7927520

http://blog.csdn.net/david_xtd/article/details/18888409
http://blog.csdn.net/loongembedded/article/details/52382667

發佈了53 篇原創文章 · 獲贊 88 · 訪問量 33萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章