Centos8升级 Centos9

注意:Centos9 是用 UEFI 启动方式, 升级前请先确认,以免重启无法引导

由于 Centos9 是滚动更新所以VER=9.0-26参数需要查看http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/的 rpm

dnf upgrade --refresh -y
dnf remove -y $(dnf repoquery --unneeded)
dnf remove -y $(dnf repoquery --extras)
dnf autoremove -y

VER="9.0-26"
dnf install -y http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/Packages/centos-{stream-release,stream-repos,gpg-keys}-${VER}.el9.noarch.rpm  --allowerasing
dnf install -y https://dl.fedoraproject.org/pub/epel/{epel-release-latest-9.noarch.rpm,epel-next-release-latest-9.noarch.rpm}
dnf -y remove rxvt-unicode-terminfo
dnf -y --releasever=9 --allowerasing --setopt=deltarpm=false distro-sync
rpmdb --rebuilddb
dnf -y remove -y subscription-manager
dnf upgrade --refresh -y
dnf -y groupupdate "Core" "Minimal Install"
dnf -y install kernel*  yum 
rpm -qa | grep '\.el8' | xargs xargs rpm -e # 卸载

#grubby --default-kernel
grubby --set-default 0

dnf -y install grub2 grub2-efi* shim-x64   #centos9的 baseos 包里面是shim-x64-15-15.el8_2.x86_64.rpm
dnf -y reinstall grub2 grub2-efi-x64  shim-x64
grub2-mkconfig -o /boot/grub2/grub.cfg
#grub2-install /dev/sda  #不适用于 uefi

 [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS    #判断是 BIOS 还是 EFI

如果有dnf module @modulefailsafe 报错可以禁用或者不管

rm -rf /etc/dnf/modules.d/*  /var/lib/dnf/modulefailsafe/*   #  删掉即可

 

升级完成前确认网络配置以及系统内核引导全部正常后才能重启, 否则后续处理起来比较麻烦, 要挂救援系统操作。

 

由于我个人是从 Centos7 升级上来的, 用其他发行版的network-scripts包进行安装

systemctl disable NetworkManager
dnf -y install  https://blog.racknerd.com/wp-content/uploads/2022/12/network-scripts-10.11.4-1.el9.x86_64.rpm
/usr/lib/systemd/systemd-sysv-install enable network
echo "exclude=network-scripts  initscripts " >>/etc/dnf/dnf.conf   #Centos9没有network-scripts包 更新的时候会触发卸载
#vim  /etc/sysconfig/network-scripts/ifcfg-eth0  #修改网卡配置

添加新评论 »