Linux【1】-系统安装-2-3-Centos7升级到centos8

下面是温和升级的方案,我按着下面的操作,系统是从centos7升级到了centos8 ,但内核还是centos7的,最后的最后各种折腾,还是选了通过U盘来升级。所以下面的方法仅供参考,娱乐一下。。

一、安装流程

1.查看自己的centos版本

[root@upgrade-centos ~]# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

2.升级到最新的centos7系统

[root@upgrade-centos ~]# yum update –y

[root@upgrade-centos ~]# more /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

有说明文档提到,如果升级了centos7系统,需要重启一下。 因为我的本来就是7.9,所以这里就没有啥更新。

3.安装EPEL Repository

[root@upgrade-centos ~]# yum install epel-release

4.安装 yum-utils tools

[root@upgrade-centos ~]# yum install yum-utils -y

5.安装rpmconf to resolve RPM packages

[root@upgrade-centos ~]# yum install rpmconf -y


Tool to handle rpmnew and rpmsave files
rpmconf command searches for .rpmnew, .rpmsave, and .rpmorigfiles and asks the user what to do with them.

6.Perform reconciliation of configs.

[root@upgrade-centos ~]# rpmconf -a

Configuration file '/etc/ssh/sshd_config'
-rw-------. 1 root root 3907 Nov 24 16:35 /etc/ssh/sshd_config.rpmnew
-rw-r--r--. 1 root root 4360 Feb 15 05:34 /etc/ssh/sshd_config

==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
M : merge configuration files
Z : background this process to examine the situation
S : skip this file
The default action is to keep your current version.
*** aliases (Y/I/N/O/D/M/Z/S) [default=N] ?

7.Perform a clean-up of all the packages you don’t require.

[root@upgrade-centos ~]# package-cleanup --leaves

Loaded plugins: fastestmirror
bind-libs-lite-9.11.4-26.P2.el7_9.8.x86_64
libgudev1-219-78.el7_9.5.x86_64
libndp-1.2-9.el7.x86_64
libsoup-2.62.2-2.el7.x86_64
libsysfs-2.1.0-16.el7.x86_64
[root@upgrade-centos ~]# package-cleanup --orphans
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.mirrors.estointernet.in
* epel: ftp.jaist.ac.jp
* extras: centos.mirrors.estointernet.in
* updates: centos.mirrors.estointernet.in
kernel-3.10.0-327.18.2.el7.x86_64

8.安装dnf (package manager) on CentOS 7

What is DNF? DNF is a software package manager that installs, updates, and removes packages on Fedora and is the successor to YUM

[root@upgrade-centos ~]# yum install dnf -y

9.删掉YUM package manager

[root@upgrade-centos ~]# dnf remove yum yum-metadata-parser
[root@upgrade-centos ~]# rm -rf /etc/yum

Remove yum
YUM is the default package manager for CentOS 7, and remove yum configuration file to avoid any conflict with dnf. Since CentOS 8 uses dnf as the primary package manager.

10.Upgrade CentOS 7 to Centos 8

We are all set to upgrade CentOS 7 to CentOS 8, but before that, we need to upgrade the system.

[root@upgrade-centos ~]# dnf upgrade

11.安装CentOS 8 release package using dnf

dnf -y upgrade
# dnf -y upgrade https://vault.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-linux-release-8.5-1.2111.el8.noarch.rpm
#dnf install https://vault.centos.org/8.5.2111/BaseOS/Source/SPackages/centos-linux-release-8.5-1.2111.el8.src.rpm   # latest CentOS release is 8.5


dnf install http://vault.centos.org/8.5.2111/BaseOS/x86_64/os/Packages/{centos-linux-repos-8-3.el8.noarch.rpm,centos-linux-release-8.5-1.2111.el8.noarch.rpm,centos-gpg-keys-8-3.el8.noarch.rpm}

dnf -y upgrade https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm  # Upgrade EPEL Repository
dnf clean all

Step 14: Remove the old CentOS 7 Kernel

[root@upgrade-centos ~]# rpm -e `rpm -q kernel`

Step 15: Remove all the conflicting packages

[root@upgrade-centos ~]# rpm -e --nodeps sysvinit-tools

Step 16: Remove any conflicting packages

Some of the packages might conflict with the upgrade process, remove them as below by replacing the package_name

# dnf remove <package_name>

Step 17: Upgrade to CentOS 8. This will take some time

#需要更新源
[root@autocontroller ~]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
[root@autocontroller ~]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
[root@autocontroller ~]# dnf update

[root@upgrade-centos ~]# dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync

CentOS Linux 8 - Extras                                                30 kB/s |  10 kB     00:00
Module yaml error: Unexpected key in data
Module yaml error: Unexpected key in data
Module yaml error: Unexpected key in data
Module yaml error: Unexpected key in data
Module defaults error: Unexpected key in data
Module defaults error: Unexpected key in data
Module defaults error: Unexpected key in data
Module defaults error: Unexpected key in data
Error:
 Problem: The operation would result in removing the following protected packages: kernel

Step 18: Install new kernel for CentOS 8

CentOS 8 repos change Since CentOS 8 has reached EOL, the mirror.centos.org has been changed to vault.centos.org

[root@upgrade-centos ~]# dnf -y install kernel-core

Step 19: Install CentOS 8 minimal packages

#[root@upgrade-centos ~]# dnf -y groupupdate "Core" "Minimal Install"  #这一步有报错,干脆直接跳过了
[root@upgrade-centos ~]# dnf -y groupupdate "Core" "Minimal Install" --skip--broken

Step 20: Reboot the server

[root@upgrade-centos ~]# reboot

Step 21: Verify the upgrade

[root@upgrade-centos ~]# more /etc/redhat-release CentOS Linux release 8.5.2111

二、报错:

铁汉 14:54:10

2.1 报错1

[root@upgrade-centos ~]# dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync

Running transaction check
Error: transaction check vs depsolve:
(kernel-debug-devel if kernel-debug-core) is needed by dkms-3.0.7-1.el8.noarch
(kernel-devel if kernel-core) is needed by dkms-3.0.7-1.el8.noarch
(kernel-rt-debug-devel if kernel-rt-debug-core) is needed by dkms-3.0.7-1.el8.noarch
(kernel-rt-devel if kernel-rt-core) is needed by dkms-3.0.7-1.el8.noarch

rpmlib(RichDependencies) <= 4.12.0-1 is needed by dkms-3.0.7-1.el8.noarch

To diagnose the problem, try running: 'rpm -Va --nofiles --nodigest'.
You probably have corrupted RPMDB, running 'rpm --rebuilddb' might fix the issue.
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.

这一步一般会报错,然后根据报错来解决:

[root@c01 ~]# rpm -Va --nofiles --nodigest
Unsatisfied dependencies for iprutils-2.4.17.1-3.el7_7.x86_64:
        /sbin/pidof is needed by (installed) iprutils-2.4.17.1-3.el7_7.x86_64
Unsatisfied dependencies for initscripts-9.49.53-1.el7_9.1.x86_64:
        sysvinit-tools >= 2.87-5 is needed by (installed) initscripts-9.49.53-1.el7_9.1.x86_64

#解决过程		        
[root@c01 ~]# dnf remove iprutils

[root@c01 ~]# dnf install iprutils
CentOS Linux 8 - BaseOS                                               0.0  B/s |   0  B     00:00
CentOS Linux 8 - AppStream                                            0.0  B/s |   0  B     00:00
Failed to synchronize cache for repo 'baseos', ignoring this repo.
Failed to synchronize cache for repo 'appstream', ignoring this repo.
Last metadata expiration check: 0:03:19 ago on Thu 27 Oct 2022 04:21:01 PM CST.
Module yaml error: Unexpected key in data
Module yaml error: Unexpected key in data
Module yaml error: Unexpected key in data
Module yaml error: Unexpected key in data
Module defaults error: Unexpected key in data
Module defaults error: Unexpected key in data
Module defaults error: Unexpected key in data
Module defaults error: Unexpected key in data
No match for argument: iprutils
Error: Unable to find a match: iprutils

dnf clean all
rm -rf /var/cache/dnf
dnf upgrade

dnf remove initscripts

dnf clean all
rm -rf /var/cache/dnf
dnf upgrade

解决途径:

[root@autocontroller ~]# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
[root@autocontroller ~]# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
[root@autocontroller ~]# dnf update


Key imported successfully
Running transaction check
Error: transaction check vs depsolve:
(gcc >= 8 with gcc < 9) is needed by annobin-9.72-1.el8_5.2.x86_64

rpmlib(RichDependencies) <= 4.12.0-1 is needed by annobin-9.72-1.el8_5.2.x86_64
(kernel-debug-devel if kernel-debug-core) is needed by dkms-3.0.7-1.el8.noarch
(kernel-devel if kernel-core) is needed by dkms-3.0.7-1.el8.noarch
(kernel-rt-debug-devel if kernel-rt-debug-core) is needed by dkms-3.0.7-1.el8.noarch
(kernel-rt-devel if kernel-rt-core) is needed by dkms-3.0.7-1.el8.noarch
rpmlib(RichDependencies) <= 4.12.0-1 is needed by dkms-3.0.7-1.el8.noarch
(annobin if gcc) is needed by redhat-rpm-config-125-1.el8.noarch
rpmlib(RichDependencies) <= 4.12.0-1 is needed by redhat-rpm-config-125-1.el8.noarch
To diagnose the problem, try running: 'rpm -Va --nofiles --nodigest'.
You probably have corrupted RPMDB, running 'rpm --rebuilddb' might fix the issue.
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.

参考资料

这里是一个广告位,,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn