CentOS转RHEL

上月,CentOS宣布将开发重心转向CentOS Stream,CentOS 8的支持期从2029年缩短到2021年。我的VPS正在使用CentOS 8,原计划切换到CentOS Stream,试验后遇到了bug,正好手头有Redhat开发者订阅,于是决定利用Convert2RHEL切换到Red Hat Enterprise Linux。

申请Red Hat开发者订阅

首先注册Redhat账户:

https://www.redhat.com/wapps/ugc/register.html

然后通过这个网址进入开发者平台

https://developers.redhat.com/auth/realms/rhd/account/

勾选 Red Hat Developer Program 然后点击保存。

需要注意的是Redhat开发者订阅只能用于非生产环境,不要用于商业目的。

更新CentOS

检查系统版本

1
2
cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

升级系统

1
2
sudo yum clean all
sudo yum update

重启系统

查看现在的系统版本

1
2
cat /etc/redhat-release
CentOS Linux release 8.3.2011

设置RHEL光盘源

由于技术上的原因Convert2RHEL目前还不支持subscription-manager,只能使用第三方源,所以我们使用光盘作为源。

下载光盘文件,下载链接需要登录后到Customer Portal获取

1
2
sudo yum install curl nano
curl -o rhel-8.3-x86_64-dvd.iso 'download_link'

挂载ISO文件

1
2
sudo mkdir /mnt/vcdrom
sudo mount -o loop -t iso9660 ~/rhel-8.3-x86_64-dvd.iso /mnt/vcdrom

编辑/etc/yum.repos.d/RHEL-Media.repo

1
2
3
4
5
6
7
8
9
[rhel-8-baseos]
name=rhel-8-baseos
baseurl=file:///mnt/vcdrom/BaseOS
enabled=1

[rhel-8-appstream]
name=rhel-8-appstream
baseurl=file:///mnt/vcdrom/AppStream
enabled=1

查看光盘源

1
sudo yum repolist all

Convert2RHEL转换系统

安装Convert2RHEL

1
sudo yum install https://github.com/oamg/convert2rhel/releases/download/v0.14/convert2rhel-0.14-1.el8.noarch.rpm

使用光盘源转换

1
sudo convert2rhel --disable-submgr --enablerepo rhel-8-baseos --enablerepo rhel-8-appstream --debug

等待直到Convert2RHEL安装所有RHEL包,这要花一段时间。转换结束后提示下面几个包没有更改。

1
2
3
4
5
6
7
The following packages were left unchanged.
Package Packager Repository
------- -------- ----------
centos-gpg-keys-8-2.el8.noarch CentOS Buildsys @BaseOS
centos-linux-release-8.3-1.2011.el8.noarch CentOS Buildsys @BaseOS
centos-linux-repos-8-2.el8.noarch CentOS Buildsys @BaseOS
convert2rhel-0.14-1.el8.noarch N/A @@commandline

重启,激活订阅

1
sudo subscription-manager register --username=<username>  --password=<password>  --auto-attach

删除CentOS的源

1
sudo rm /etc/yum.repos.d/CentOS*

此时已经可以利用订阅更新系统

1
sudo yum update

转换成功

尾记

Convert2RHEL不会更新/etc/redhat-release文件,此时查看系统版本

1
2
cat /etc/redhat-release
CentOS Linux release 8.3.2011

因为其不属于kernel

1
2
rpm -qf /etc/redhat-release
centos-linux-release-8.3-1.2011.el8.noarch

其属于名为redhat-release-server的包,可以手动替换这个包

1
2
3
4
sudo yum shell
> remove centos-linux-release
> install redhat-release
> run

这时再查看系统版本就是RHEL了

1
2
cat /etc/redhat-release
Red Hat Enterprise Linux release 8.3 (Ootpa)

参考文献