我平時都在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即可。