Linux核心編譯詳細教程,linux核心編譯

來源:互聯網
上載者:User

Linux核心編譯詳細教程,linux核心編譯

嘗試編譯下Linux-kernel 4.14.14,使用Ubuntu 16.04 64位 系統。

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' failedmake[1]: *** [scripts/kconfig/dochecklxdialog] Error 1Makefile:543: recipe for target 'menuconfig' failedmake: *** [menuconfig] Error 2

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

# 提示找不到ncurses-devel包# sudo apt-get install ncurses-develsudo 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/mconfscripts/kconfig/mconf  Kconfig

配置完結果

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.14update-grub2

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.