CentOS 7 下编译安装 4.14 内核

简介: CentOS 7 下编译安装 4.14 内核

rpm升级

# rpm的方式升级内核
1.载入内核公钥
[root@localhost ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
2.安装内核 ELRepo
[root@localhost ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
3.载入elrepo-kernel元数据
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel repolist
4.查看可用的rpm包
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel list kernel*  # 产品需求是4.14的内核,这里没有,只好去官方找安装包,进行编译升级
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirrors.neusoft.edu.cn
Installed Packages
kernel.x86_64                                     3.10.0-957.el7                        @anaconda
kernel-tools.x86_64                               3.10.0-957.el7                        @anaconda
kernel-tools-libs.x86_64                          3.10.0-957.el7                        @anaconda
Available Packages
kernel-lt.x86_64                                  4.4.235-1.el7.elrepo                  elrepo-kernel
kernel-lt-devel.x86_64                            4.4.235-1.el7.elrepo                  elrepo-kernel
kernel-lt-doc.noarch                              4.4.235-1.el7.elrepo                  elrepo-kernel
kernel-lt-headers.x86_64                          4.4.235-1.el7.elrepo                  elrepo-kernel
kernel-lt-tools.x86_64                            4.4.235-1.el7.elrepo                  elrepo-kernel
kernel-lt-tools-libs.x86_64                       4.4.235-1.el7.elrepo                  elrepo-kernel
kernel-lt-tools-libs-devel.x86_64                 4.4.235-1.el7.elrepo                  elrepo-kernel
kernel-ml.x86_64                                  5.8.7-1.el7.elrepo                    elrepo-kernel
kernel-ml-devel.x86_64                            5.8.7-1.el7.elrepo                    elrepo-kernel
kernel-ml-doc.noarch                              5.8.7-1.el7.elrepo                    elrepo-kernel
kernel-ml-headers.x86_64                          5.8.7-1.el7.elrepo                    elrepo-kernel
kernel-ml-tools.x86_64                            5.8.7-1.el7.elrepo                    elrepo-kernel
kernel-ml-tools-libs.x86_64                       5.8.7-1.el7.elrepo                    elrepo-kernel
kernel-ml-tools-libs-devel.x86_64                 5.8.7-1.el7.elrepo                    elrepo-kernel
# lt:long term support,长期支持版本;
# ml:mainline,主线版本;
5.安装最新版本的kernel
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel -y install kernel-ml.x86_64
6.删除旧版本工具包
[root@localhost ~]# yum -y remove kernel-tools-libs.x86_64 kernel-tools.x86_64
7.安装新版本工具包
[root@localhost ~]# yum --disablerepo=\* --enablerepo=elrepo-kernel -y install kernel-ml-tools.x86_64

编译升级

升级前

[root@localhost ~]# uname -r
3.10.0-957.el7.x86_64
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

下载安装包

linux内核官网:https://www.kernel.org/
[root@localhost ~]# wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.196.tar.xz
链接:https://pan.baidu.com/s/1QSc_PeVsj6olE6vIrRScYQ  提取码:w1g2  # 有百度会员的,可以用网盘下载,没有的话,只能wget了,官方的服务器下载会比较慢,文件不大,只有97MB不到

编译内核

选择配置项的方式有以下几种,选择哪种都可以。
make config (基于文本的配置界面)
make menuconfig (基于文本菜单的配置界面)
make xconfig (基于图形窗口的配置界面)
make oldconfig (基于原来内核配置的基础上修改)
以上几种:
# make xconfig 最为友好,基于窗口操作,但是需要 Xwindow 的支持,CentOS 还好,若是使用其它没有图形界面的发行版就 GG 了。
# make menuconfig 相对比较友好,又是基于文本菜单,所有的发行版都可以使用,所以这里推荐使用 make menuconfig。

使用 make menuconfig 需要 ncurses-devel 的支持,如果之前没装过,需要执行下面的命令安装一下。
[root@localhost ~]# yum -y install ncurses-devel
[root@localhost ~]# tar xf linux-4.14.196.tar.xz -C /usr/local/
[root@localhost linux-4.14.196]# yum -y install gcc make elfutils-libelf-devel openssl-devel bc  # 安装编译内核所需的依赖
[root@localhost ~]# cd /usr/local/linux-4.14.196/
[root@localhost linux-4.14.196]# make menuconfig
# 执行成功后,会显示下面的界面

在这里插入图片描述

Linux 内核所有的配置项都在这里,内核的编译分为两个部分,核心和模块,对于核心的部分,要编译进核心,可能以后会用到的部分,尽量编译成模块。
文本菜单选择界面,使用左(←)、右(→)箭头切换底部菜单,上(↑)、下(↓)箭头切换中间的配置项,空格键 选择配置项,部分配置项右边有 —> 标识,代表有下级子项,可以使用 Enter 进去选择。
同时每一项的前面都有以下标识,可以根据需要选择。
- <*>[*]  表示编译进核心
- <M>     表示编译成模块
- 空格    表示不选中此项
如果你只是看一下整个编译过程,不想深究每一项,执行上一步 make menuconfig 之后,直接保存退出就可以了,它会使用 CentOS 内部的配置文件作为这次编译的配置文件
# 配置项选完,config 配置文件生成之后,就可以开始编译了
# 编译时间比较长,如果上面你是自定义配置项,把不需要的配置都关闭,编译会快的多。我这使用的 CentOS 内部的配置文件,CentOS 为了大多数人的使用,开的配置项比较多,所以编译的时间比较长,也和你的电脑配置有关。我make了两个小时。
[root@localhost linux-4.14.196]# make
[root@localhost linux-4.14.196]# make modules_install   # 安装模块
[root@localhost linux-4.14.196]# make install           # 安装核心
[root@localhost linux-4.14.196]# ll /boot/   # 安装完成后,就可以看到4.14的内核文件了
total 201364
-rw-r--r--. 1 root root   151918 Nov  9  2018 config-3.10.0-957.el7.x86_64
drwxr-xr-x. 3 root root       17 Jun 30 18:04 efi
drwxr-xr-x. 2 root root     4096 Sep  9 14:06 extlinux
drwxr-xr-x. 2 root root       27 Jun 30 18:05 grub
drwx------. 5 root root       97 Sep  9 19:07 grub2
-rw-------. 1 root root 57430086 Jun 30 18:08 initramfs-0-rescue-502ad5c8bfc847fea2cacceff257adae.img
-rw-------. 1 root root 22417877 Jun 30 18:09 initramfs-3.10.0-957.el7.x86_64.img
-rw-------. 1 root root 98006427 Sep  9 19:07 initramfs-4.14.196.img
-rw-r--r--. 1 root root   314036 Nov  9  2018 symvers-3.10.0-957.el7.x86_64.gz
lrwxrwxrwx. 1 root root       25 Sep  9 19:04 System.map -> /boot/System.map-4.14.196
-rw-------. 1 root root  3543471 Nov  9  2018 System.map-3.10.0-957.el7.x86_64
-rw-r--r--. 1 root root  3498834 Sep  9 19:04 System.map-4.14.196
lrwxrwxrwx. 1 root root       22 Sep  9 19:04 vmlinuz -> /boot/vmlinuz-4.14.196
-rwxr-xr-x. 1 root root  6639904 Jun 30 18:08 vmlinuz-0-rescue-502ad5c8bfc847fea2cacceff257adae
-rwxr-xr-x. 1 root root  6639904 Nov  9  2018 vmlinuz-3.10.0-957.el7.x86_64
-rw-r--r--. 1 root root  7517472 Sep  9 19:04 vmlinuz-4.14.196

更新启动引导

[root@localhost linux-4.14.196]# awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg     # 查看内核插入顺序,默认新内核是从头插入
0 : CentOS Linux (4.14.196) 7 (Core)
1 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-502ad5c8bfc847fea2cacceff257adae) 7 (Core)
[root@localhost linux-4.14.196]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.14.196
Found initrd image: /boot/initramfs-4.14.196.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-502ad5c8bfc847fea2cacceff257adae
Found initrd image: /boot/initramfs-0-rescue-502ad5c8bfc847fea2cacceff257adae.img
done

修改默认启动内核

[root@localhost ~]# grub2-editenv list    # 查看默认启动的内核
saved_entry=CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
[root@localhost ~]# awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg    # 查看内核插入顺序
0 : CentOS Linux (4.14.196) 7 (Core)
1 : CentOS Linux (3.10.0-957.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-502ad5c8bfc847fea2cacceff257adae) 7 (Core)
[root@localhost ~]# grub2-set-default 'CentOS Linux (4.14.196) 7 (Core)'     # 设置默认启动的内核
[root@localhost ~]# grub2-editenv list    # 查看默认启动的内核
saved_entry=CentOS Linux (4.14.196) 7 (Core)

重启之后验证

[root@localhost ~]# reboot 
[root@localhost ~]# uname -r 
4.14.196
目录
相关文章
|
1月前
|
Linux 开发工具 C语言
Centos8下编译安装最新版ffmpeg解决方案(含Centos8换源阿里云)
Centos8下编译安装最新版ffmpeg解决方案(含Centos8换源阿里云)
153 3
|
1月前
|
Kubernetes 监控 Linux
容器服务ACK常见问题之新增一台CentOS 5.4内核的节点失败如何解决
容器服务ACK(阿里云容器服务 Kubernetes 版)是阿里云提供的一种托管式Kubernetes服务,帮助用户轻松使用Kubernetes进行应用部署、管理和扩展。本汇总收集了容器服务ACK使用中的常见问题及答案,包括集群管理、应用部署、服务访问、网络配置、存储使用、安全保障等方面,旨在帮助用户快速解决使用过程中遇到的难题,提升容器管理和运维效率。
|
7月前
|
关系型数据库 MySQL Linux
百度搜索:蓝易云【Centos8 stream系统编译安装PHP教程。】
以上是在CentOS 8 Stream系统上编译安装PHP的基本教程。请注意,具体的配置和参数可能因您的需求而有所不同,您可以根据自己的情况进行调整。同时,请确保在执行任何操作之前备份重要的文件和配置。
224 0
|
3月前
|
Linux C语言
centos 7 下使用高版本gcc编译安装
centos 7 下使用高版本gcc编译安装
117 0
|
4月前
|
Linux Python
百度搜索:蓝易云【CentOS 7.8编译安装python 3.7教程。】
请注意,编译安装Python可能需要一些时间,并需要较高的系统性能和网络连接。在安装过程中,请确保按照提示和错误信息进行相应的操作和解决方案。
84 1
|
4月前
|
SQL 关系型数据库 MySQL
centos编译安装mariadb
一般我不太愿意用mysql,那个玩意,有的时候不太友好。 我还是比较喜欢mariadb。
132 0
|
4月前
|
关系型数据库 MySQL Shell
centos编译安装mysql
centos编译安装mysql
137 0
|
4月前
|
应用服务中间件 Linux Shell
centos编译安装nginx(2)
安装成功之后,nginx的配置文件,在安装目录(/usr/local/nginx)下的conf目录下的nginx.conf中。 Php-fpm在安装的时候已经配置过了,这里不再赘述
56 0
centos编译安装nginx(2)
|
4月前
|
应用服务中间件 Shell Linux
centos编译安装nginx(1)
进入解压后的目录,编译
108 0
|
4月前
|
小程序 JavaScript Shell
centos编译安装PHP(2)
Php编译安装成功之后,是没有php.ini文件的,需要我们从源码包中复制过去。
47 1