Converting system between RHEL and CentOS

rhel2centosHave you ever had the need to switch a CentOS system to a valid Red Hat Enterprise Linux subscription and viceversa?

I had this need quite a few times, with the most simple case being to transform an evaluation environment based on CentOS that has been used to convince a boss, into a fully supported Red Hat subscription at the end of the evaluation.

On the other hand, it could prove very useful to create an exact copy of an installed system that is currently attached to a Red Hat subscription on an image in your laptop for development purposes. Or simply because the Red Hat subscription has expired and we don’t need any kind of paid support from Red Hat.

As an example for this conversion tutorial, we’re using a CentOS/RHEL 6.6 system. The procedure is the same even if we are also switching minor release during the conversion; for example upgrading from 6.3 to 6.6.

From Red Hat Enterprise Linux to CentOS

This is the most simple case, mainly for two reasons. First of all, we can fetch the packages we need for the installation on the web (we don’t need a valid Red Hat subscription) and basically we are reducing the number of packages that are installed on the sytem in comparison with a pristine Red Hat Enterprise Linux system.

As the first step we must remove the -release package from the system and switch it with the one we’re interested in. This way the yum commands will be able to expand the necessary variables and fetch the correct packages.

rpm -e --nodeps redhat-release-server-6Server
yum -y install http://mirror.centos.org/centos/6/os/x86_64/Packages/centos-release-6-6.el6.centos.12.2.x86_64.rpm

Also, with CentOS and Fedora, the package that defines the system release contains also the yum repository definitions, speeding up conversion considerably.

Now, the only thing we need to do is to start the package syncing process. Yum will take care of the rest.

yum -y distro-sync
reboot

If during the upgrade we performed quite a significant jump of release (for example from 6.3 to 6.6) it’s good practice to also reset the SELinux contexts on the filesystem during the first reboot:

fixfiles onboot

System cleanup after the conversion

Before restarting the system, we can also take care of a few simple finishing touches; for example we can remove the Red Hat network support packages that we will never use again:

yum -y remove rhn\* subscription\* yum-rhn-plugin

Erase packages that are no longer available in any repository:

package-cleanup --orphans

Or we can also replace the initial Firefox starting page that suggests us to register our system with Red Hat Network:

rpm -e --nodeps redhat-indexhtml
yum -y install http://mirror.centos.org/centos-6/6.6/os/x86_64/Packages/centos-indexhtml-6-2.el6.centos.noarch.rpm

To remove the leftover kernels on the system (including packages containing kernel headers, modules, etc.) we can run this command that will clean the system for us from all kernels except the one we’re running:

package-clenup -y --oldkernels --count=1

From CentOS to Red Hat Enterprise Linux

The opposite procedure is slightly different. It’s a bit simpler as the commands we require to type are reduced (quite a few packages from CentOS keep providing the old Red Hat package name in the Provides: tags. It’s otherwise a bit longer as we need a valid account to download by hand the required packages for the conversion; as the yum repositories (or channels) are not available.

After getting access to the Red Hat customer portal, we need to download the following packages to register the system (in our example we’re targeting a Server subscription):

redhat-release-server
rhn-check
rhn-client-tools
rhn-setup
rhn-setup-gnome
rhnlib
rhnsd
subscription-manager
subscription-manager-firstboot
subscription-manager-gnome
yum-rhn-plugin

Now we can proceed with the system conversion, as yum will behave like running on a Red Hat system:

rpm -e --nodeps centos-release
yum install *rpm

Then we can register our host to the channels we want:

subscription-manager --register

And finally proceed with the package synchronization:

yum -y distro-sync
reboot

2 thoughts to “Converting system between RHEL and CentOS”

  1. Hi,
    even after doing what you suggested you still have some Centos and some Red Hat packages installed in parallel. If you open up a RedHat support call it will be detected that you are using packages that are created by Centos and are not supported by Red Hat.

    To fix this you could use something like this:

    rpm -qa --queryformat %{name}\ %{vendor}\\n | grep “CentOS” | sed -e ‘s: .*::’ | xargs yum reinstall -y

    I had the same problem, and described my complete solution here.

Leave a Reply