由于 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*
dnf -y install grub2-efi*
rpm -qa | grep '\.el8' | xargs xargs rpm -e # 卸载
grub2-mkconfig -o /boot/grub2/grub.cfg
#grub2-install /dev/sda #不适用于 uefi
如果有dnf module @modulefailsafe 报错可以禁用或者不管
/etc/dnf/modules.d/和 /var/lib/dnf/modulefailsafe目录删掉即可