从Centos-7升级到Centos-Stream-8

如果在正式环境升级,请做好数据备份以及重要配置备份!因为升级会造一部分应用被卸载。

注意:升级前请备份好数据,升级可能会导致ssh的root用户无法登陆、网卡名称发生改变、引导丢失无法开机等问题。

1.安装epel源

yum -y install epel-release

2.更新系统至最新版本

防止升级时出现各种奇葩问题

yum -y update

3.重启系统

reboot

4.安装rpmconf和yum-utils

yum -y install rpmconf yum-utils

5.执行rpmconf

如果出现一些提示,请输入Y和回车继续,如果没提示继续第四步操作

rpmconf -a

6.安装dnf

yum -y install dnf

7.移除yum和yum-metadata-parser

dnf -y remove yum yum-metadata-parser

8.安装Centos-8-Stream的源和升级epel源

rpm -e --nodeps `rpm -qa|grep centos-release`

rpm -ivh --nodeps --force http://mirrors.nju.edu.cn/centos/8-stream/BaseOS/x86_64/os/Packages/centos-stream-release-8.6-1.el8.noarch.rpm

rpm -ivh --nodeps --force http://mirrors.nju.edu.cn/centos/8-stream/BaseOS/x86_64/os/Packages/centos-stream-repos-8-6.el8.noarch.rpm

rpm -ivh --nodeps --force http://mirrors.nju.edu.cn/centos/8-stream/BaseOS/x86_64/os/Packages/centos-gpg-keys-8-6.el8.noarch.rpm

dnf -y upgrade https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm

dnf clean all

9.卸载centos7的内核

rpm -e --nodeps `rpm -qa|grep -i kernel`

10.升级到Centos-8-Stream

这一步一般会报错,如果没有报错请进行下一步操作

 dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync

执行完上面的命令之后如果报下面的错,如果没报下面的错跳过这一步即可(请认真阅读错误提示!)。

请把红框里面的包名(可能有多个包,重复下面的步骤)替换到下面命令:命令:

find /var/cache/dnf/ -name *包名*

如:

find /var/cache/dnf/ -name *dracut-network-049-218.git20221019.el8.x86_64*

安装rpm包如:

rpm -ivh --nodeps --force /var/cache/dnf/baseos-055ffcb2ec25a27f/packages/dracut-network-049-218.git20221019.el8.x86_64.rpm

之后往下操作:

dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync

从Centos-7升级到Centos-Stream-8_第1张图片

 

发现报错之后先卸载类似于图上from package后面的包名

rpm -e --nodeps python36-rpmconf-1.0.22-1.el7.noarch
rpm -e --nodeps sysvinit-tools-2.88-14.dsf.el7.x86_64

卸载完后再次执行升级

 dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync

11.重新安装yum、rpmconf和yum-utils

rm -rf /etc/yum
dnf clean all
dnf -y install yum rpmconf yum-utils

12.安装内核

(防止有些时候没安装内核开机失败,开机失败的可以用Centos8 ISO镜像救援模式安装内核)

dnf -y install kernel kernel-core
dnf -y install shim grub2-tools-extra grubby grub2-common grub2-pc
dnf -y install grub2-tools-efi grub2-tools-minimal grub2-efi grub2-pc-modules grub2-tools

13.安装基础环境

dnf -y groupinstall "Minimal Install"

14.执行rpmconf

会出现如下界面,一直输入Y和回车即可

rpmconf -a

从Centos-7升级到Centos-Stream-8_第2张图片

15.防止迁移完成后找不到引导

执行下面的命令,防止迁移完成后找不到引导,重启开不了机,根据以下命令选择分区表类型,根据分区表类型执行相关命令

查看分区表类型

fdisk -l

GPT分区表

从Centos-7升级到Centos-Stream-8_第3张图片

MBR分区表

从Centos-7升级到Centos-Stream-8_第4张图片

GPT分区(UFFI的BIOS)

export grubcfg=`find /boot/ -name centos`
grub2-mkconfig -o $grubcfg/grub.cfg

添加UEFI启动项(注意/dev/nvme0n1为efi分区所在磁盘,需根据实际情况自行选择磁盘路径,具体参考上图,-p后面是分区位置(默认为1),efi分区为/dev/nvme0n1p1值就是1,efi分区为/dev/nvme0n1p2值就是2)

efibootmgr -c -w -L "CentOS" -d /dev/nvme0n1 -p 1 -l \\EFI\\Boot\\bootx64.efi

MBR分区(传统的BIOS、dos、msdos)(注意/dev/nvme0n1需根据实际情况自行选择磁盘路径,具体参考上图)

grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-install /dev/nvme0n1

16.重启机器

reboot

你可能感兴趣的:(centos,linux,运维)