Converting CentOS 8 to RHEL
2021-12-31
Abstract
Red Hat's recommended way of upgrading CentOS to RHEL is using the convert2rhel utility. That utility seems to reinstall all packages which has the potential of breaking for example manual edits to config files. On installations where Red Hat's support is not going to be used (like the developer subscription), the minimal steps for moving from CentOS 8 to system that can receive RHEL 8 upgrades might be sufficient.
Initial situation
Assume we have CentOS Linux 8 machine and Red Hat subscription available, for example using the RHEL Individual Developer Subscription. With CentOS Linux 8's end of life on 2021-12-31, we'd like to convert that installation to RHEL 8 to continue getting package updates, while we don't worry too much that initially we will continue using the original CentOS packages and only migrate to the true RHEL content with subsequent upgrades.
We also assume we have access to Red Hat's access.redhat.com portal with sufficient subscriptions to manually download packages and subscribe systems.
The official method
The official method uses the convert2rhel utility. It is however a fairly large python code which is hard to understand and review the exact steps. For example, it is not clear what that utility will do during package reinstallation when it finds modified no-noreplace config files.
Therefore, in some situations, manual steps where minimum changes are made to the system might achieve functionally the same results, with lower risk. On the other hand, if that resulting RHEL installation is expected to be supported by Red Hat, the official method is certainly recommended.
The minimal method
Since the resulting RHEL machine will be subscribed to Red Hat's central subscription management, the first step involves installing the subscription-manager package. It is in CentOS repositories, so plain
centos8# dnf install -y subscription-manager
will install it to the machine, together with some additional dependency packages.
The subscription manager dnf plugin logic tries to automatically
figure out what products are installed on the machine, to
configure the appropriate dnf repositories for every dnf operation.
On RHEL, the package redhat-release ships
/etc/pki/product-default/479.pem
which
identifies the installation as RHEL 8 x86_64 to the dnf.
We should be able to find the package in Packages tab of
RHEL 8 Download page:
Search for redhat-release package
However, when we download the binary rpm and try to install it with
centos8# dnf install -y ./redhat-release-8.5-0.8.el8.x86_64.rpm
we will get conflict with files provided by its CentOS counterpart centos-linux-release:
Error: Transaction test error: file /etc/os-release from install of redhat-release-8.5-0.8.el8.x86_64 conflicts with file from package centos-linux-release-8.5-1.2111.el8.noarch file /etc/redhat-release from install of redhat-release-8.5-0.8.el8.x86_64 conflicts with file from package centos-linux-release-8.5-1.2111.el8.noarch file /etc/rpm/macros.dist from install of redhat-release-8.5-0.8.el8.x86_64 conflicts with file from package centos-linux-release-8.5-1.2111.el8.noarch file /etc/system-release from install of redhat-release-8.5-0.8.el8.x86_64 conflicts with file from package centos-linux-release-8.5-1.2111.el8.noarch file /etc/system-release-cpe from install of redhat-release-8.5-0.8.el8.x86_64 conflicts with file from package centos-linux-release-8.5-1.2111.el8.noarch file /usr/lib/os-release from install of redhat-release-8.5-0.8.el8.x86_64 conflicts with file from package centos-linux-release-8.5-1.2111.el8.noarch
Attempt to remove centos-linux-release fails with
Error: Problem: The operation would result in removing the following protected packages: setup
In theory,
centos8# dnf swap 'centos-*' ./redhat-release-8.5-0.8.el8.x86_64.rpm
should work but it fails with
Error: Cannot add local packages, because transaction job already exists
Luckily, the shell subcommand still works:
centos8# ( echo install ./redhat-release-8.5-0.8.el8.x86_64.rpm ; echo remove 'centos-*' ; echo run ) | dnf shell -y [...] Installed: redhat-release-8.5-0.8.el8.x86_64 Removed: centos-gpg-keys-1:8-2.el8.noarch centos-linux-release-8.3-1.2011.el8.noarch centos-linux-repos-8-2.el8.noarch Complete! > Leaving Shell centos8#
We've removed not just centos-linux-release, but centos-linux-repos (and centos-gpg-keys) as well, so that any subsequent upgrades have to depend on proper configuration of RHEL repositories only and packages from CentOS repositories will no longer show up in future dnf transactions.
With this swap, we've turned the installation to RHEL 8, at least as far as the subscription manager is concerned. When we now run
centos8# subscription-manager register --org ... --activationkey ...
we should get the system registered and see RHEL repositories autoconfigured:
centos8# subscription-manager repos --list-enabled +----------------------------------------------------------+ Available Repositories in /etc/yum.repos.d/redhat.repo +----------------------------------------------------------+ Repo ID: rhel-8-for-x86_64-baseos-rpms Repo Name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) Repo URL: https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/baseos/os Enabled: 1 Repo ID: rhel-8-for-x86_64-appstream-rpms Repo Name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) Repo URL: https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/appstream/os Enabled: 1
containers-common
When containers-common package is installed on the CentOS machine, there may be one more file conflict reported when installing redhat-release:
Error: Transaction test error: file /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release from install of redhat-release-8.5-0.8.el8.x86_64 conflicts with file from package containers-common-2:1-2.module_el8.5.0+890+6b136101.noarch
The solution is to manually download also the RHEL 8 noarch rpm and upgrade it over the original CentOS 8 package:
centos8# dnf upgrade -y containers-common-1-2.module+el8.5.0+12582+56d94c81.noarch.rpm
Then the dnf shell swap to redhat-release should pass.