前言
环境:centos 7.6 、默认官方yum源
在centos7.6安装完成之后,想要使用yum update命令来升级全部的包,但是不想更新内核,也不升级内核,本篇记录下避免踩坑。
yum update 不更新内核、不升级操作系统版本
这里在安装完成centos7.6之后先创建一个快照。
[root@localhost ~]# cat /etc/redhat-release #查看操作系统版本
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# uname -r #查看内核版本
3.10.0-957.el7.x86_64
[root@localhost ~]# yum --exclude=kernel* --exclude=centos-release* update #升级软件包,不升级内核相关的包以及操作系统版本
#从输出来看,没有相关kernel开头的包要升级安装,也没有centos-release开头的包要升级安装
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.ustc.edu.cn
...................................................
Dependencies Resolved
=======================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================
Installing:
iwl7260-firmware noarch 25.30.13.0-80.el7_9 updates 6.1 M
Updating:
GeoIP x86_64 1.5.0-14.el7 base 1.5 M
NetworkManager x86_64 1:1.18.8-2.el7_9 updates 1.9 M
NetworkManager-libnm x86_64 1:1.18.8-2.el7_9 updates 1.7 M
NetworkManager-team x86_64 1:1.18.8-2.el7_9 updates 165 k
................................
#升级完成,重启
[root@localhost ~]# init 6
#查看内核版本以及操作操作系统版本
[root@localhost ~]# cat /etc/redhat-release #还是centos7.6
CentOS Linux release 7.6.1810 (Core)
[root@localhost ~]# uname -r #内核版本也没有变
3.10.0-957.el7.x86_64
yum update 更新内核、升级系统版本
#恢复快照
[root@localhost ~]# yum update #查看下面的输出
.......................
=======================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================
Installing:
iwl7260-firmware noarch 25.30.13.0-80.el7_9 updates 6.1 M
replacing iwl7265-firmware.noarch 22.0.7.0-69.el7
kernel x86_64 3.10.0-1160.90.1.el7 updates 52 M
Updating:
centos-release x86_64 7-9.2009.1.el7.centos updates 27 k
kernel-tools x86_64 3.10.0-1160.90.1.el7 updates 8.2 M
kernel-tools-libs x86_64 3.10.0-1160.90.1.el7 updates 8.1 M
................
#从以上输出,我们可以看出yum update 默认是升级更新全部的软件包,包括内核以及操作系统的包,从上面输出可以看到,
#内核有个 kernel-3.10.0-1160.90.1.el7包可以升级安装,kernel-tools工具包也可以升级安装
#操作系统版本可以升级到centos-release-7-9.2009.1.el7.centos
总结
#升级软件包,但是不升级内核相关的包以及操作系统版本
#使用--exclude=xx 来忽略对应的包
yum --exclude=kernel* --exclude=centos-release* update
#升级更新全部软件包,会升级更新内核相关的包,也会升级操作系统版本,如果的centos是7.6,则会默认升级到centos7.9
yum update
备注:yum update 会不会更新内核以及操作系统版本,其实主要是根据yum源里面有没有可用的包来决定的,比如笔者的yum是默认的是centos官方的,
所以,即使我的操作系统版本是centos7.6,但是官网的yum源里面有centos7.9的更新包,所以还是会升级到centos7.9.如果是本地的yum源,如
CentOS-7-x86_64-DVD-1810.iso挂载的yum,包里面没有centos7.9的更新包,所以,yum update 也不会更新升级操作系统版本。