linux-手动下载和安装内核
1、CentOS7安装高版本内核
1.1 下载内核
手动下载和安装内核是一个高级操作,需要从官方源或其他可信源手动下载和安装内核。
(1)选择合适的内核版本,可以访问官方操作系统网站或内核开发者网站,以获取可用的内核版本信息。
(2)下载内核源代码: 一旦确定了要安装的内核版本,可以通过以下方式之一获取内核源代码:
官方操作系统网站提供的下载链接。
内核开发者网站的代码仓库或下载链接。
wget https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.x.x.tar.gz
1.2 解压源代码
下载完成后,使用以下命令解压源代码压缩包:
tar -xzvf linux-5.x.x.tar.gz
1.3 配置内核选项
进入解压后的内核源代码目录,并使用现有的内核配置文件作为基础配置。可以复制系统中 /boot/config-$(uname -r) 文件到内核源代码目录,并命名为 .config(可选)
cp /boot/config-$(uname -r) /path/to/linux-5.x.x/.config
然后,运行以下命令以进行配置:在配置界面中可以根据需要修改内核选项;保存配置后退出。
make menuconfig
报错1:
[root@localhost linux-5.15.14]# make menuconfig
HOSTCC scripts/basic/fixdep
/bin/sh: gcc: command not found
make[2]: *** [scripts/basic/fixdep] Error 127
make[1]: *** [scripts_basic] Error 2
make: *** [__sub-make] Error 2
解决办法:安装gcc
[root@localhost linux-5.15.14]# yum -y install gcc
报错2:
[root@localhost linux-5.15.14]# make menuconfig
HOSTCC scripts/basic/fixdep
*
* Unable to find the ncurses package.
* Install ncurses (ncurses-devel or libncurses-dev
* depending on your distribution).
*
* You may also need to install pkg-config to find the
* ncurses installed in a non-default location.
*
make[2]: *** [scripts/kconfig/mconf-cfg] Error 1
make[1]: *** [menuconfig] Error 2
make: *** [__sub-make] Error 2
解决办法:安装ncurses-devel
[root@localhost linux-5.15.14]# yum -y install ncurses-devel
报错3:
[root@localhost linux-5.15.14]# make menuconfig
UPD scripts/kconfig/mconf-cfg
HOSTCC scripts/kconfig/mconf.o
HOSTCC scripts/kconfig/lxdialog/checklist.o
HOSTCC scripts/kconfig/lxdialog/inputbox.o
HOSTCC scripts/kconfig/lxdialog/menubox.o
HOSTCC scripts/kconfig/lxdialog/textbox.o
HOSTCC scripts/kconfig/lxdialog/util.o
HOSTCC scripts/kconfig/lxdialog/yesno.o
HOSTCC scripts/kconfig/confdata.o
HOSTCC scripts/kconfig/expr.o
LEX scripts/kconfig/lexer.lex.c
/bin/sh: flex: command not found
make[2]: *** [scripts/kconfig/lexer.lex.c] Error 127
make[1]: *** [menuconfig] Error 2
make: *** [__sub-make] Error 2
解决办法:安装 flex
[root@localhost linux-5.15.14]# yum -y install flex
报错4:
[root@localhost linux-5.15.14]# make menuconfig
LEX scripts/kconfig/lexer.lex.c
YACC scripts/kconfig/parser.tab.[ch]
/bin/sh: bison: command not found
make[2]: *** [scripts/kconfig/parser.tab.h] Error 127
make[1]: *** [menuconfig] Error 2
make: *** [__sub-make] Error 2
解决办法:安装 bison
[root@localhost linux-5.15.14]# yum -y install bison
报错5:
[root@localhost linux-5.15.14]# make menuconfig
YACC scripts/kconfig/parser.tab.[ch]
HOSTCC scripts/kconfig/lexer.lex.o
HOSTCC scripts/kconfig/menu.o
HOSTCC scripts/kconfig/parser.tab.o
HOSTCC scripts/kconfig/preprocess.o
HOSTCC scripts/kconfig/symbol.o
HOSTCC scripts/kconfig/util.o
HOSTLD scripts/kconfig/mconf
***
*** Compiler is too old.
*** Your GCC version: 4.8.5
*** Minimum GCC version: 5.1.0
***
scripts/Kconfig.include:44: Sorry, this compiler is not supported.
make[2]: *** [menuconfig] Error 1
make[1]: *** [menuconfig] Error 2
make: *** [__sub-make] Error 2
解决办法:安装更高版本GCC
[root@localhost ~]#wget http://buildlogs-seed.centos.org/c7-devtoolset-10.x86_64/cbs/devtoolset-10-runtime-10.0-0.el7.x86_64.rpm --no-check-certificate[root@localhost ~]#yum install devtoolset-10-runtime-10.0-0.el7.x86_64.rpm -y[root@localhost ~]#wget http://buildlogs-seed.centos.org/c7-devtoolset-10.x86_64/cbs/devtoolset-10-binutils-2.35-5.el7.2.x86_64.rpm --no-check-certificate[root@localhost ~]#yum install devtoolset-10-binutils-2.35-5.el7.2.x86_64.rpm -y[root@localhost ~]#wget http://buildlogs-seed.centos.org/c7-devtoolset-10.x86_64/cbs/devtoolset-10-gcc-10.2.1-11.1.el7.x86_64.rpm --no-check-certificate[root@localhost ~]#yum install devtoolset-10-gcc-10.2.1-11.1.el7.x86_64.rpm -y[root@localhost ~]#wget http://buildlogs-seed.centos.org/c7-devtoolset-10.x86_64/cbs/devtoolset-10-libstdc++-devel-10.2.1-11.1.el7.x86_64.rpm --no-check-certificate[root@localhost ~]#yum install devtoolset-10-libstdc++-devel-10.2.1-11.1.el7.x86_64.rpm -y[root@localhost ~]#wget http://buildlogs-seed.centos.org/c7-devtoolset-10.x86_64/cbs/devtoolset-10-gcc-c++-10.2.1-11.1.el7.x86_64.rpm --no-check-certificate[root@localhost ~]#yum install devtoolset-10-gcc-c++-10.2.1-11.1.el7.x86_64.rpm -y[root@localhost localhost-6.0.16]#scl enable devtoolset-10 bash
1.4 编译内核
make -j 8
报错1:
scripts/sign-file.c:25:10: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [scripts/sign-file] Error 1
make[2]: *** Waiting for unfinished jobs....
HOSTCC scripts/genksyms/parse.tab.o
HOSTCC scripts/genksyms/lex.lex.o
DESCEND objtool
HOSTLD scripts/genksyms/genksyms
make[1]: *** [scripts] Error 2
make[1]: *** Waiting for unfinished jobs....<stdin>:1:10: fatal error: libelf.h: No such file or directory
解决办法:
yum install elfutils-libelf-devel openssl-devel -y
1.5 安装内核模块
编译完成后,可以安装内核及其模块:
make modules_install
报错1:
arch/x86/Makefile:142: CONFIG_X86_X32 enabled but no binutils support
sed: can't read modules.order: No such file or directory
make: *** [Makefile:1479: __modinst_pre] Error 2
解决方案:
这个报错原因是 `CONFIG_X86_X32 enabled but no binutils support`,选择重新编译binutils或者禁用CONFIG_X86_X32,我选择禁用,编辑.config文件,将CONFIG_X86_X32=y改为CONFIG_X86_X32=n。重新运行`make -j4`,不再报此处错误。
报错2:
make[1]: *** No rule to make target 'debian/canonical-certs.pem', needed by 'certs/x509_certificate_list'. Stop.
解决方案:
编辑.config文件,修改CONFIG_SYSTEM_TRUSTED_KEYS
修改CONFIG_SYSTEM_TRUSTED_KEYS,将其赋空值。
修改前:原变量有值
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
修改后:将该变量赋空值,将该项原有内容删掉即可,如下:
CONFIG_SYSTEM_TRUSTED_KEYS=""
修改CONFIG_SYSTEM_REVOCATION_KEYS(可选),如果CONFIG_SYSTEM_REVOCATION_KEYS的值不为空的话,也将其赋空值。
修改前:原变量有值
CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
修改后:将该变量赋空值
CONFIG_SYSTEM_REVOCATION_KEYS=""
1.6 安装内核
make -j 8install
1.7 重启系统:选择新的内核启动
reboot
1.8 验证新内核
系统重启后,运行以下命令验证新内核是否生效:
uname -r
ed-certs.pem"
修改后:将该变量赋空值
CONFIG_SYSTEM_REVOCATION_KEYS=“”
#### 1.6 安装内核
```shell
make -j 8 install
1.7 重启系统:选择新的内核启动
reboot
1.8 验证新内核
系统重启后,运行以下命令验证新内核是否生效:
uname -r
版权归原作者 zzk899 所有, 如有侵权,请联系我们删除。