目錄: 0、測試環境
1、獲得最新內核源代碼
2、編譯源代碼
3、運行新的內核
0、測試環境:
我的系統 : ubuntu 16.04 LTS (內核版本:4.4.0-36-generic )
下載源代碼內核版本 : Linux 4.8-rc6
測試時間 : 2016/9/16
1、獲得最新內核源代碼
獲取方法可以有以下兩種:
1.1 在linux 內核官方主頁:http://www.kernel.org,你永遠可以獲得 當前最新的linux內核源完整的tarball(一種用tar命令生成的 歸檔/壓縮 文件)以及不斷發布的 補丁(patch) .
1.2 直接從git上面獲取: https://github.com/torvalds/linux。具體是:Terminal 進入自己想要同步下來的目錄后。clone下來:
cd /同步下來/的/目錄 git clone https://github.com/torvalds/linux.git #這個應該有2G多
1.3 編譯准備
連同源代碼和編譯后的產生的文件,請准備好20G的硬盤空間!(從git上clone下來的源代碼 2.6 G; 經過make后另外生成的編譯文件 13.5G 這加起來有17G的空間)
/ 根目錄(具體來說是 /lib,沒掛載/lib的話就默認是使用/目錄) 要有至少4G的空余空間
/ boot 要有至少 400M 的空余空間
所以請在編譯前查看自己是否有對應充足的空間。(我就是不知道這一點重裝了兩次系統:一次是 /home 不足,一次是/boot不足)
2、編譯源代碼
編譯內核:(根據github README 的說明)
2.0、在編譯前仔細看README,有一些細節得注意例如說:
DOCUMENTATION:
這個說明項里面提到,可以參考的文檔網站:幫助文檔項目 還有git項目的目錄里document里有部分項目文檔的說明等。
SOFTWARE REQUIREMENTS
而這個提到要去看一下 項目目錄里的 “Documentation/Changes” 的軟件要求最低要求(不然后面遇到版本問題會很頭大),我使用的時ubuntu 16.04,里面提到的軟件版本都符合要求,就是有一些沒軟件我沒有,因為剛接觸還不確定需不需要所以沒有的我都自己下載了。
還有,在開始編譯前:要 Make sure you have no stale .o files and dependencies lying around:
cd linux #進入git clone 下來的linux 目錄(最頂目錄)
make mrproper
具體還是自己刻苦啃一下 README 比較好。
2.1、執行 make menuconfig
我決定自定義編譯的路徑:( 根據 “BUILD directory for the kernel”)
執行:
make O=/home/bensonlaur/build/kernel menuconfig
結果報錯:
/home/bensonlaur/gproject/linux/scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h: 沒有那個文件或目錄
解決:
#因為缺少包,安裝之,然后重新 make menuconfig sudo apt-get install libncurses5-dev
2.2、開始按上面的配置結果來 執行: make
執行:(由於github 項目里的README說,一旦自定義了build路徑,選擇了O選項,所有的make都得制定這個路徑)
make O=/home/bensonlaur/build/kernel
(注意:剛才執行 make O=/home/bensonlaur/build/kernel menuconfig 成功時,會顯示圖形界面給你配置,save 配置為 .config 。
我試過別的名字,這樣的話在make這一步會提示:
*** *** Configuration file ".config" not found! *** *** Please run some configurator (e.g. "make oldconfig" or *** "make menuconfig" or "make xconfig"). ***
,我也不知道改了配置名字后,去哪里制定我的別的名字的配置文件,就重新使用make O=/home/bensonlaur/build/kernel menuconfig生成 名為.config的配置文件,於是就沒報這個錯了 )
繼續make 時繼續報錯:
/home/bensonlaur/gproject/linux/scripts/sign-file.c:25:30: fatal error: openssl/opensslv.h: 沒有那個文件或目錄
解決:
#還是因為缺少包,安裝之,然后重新 執行make sudo apt-get install libssl-dev
解決缺少的文件問題后,接着就是漫長的編譯等待了
(時間需要很長,也消耗空間,第一次都沒底,可憐我12G的/home空間本來已經剩下9G,沒想到還爆滿,也不知道還會生成多少,為了分20G給/home,還重裝了一遍系統,還好這次夠用)。
此過程有很多warning,不知道是什么情況,我先記錄在這里:
...... /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘save_mc_for_early’: /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c:521:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=] } ^ /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘load_microcode.isra.3.constprop’: /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c:144:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=] } ^ /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘get_matching_model_microcode.isra.4.constprop’: /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c:357:1: warning: the frame size of 1080 bytes is larger than 1024 bytes [-Wframe-larger-than=] } ^ /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c: In function ‘save_microcode_in_initrd_intel’: /home/bensonlaur/gproject/linux/arch/x86/kernel/cpu/microcode/intel.c:681:1: warning: the frame size of 1032 bytes is larger than 1024 bytes [-Wframe-larger-than=] } ^ ...... 這個不是warning,也記錄下吧,(反正現在還在等着) CC [M] kernel/torture.o CC certs/system_keyring.o EXTRACT_CERTS Generating X.509 key generation config ### ### Now generating an X.509 key pair to be used for signing modules. ### ### If this takes a long time, you might wish to run rngd in the ### background to keep the supply of entropy topped up. It ### needs to be run as root, and uses a hardware random ### number generator if one is available. ### Generating a 4096 bit RSA private key ..........................................................................................++ .................++ unable to write 'random state' writing new private key to 'certs/signing_key.pem' ----- ### ### Key pair generated. ### EXTRACT_CERTS certs/signing_key.pem AS certs/system_certificates.o LD certs/built-in.o CC mm/filemap.o CC mm/mempool.o ...... CC [M] fs/jffs2/xattr.o /home/bensonlaur/gproject/linux/fs/jffs2/xattr.c: In function ‘jffs2_build_xattr_subsystem’: /home/bensonlaur/gproject/linux/fs/jffs2/xattr.c:887:1: warning: the frame size of 1128 bytes is larger than 1024 bytes [-Wframe-larger-than=] } ^ CC [M] fs/jffs2/xattr_trusted.o ...... (呀,等了那么久,不小心復制 ctrl+shift+c 按錯成 取消的ctrl+c,還好重新make好像可以從上次繼續,嚇死我了,以為又要等那么久,算了不貼了,warning應該都是類似的那個warning: the frame size of 1128 bytes is larger than 1024 bytes [-Wframe-larger-than=]) ...... ......
2.3、執行 :sudo make modules_install install
我前面指定了O選項,這里同樣指定執行:
sudo make O=/home/bensonlaur/build/kernel modules_install install
此過程會在 /lib 生成接近4G的所編譯內核的文件,在/boot生成400M的文件(包括initrd.img-4.8.0-rc6,/boot/grub/menu.lst 等)。
2.4 配置kernel
CONFIGURING the kernel:
在README 的“CONFIGURING the kernel”里面提到,配置是必要的,如果想要以最小的工作量把已有的自己系統的配置搬過來 ,執行make oldconfig:
sudo make O=/home/bensonlaur/build/kernel oldconfig
關於make oldconfig: 不必要的驅動會使內核變得臃腫,不同於386的處理器類型的設置會試內核無法運行在386上,建議不熟悉配置的使用make oldconfig。
3、運行新的內核
- Booting a kernel directly from a floppy without the assistance of a bootloader such as LILO, is no longer supported.
If you boot Linux from the hard drive, chances are you use LILO, which uses the kernel image as specified in the file /etc/lilo.conf. The kernel image file is usually /vmlinuz, /boot/vmlinuz, /bzImage or /boot/bzImage. To use the new kernel, save a copy of the old image and copy the new image over the old one. Then, you MUST RERUN LILO to update the loading map! If you don't, you won't be able to boot the new kernel image.
上面說現在啟動新的內核需要一個叫 LILO (linux loader)的軟件,下面安裝並讓其自動配置。
( 安裝之后執行 liloconfig會自動幫我們檢測並生成配置文件 /etc/lilo.conf 和/boot/map等, 這個文件里是具體的配置和說明)
bensonlaur@b-lenovo:~$ lilo 程序“lilo”尚未安裝。 您可以使用以下命令安裝: sudo apt install lilo bensonlaur@b-lenovo:~$ sudo apt install lilo 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關系樹 正在讀取狀態信息... 完成 下列【新】軟件包將被安裝: lilo 升級了 0 個軟件包,新安裝了 1 個軟件包,要卸載 0 個軟件包,有 0 個軟件包未被升級。 需要下載 252 kB 的歸檔。 解壓縮后會消耗 671 kB 的額外空間。 獲取:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 lilo amd64 1:24.2-1 [252 kB] 已下載 252 kB,耗時 1秒 (166 kB/s) 正在預設定軟件包 ... 正在選中未選擇的軟件包 lilo。 (正在讀取數據庫 ... 系統當前共安裝有 215673 個文件和目錄。) 正准備解包 .../lilo_1%3a24.2-1_amd64.deb ... 正在解包 lilo (1:24.2-1) ... 正在處理用於 man-db (2.7.5-1) 的觸發器 ... 正在設置 lilo (1:24.2-1) ... bensonlaur@b-lenovo:~$ sudo liloconfig 2 images '/boot/vmlinuz*' found. New file created as: /etc/lilo.conf Now you must execute '/sbin/lilo' to activate this new configuation! bensonlaur@b-lenovo:~$ sudo /sbin/lilo Added Linux + * Added Linux_Old + bensonlaur@b-lenovo:~$
配置完之后從啟便可進入我們自己編譯的內核了。
重啟前查看下自己的當前內核版本:
uname -r
重啟后菜單里有兩個選項:linux linux_old (T_T我的windows不見了,算了后面再解決)(解決辦法:linux——啟動引導程序 LILO 與 grub 中的第5點)
選擇第一個【linux】,等待一定時間就啟動了,所有一切看上去好像沒什么變化,再執行一遍:
uname -r
如果看到的版本是最新的你編譯的版本,那么恭喜,你正在體驗的就是世界上最新鮮的linux內核。
那么,接下來想辦法去玩一下這個內核吧。:)
獲得幫助
訂閱Linux內核郵件列表 :http://www.wowotech.net/linux_application/lkml.html
工具介紹:
Oprofile 工具:一個功能強大的性能分析工具,在這里 被推薦下載,下載地址:在這里 (好像直接系統下載跟方便:
sudo apt install oprofile
)
Oprofile的安裝和使用:
安裝說明:這里
安裝時缺少2個庫:
configure: error: popt library not found 相應的安裝包:sudo apt install popt-devel configure: error: liberty library not found 相應的安裝包:sudo apt install libiberty-dev
測試時間:2016/9/16
