CentOS 7.3 手動編譯安裝最新版本Linux Kernel

本文演示機器系統版本是CENTOS7.3。 查看系統版本信息。linux

[root@localhost ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.3.1611 (Core)
Release:        7.3.1611
Codename:       Core
[root@localhost ~]#
[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
[root@localhost ~]# cat /proc/version
Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
[root@localhost ~]#

安裝編譯所需軟件。ubuntu

#逐條運行命令
[root@localhost ~]# yum groupinstall "Development Tools"
[root@localhost ~]# yum install ncurses-devel
[root@localhost ~]# yum install qt-devel

下載最新穩定版本Linux Kernel。本文發表時(2017-03-29)最新穩定內核版本是4.10.6。centos

[root@localhost ~]# wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.10.6.tar.xz
[root@localhost ~]# tar -xf linux-4.10.6.tar.xz -C /usr/src/
[root@localhost ~]# ls /usr/src/
debug  kernels  linux-4.10.6
[root@localhost ~]# cd /usr/src/linux-4.10.6/

開始配置和編譯內核。[截圖示例以下圖,代碼如圖下所示] 編譯界面dom

[root@localhost linux-4.10.6]# make menuconfig
scripts/kconfig/mconf  Kconfig
#
# using defaults found in /boot/config-3.10.0-514.el7.x86_64
#
/boot/config-3.10.0-514.el7.x86_64:621:warning: symbol value 'm' invalid for CPU_FREQ_STAT
/boot/config-3.10.0-514.el7.x86_64:861:warning: symbol value 'm' invalid for NF_CT_PROTO_DCCP
/boot/config-3.10.0-514.el7.x86_64:863:warning: symbol value 'm' invalid for NF_CT_PROTO_SCTP
/boot/config-3.10.0-514.el7.x86_64:864:warning: symbol value 'm' invalid for NF_CT_PROTO_UDPLITE
/boot/config-3.10.0-514.el7.x86_64:882:warning: symbol value 'm' invalid for NF_NAT_PROTO_DCCP
/boot/config-3.10.0-514.el7.x86_64:883:warning: symbol value 'm' invalid for NF_NAT_PROTO_UDPLITE
/boot/config-3.10.0-514.el7.x86_64:884:warning: symbol value 'm' invalid for NF_NAT_PROTO_SCTP
configuration written to .config

*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.
#編譯用時與機器配置,選擇選項等有關,大約須要十幾分鍾以上
[root@localhost linux-4.10.6]# make
[root@localhost linux-4.10.6]# make modules_install
[root@localhost linux-4.10.6]# make install
[root@localhost linux-4.10.6]# make clean
#更新內核啓動參數
[root@localhost linux-4.10.6]# grub2-set-default 0

重啓電腦並檢查是否安裝成功。ui

[root@localhost ~]# uname -a
Linux localhost.localdomain 4.10.6 #1 SMP Wed Mar 29 13:47:22 CST 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.3.1611 (Core)
Release:        7.3.1611
Codename:       Core
[root@localhost ~]#

補充Ubuntu安裝最新穩定版內核。es5

#須要root權限
dell@DELL:/usr/src/linux-4.10.10$ sudo make menuconfig
  HOSTCC  scripts/kconfig/mconf.o
In file included from scripts/kconfig/mconf.c:23:0:
scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h: 沒有那個文件或目錄
compilation terminated.
scripts/Makefile.host:124: recipe for target 'scripts/kconfig/mconf.o' failed
make[1]: *** [scripts/kconfig/mconf.o] Error 1
Makefile:546: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2
dell@DELL:/usr/src/linux-4.10.10$
dell@DELL:/usr/src/linux-4.10.10$ sudo

該錯誤是由於make menuconfig須要安裝libncurses5-dev。debug

dell@DELL:/usr/src/linux-4.10.10$ sudo apt install libncurses5-dev

開始執行make menuconfig 命令。code

dell@DELL:/usr/src/linux-4.10.10$ sudo make menuconfig

執行make命令。編譯過程報錯。cdn

scripts/sign-file.c:25:30: fatal error: openssl/opensslv.h: 沒有那個文件或目錄
compilation terminated.
scripts/Makefile.host:107: recipe for target 'scripts/sign-file' failed
make[1]: *** [scripts/sign-file] Error 1
Makefile:560: recipe for target 'scripts' failed
make: *** [scripts] Error 2
dell@DELL:/usr/src/linux-4.10.10$

解決該方法是安裝libssl-dev。ip

#解決方法
dell@DELL:/usr/src/linux-4.10.10$ sudo apt install libssl-dev

其餘狀況和CentOS安裝相似,本文再也不加以詳細講解。

須要補充一點。

dell@DELL:/usr/src/linux-4.10.10$ sudo grub-set-default 0
dell@DELL:/usr/src/linux-4.10.10$ cat /proc/version
Linux version 4.4.0-72-generic (buildd@lcy01-17) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017
dell@DELL:/usr/src/linux-4.10.10$ sudo reboot

安裝完成後檢查版本。

dell@DELL:~$ uname -a
Linux DELL 4.10.10 #1 SMP Thu Apr 13 15:54:58 CST 2017 x86_64 x86_64 x86_64 GNU/Linux
dell@DELL:~$ cat /proc/version
Linux version 4.10.10 (root@DELL) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #1 SMP Thu Apr 13 15:54:58 CST 2017
dell@DELL:~$
相關文章
相關標籤/搜索