亲宝软件园·资讯

展开

从CentOS 7.0升级到7.7版本

yang wu 人气:0

我平时都在VirtualBox上装虚拟机,方法是导入ova镜像文件,比如导入从网上下载的CentOS7-base.ova,该ova为CentOS 7.0版本,而现在最新版本为7.7,为此进入系统后第一件事就是系统升级:

# yum update

可是该命令居然异常退出了!

重新进入系统后检查:

# uname -r
3.10.0-123.9.2.el7.x86_64

# cat /proc/version
Linux version 3.10.0-123.9.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Tue Oct 28 18:05:26 UTC 2014

# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

可见Linux发行版本号已改为7.7,但核心仍然是旧版本,并且再次执行yum update命令失败,说明系统未升级成功。经常一段时间摸索找到两种从7.0升级到7.7的方法。

方法一:升级失败后手工解决错误并重新升级

yum update命令异常退出后重新登录系统,然后执行:

清理上次失败的命令

# yum-complete-transaction --cleanup-only

查看重复的包

# package-cleanup --dupes
kbd-misc-1.15.5-10.el7.noarch
kbd-misc-1.15.5-15.el7.noarch
nss-tools-3.44.0-7.el7_7.x86_64
nss-tools-3.16.2-7.el7_0.x86_64
...
gzip-1.5-10.el7.x86_64
gzip-1.5-7.el7.x86_64

该命令本应无输出,但由于上次yum update命令失败导致大量重复的新旧包。

删除重复的包

# package-cleanup --cleandupes
...
Complete!
Warning: Some duplicates were not removed because they are required by installed packages.
You can try --cleandupes with --removenewestdupes, or review them with --dupes and remove manually.

该命令虽然删除了很多重复包,但提示未完全清除。

尝试重新升级

# yum update
...
--> Finished Dependency Resolution
Error: Package: avahi-libs-0.6.31-13.el7.x86_64 (@anaconda)
           Requires: avahi = 0.6.31-13.el7
           Removing: avahi-0.6.31-13.el7.x86_64 (@anaconda)
               avahi = 0.6.31-13.el7
           Updated By: avahi-0.6.31-19.el7.x86_64 (base)
               avahi = 0.6.31-19.el7
Error: firewalld conflicts with 1:NetworkManager-0.9.9.1-28.git20140326.4dba720.el7_0.2.x86_64
Error: avahi-libs conflicts with avahi-0.6.31-19.el7.x86_64
 You could try using --skip-broken to work around the problem
...

仍升级失败!

根据上面的错误信息删除旧包

# rpm -e avahi-libs-0.6.31-13.el7.x86_64
error: Failed dependencies:
        avahi-libs = 0.6.31-13.el7 is needed by (installed) avahi-0.6.31-13.el7.x86_64
        avahi-libs = 0.6.31-13.el7 is needed by (installed) avahi-autoipd-0.6.31-13.el7.x86_64

该命令失败,原因是存在依赖项。为此需同时删除依赖项:

# rpm -e avahi-libs-0.6.31-13.el7.x86_64 \
> avahi-0.6.31-13.el7.x86_64 \
> avahi-autoipd-0.6.31-13.el7.x86_64
error: Failed dependencies:
        avahi-autoipd is needed by (installed) NetworkManager-1:0.9.9.1-28.git20140326.4dba720.el7_0.2.x86_64

仍有其它级联依赖项,一并删除:

# rpm -e avahi-libs-0.6.31-13.el7.x86_64 \
> avahi-0.6.31-13.el7.x86_64 \
> avahi-autoipd-0.6.31-13.el7.x86_64 \
> NetworkManager-1:0.9.9.1-28.git20140326.4dba720.el7_0.2.x86_64
error: Failed dependencies:
        NetworkManager = 1:0.9.9.1-28.git20140326.4dba720.el7_0.2 is needed by (installed) NetworkManager-tui-1:0.9.9.1-28.git20140326.4dba720.el7_0.2.x86_64

继续一并删除:

# rpm -e avahi-libs-0.6.31-13.el7.x86_64 \
> avahi-0.6.31-13.el7.x86_64 \
> avahi-autoipd-0.6.31-13.el7.x86_64 \
> NetworkManager-1:0.9.9.1-28.git20140326.4dba720.el7_0.2.x86_64 \
> NetworkManager-tui-1:0.9.9.1-28.git20140326.4dba720.el7_0.2.x86_64

成功!

继续尝试升级

# yum update
...
Replaced:
  grub2.x86_64 1:2.02-0.2.10.el7.centos.1

Complete!

成功!成功升级后请重启系统:

# reboot

再次查看并删除重复的包

# package-cleanup --dupes
...
kbd-misc-1.15.5-10.el7.noarch
kbd-misc-1.15.5-15.el7.noarch
libdb-5.3.21-25.el7.x86_64
libdb-5.3.21-17.el7_0.1.x86_64
...
libteam-1.27-9.el7.x86_64
libteam-1.9-15.el7.x86_64

仍有一些重复的包,删除之:

# package-cleanup --cleandupes
...
--> Finished Dependency Resolution
Error: Rpmdb checksum is invalid: pkg checksums: grub2-tools-1:2.02-0.2.10.el7.centos.1.x86_64
 You could try using --skip-broken to work around the problem
...

不知何故居然报错了,但再次执行就成功了:

# package-cleanup --cleandupes
...
Removed:
  audit-libs.x86_64 0:2.3.3-4.el7                         bind-license.noarch 32:9.9.4-14.el7               device-mapper.x86_64 7:1.02.84-14.el7
  device-mapper-event-libs.x86_64 7:1.02.84-14.el7        device-mapper-libs.x86_64 7:1.02.84-14.el7        dracut.x86_64 0:033-161.el7
  e2fsprogs-libs.x86_64 0:1.42.9-4.el7                    kbd-misc.noarch 0:1.15.5-10.el7                   libcom_err.x86_64 0:1.42.9-4.el7
  libcurl.x86_64 0:7.29.0-19.el7                          libdb.x86_64 0:5.3.21-17.el7_0.1                  libss.x86_64 0:1.42.9-4.el7
  libteam.x86_64 0:1.9-15.el7                             systemd.x86_64 0:208-11.el7_0.4                   systemd-libs.x86_64 0:208-11.el7_0.4

Complete!

再检查一下是否有重复的包:

# package-cleanup --dupes

没有重复的包了。

重启系统并再次检查新版本号

# reboot

# uname -r 3.10.0-1062.18.1.el7.x86_64

# cat /proc/version
Linux version 3.10.0-1062.18.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Mar 17 23:49:17 UTC 2020

# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

完全正确!至此升级成功!

 

方法二:从7.0到7.5再到7.7版本

如果你已执行了yum update命令并且失败则只能用上面的方法一解决,本方法适用于新装系统。

从7.0升级到7.5版本

yum update命令默认升级到最新版,但我们可修改配置文件让其升级到指定的版本。

检查是否有更新

# yum list centos-release
...
Installed Packages
centos-release.x86_64                                                   7-0.1406.el7.centos.2.5                                                   @updates
Available Packages
centos-release.x86_64                                                   7-7.1908.0.el7.centos                                                     base

该命令显示当前版本是7.0,可升级到7.7版本(但我们知道升级会报错)。

修改CentOS-Base.repo文件,指向7.5版本库

把CentOS-Base.repo文件里的mirrorlist注释掉,并增加相应的baseurl,其它不变,如下:

# cat /etc/yum.repos.d/CentOS-Base.repo
...
[base]
... #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=http://vault.centos.org/7.5.1804/os/$basearch/ ...
[updates]
... #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ baseurl=http://vault.centos.org/7.5.1804/updates/$basearch/ ...
[extras] ...
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ baseurl=http://vault.centos.org/7.5.1804/extras/$basearch/ ...
[centosplus]
... #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ baseurl=http://vault.centos.org/7.5.1804/centosplus/$basearch/ ...

清空缓存

修改配置文件后要清理一下缓存:

# yum clean all

再次检查更新

# yum list centos-release
Installed Packages
centos-release.x86_64                                                   7-0.1406.el7.centos.2.5                                                   @updates
Available Packages
centos-release.x86_64                                                   7-5.1804.5.el7.centos                                                     updates

可见如果升级则将升级到7.5版本。

升级到7.5版本

# yum update

升级成功后请reboot重启系统。

从7.5升级到7.7版本

把上面的CentOS-Base.repo文件还原、清空缓存、然后执行yum update即可。

 

加载全部内容

相关教程
猜你喜欢
用户评论