ClickCease RHEL 7 to CentOS 7 conversion script

Join Our Popular Newsletter

Join 4,500+ Linux & Open Source Professionals!

2x a month. No spam.

RHEL 7 to CentOS 7 conversion script

by Rohan Timalsina

May 23, 2023 - TuxCare expert team

We have received requests for assistance with converting systems running RHEL 7 to CentOS 7. There are various reasons for organizations wanting to make this transition, ranging from the desire to standardize their server fleets to licensing changes, future migration paths, or other factors. 

CentOS is a free, community-driven version of RHEL, making it an excellent alternative to the licensed RHEL for those who don’t need official support. While changing repositories may seem like a straightforward task, it is, in fact, a somewhat intricate process. For this reason, we created a script to automatically perform the conversion.

This article provides an in-depth look at the conversion script and RHEL 7 to CentOS 7 migration process. It should be noted, however, that CentOS 7 will reach its end-of-life stage in June 2024, so support from the vendor will end at that point and organizations will need to purchase extended support to continue to safely use this distribution.

Now, on to the migration steps…

 

What does this script do?

Before executing this script, it is worth understanding what it does. This script is written in Python and performs the following nine operations:

 

1.  Check if the conversion has already been completed

 

This script is designed to be idempotent, which means it can be executed multiple times without any risk. The status of every step is stored in a special file, so the script will never execute a previously completed step again. If all steps have been done, the script will return the message “The system has already migrated to CentOS 7” and exit. 

2. Check if the script is running with root privileges

Most of the commands executed by the script require root privileges, so this is checked at the very beginning.

 

3. Check if the current system is RHEL 7

The script verifies that the installed system is RHEL 7. As each operating system has its own specific characteristics, trying to execute the script on an unsupported system may result in unexpected results.

4. Remove RHEL-specific packages

This step removes packages specific to RHEL, such as logos and configuration files containing information about the release and repositories. These are the packages mainly responsible for the “branding” of the distribution.

 

5. Install CentOS-specific packages

After removing RHEL-specific packages, they are replaced with the corresponding packages from CentOS. Going forward, the CentOS repositories will be used to install and update packages.

 

6. Update distribution packages

A regular update of all system packages to the latest versions available in the CentOS repositories is performed.

 

7. Synchronize distribution packages

The extra step of keeping the packages in sync with the latest versions available in the CentOS repositories is necessary for cases where a package in CentOS has a lower version than the equivalent RHEL one. Although this scenario is rare, it still needs to be addressed as it may arise.

 

8. Perform some EFI and Secure Boot-specific operations

This step is very crucial for converting systems running in UEFI (not BIOS) mode. Many solutions and articles do not provide information on the steps required to handle such systems, but neglecting to do so can result in an unbootable operating system after the conversion. RHEL and CentOS use different paths for the Shim and Grub2 boot loaders – /boot/efi/EFI/redhat and /boot/efi/EFI/centos respectively.

This discrepancy leads to two issues. First, after the conversion, the Grub2 bootloader will attempt to locate its configuration in the new path, even though it’s still situated in the /boot/efi/EFI/redhat directory. The second problem is the boot entries in the UEFI firmware. An RHEL entry will continue to point to the bootloader in /boot/efi/EFI/redhat, which is no longer accessible through this path. 

Most UEFI firmware implements a fallback mode, where the bootloader can still be detected and launched. However, the implementation of this mode is optional and not all hardware supports this. As a result, the system will be unable to boot after migration. Both of these issues are automatically solved in this step.

Additionally, at this step, the script makes sure that the Shim and Grub2 boot loaders and the kernel are installed from the CentOS repository. If any of these packages remain from RHEL, the system will be unable to boot into Secure Boot mode. Such packages will be detected and reinstalled from CentOS repositories.

 

9. Set the default GRUB record

Generally, RHEL systems have several latest kernels installed. Therefore, the script makes the kernel from CentOS the default kernel for the next boot step in the final step. This step is also required for systems running in Secure Boot mode.

 

RHEL 7 to CentOS 7: Step-by-Step Process

1.  Create a backup of the system 

Before starting the migration process, we recommend you do a complete backup of your RHEL 7 system. 

 

2. Download the script

The Python script to migrate RHEL 7 to CentOS 7 is available on GitHub:

https://github.com/cloudlinux/rhel2centos

You can run this command to download the script on your computer.

$ curl -O https://raw.githubusercontent.com/cloudlinux/rhel2centos/main/migrate_7.py

 

3. Run the script

Once the file is downloaded, execute the script using the Python command. 

$ sudo python migrate_7.py

Output:

The system is migrated to CentOS 7.

 

4. Verify the migration

To verify whether the migration is successful, run the following command to check the release file.

$ cat /etc/redhat-release

Output:

CentOS Linux release 7.9.2009 (Core)

Check if the system boots the CentOS kernel by default.

$ sudo grubby –info DEFAULT | grep CentOS

Output:

title=CentOS Linux (3.10.0-1160.31.1.el7.x86_64) 7 (Core)

Note: Version numbers may vary as new updates are released.

 

RHEL 7 vs. CentOS 

RHEL 7 is a commercial distribution developed by Red Hat, a prominent enterprise software company, while CentOS 7 is a community-driven distribution created from the Red Hat Enterprise Linux (RHEL) source code. 

While RHEL 7 is specifically designed to cater to the needs of enterprise environments that require robust security, stability, and support, CentOS 7 is popular among individual users and smaller organizations who are seeking a free and open-source alternative to RHEL.

Both RHEL 7 and CentOS 7 are regarded as having good security levels. However, with enterprise-level support and access to proprietary security tools, RHEL 7 has a modest advantage over CentOS. Because of this, RHEL 7 stands out as a superior option for businesses that need high levels of security. 

On the other hand, CentOS 7 is the way to go if you are seeking a free and open-source substitute with a large selection of packages. Whichever version you select, RHEL 7 and CentOS 7 are both extremely safe and reliable operating systems that may satisfy the demands of the majority of users.

It is also important to note that the maintenance support for RHEL 7 will end on June 30, 2024 and CentOS 7 will also reach its end of life on that date. Since there is a little over a year left, it is recommended for users and administrators to start planning their migration

If you are uncertain about the migration to alternative distros, you can opt for extended support from TuxCare’s EOL support for CentOS 7, which provides four-year extended lifecycle support.

 

The bottom line

To summarize, switching from RHEL 7 to CentOS 7 can be a challenging task. However, it may be carried out easily and without having any negative impacts on the system, as long as it’s done with careful planning and execution. 

We hope this guide helps you to convert your RHEL 7 system to CentOS 7!

Summary
RHEL 7 to CentOS 7 conversion script
Article Name
RHEL 7 to CentOS 7 conversion script
Description
Do you want to learn how to easily migrate RHEL 7 to CentOS 7 using the conversion script. Read this blog post
Author
Publisher Name
TuxCare
Publisher Logo

Looking to automate vulnerability patching without kernel reboots, system downtime, or scheduled maintenance windows?

Become a TuxCare Guest Writer

Mail

Help Us Understand
the Linux Landscape!

Complete our survey on the state of Open Source and you could win one of several prizes, with the top prize valued at $500!

Your expertise is needed to shape the future of Enterprise Linux!