How to Migrate CentOS 7 to Rocky Linux 9

December 20, 2023

Introduction

With CentOS 7 gaining EOL status, many alternatives with long-term support have appeared. One such alternative is Rocky Linux, which is recommended due to its many similarities with CentOS (see our detailed comparison between Rocky Linux and CentOS).

Transitioning between two Linux distributions requires careful planning and execution, as it requires first migrating CentOS 7 to Rocky Linux 8, followed by another migration to Rocky Linux 9. The Leapp framework and ELevate project help simplify the upgrade process.

This guide shows step-by-step instructions for migrating CentOS 7 to Rocky Linux 9.

How to Migrate CentOS 7 to Rocky Linux 9

Prerequisites

  • A system running CentOS 7.
  • Administrator access.
  • Internet connection.

Upgrade CentOS 7 to Rocky Linux 8

The following sections demonstrate CentOS 7 to Rocky Linux 8 migration using the ELevate project and the Leapp framework. The two projects support migration between different RHEL-based distributions.

Follow the steps below to migrate CentOS 7 to Rocky Linux 8 before you can migrate to Rocky Linux 9.

Step 1: Create a Backup

Before migrating any system, the best practice is to create backups and snapshots of the system. The exact steps depend on the infrastructure, but a bare-metal restore is recommended. Tools such as the dd command and reliable backup and restore solutions are recommended before moving production systems.

Important: It is highly recommended to do a trial run of the migration in a sandbox environment before commiting.

Step 2: Install Migration Packages

Install the required packages for migration. Follow the steps below:

1. Install the elevate-release package from the repository for the latest version. Use the following command:

sudo yum install -y http://repo.almalinux.org/elevate/elevate-release-latest-el$(rpm --eval %rhel).noarch.rpm
sudo yum install elevate CentOS 7

2. Install the Leapp migration data packages for Rocky Linux and the upgrade utility with the following:

sudo yum install -y leapp-upgrade leapp-data-rocky
sudo yum install leapp-upgrade leapp-data-rocky CentOS 7

Note: Other options include centos, almalinux, eurolinux, and oraclelinux.

The Leapp utility handles OS and application upgrades.

Step 3: Run Pre-Upgrade Checks

Run a pre-upgrade to do a system check before upgrading:

sudo leapp preupgrade
leapp preupgrade results inhibited CentOS 7 terminal output

The pre-upgrade takes some time. When completed, it generates files in the /var/log/leapp/ directory that contain all potential upgrade issues and how to address them. The following files contain crucial information:

  • answerfile - Contains questions that require a true or false answer to proceed with the upgrade.
  • leapp-report.txt - Contains all possible problems and fixes to perform before or after the upgrade.
  • leapp-preupgrade.log - The complete pre-upgrade log and debug output.

Check the first two files and perform all required pre-upgrade actions. Some common pre-upgrade fixes when migrating from CentOS 7 are:

1. Removing the pata_acpi kernel module:

sudo rmmod pata_acpi

2. Updating the SSH config file to permit root login:

echo PermitRootLogin yes | sudo tee -a /etc/ssh/sshd_config

3. Confirming the removal of the PAM PKCS#11 module:

sudo leapp answer --section remove_pam_pkcs11_module_check.confirm=True
Pre-upgrade common fixes terminal output CentOS 7

The command updates the answerfile, confirming the removal.

Address all fixes and rerun the pre-upgrade command to confirm everything is fixed:

sudo leapp preupgrade
leapp upgrade results success terminal output CentOS 7

The system is ready for upgrade when the "Upgrade Inhibited" message disappears.

Step 4: Run Upgrade

When no more suggested actions exist, the system is ready to upgrade. Proceed with the OS upgrade steps below:

1. Run the Leapp upgrade command:

sudo leapp upgrade
sudo leapp upgrade CentOS 7 to Rocky Linux 8 terminal output

Wait for the upgrade to complete. If the upgrade fails, return to the previous step and address any issues missed in the pre-upgrade check.

2. When the process completes successfully, reboot the machine:

reboot

The reboot is required for the package-swapping process to begin.

3. The GRUB menu shows a new entry called ELevate-Upgrade-Initramfs.

Grub entry elevate-upgrade-initramfs

After five seconds, the system automatically boots into this selection and continues the upgrade process.

4. The system restarts twice more after the upgrades. When the restarts are complete, the GRUB menu shows a Rocky Linux 8 entry.

Grub entry Rocky Linux 8

The entry indicates a successful upgrade from CentOS 7 to Rocky Linux 8. The system automatically boots into the upgraded version.

Step 5: Post-Upgrade Steps

After the upgrade, complete the following post-upgrade tasks:

1. Log in as the root user using the same credentials from the CentOS 7 system.

2. Clean up any orphaned packages from CentOS 7:

rpm -qa | grep -E 'el7[.-]' | xargs rpm -e

The command searches for and removes all unnecessary CentOS packages and may hinder the following upgrade.

Upgrade Rocky Linux 8 to Rocky Linux 9

The upgrade from Rocky Linux 8 to 9 is also supported through the ELevate project. The steps are similar to the upgrade from CentOS 7 to Rocky Linux 8. The sections below outline the details.

Step 1: Install Migration Packages

Install the Leapp and ELevate migration packages for migrating to Rocky Linux 9:

1. Install the elevate-release package for Rocky 8 with the following command:

sudo yum install -y http://repo.almalinux.org/elevate/elevate-release-latest-el$(rpm --eval %rhel).noarch.rpm
sudo yum install elevate Rocky Linux 8

2. The yum configuration excluded several packages during the upgrade. Change the configuration so no packages are excluded, some of which are Leapp dependencies:

yum config-manager --save --setopt exclude=''

This command does not provide an output.

2. Install the Leapp migration packages:

sudo yum install -y leapp-upgrade leapp-data-rocky
sudo yum install leapp-upgrade leapp-data-rocky rocky 8

The same packages are used for migrating to Rocky Linux 9.

Step 2: Run Pre-Upgrade Checks

Run the pre-upgrade check before upgrading the OS. The command and pre-upgrade checks are almost identical to the ones in the previous section, with minor differences. Run the Leapp preupgrade command:

sudo leapp preupgrade
leapp preupgrade results inhibited Rocky 8 terminal output

The pre-upgrade generates the same pre-upgrade files as in the previous section but with different suggested fixes. Check the answerfile to see all the recommended steps.

Common fixes for Rocky Linux 8 are:

1. Changing the firewalld configuration:

sudo sed -i "s/^AllowZoneDrifting=.*/AllowZoneDrifting=no/" /etc/firewalld/firewalld.conf

2. Removing the network configuration file for unsupported network device type:

rm /etc/sysconfig/network-scripts/ifcfg-[device_name]

3. Bypassing the VDO device check requirement in the answerfile:

sudo leapp answer --section check_vdo.no_vdo_devices=True

Rerun the pre-upgrade to confirm all changes applied and that no more issues appear.

leapp preupgrade results success Rocky 8

Continue to the next step if the "Upgrade Inhibited" message does not appear.

Step 3: Run Upgrade

The system is ready for the upgrade once it passes the pre-upgrade checks. Follow the steps below:

1. Run the Leapp upgrade command:

sudo leapp upgrade
leapp upgrade fail make-devel rocky-logos packages

Wait for the upgrade to complete. If the upgrade fails, check if the report lists any packages as problematic. Commonly, the make-devel and rocky-logos packages cause the upgrade to fail. Remove them with:

dnf remove [package_name]

Rerun the upgrade after removal.

2. When the process completes successfully, the output shows no errors:

leapp upgrade results success Rocky 8

Reboot the system to continue the upgrade:

reboot

3. The system shows a new boot entry in the Grub menu, similar to the previous upgrade. Press Enter to select the entry or wait for it to boot into the ELevate-Upgrade-Initramfs entry automatically.

4. The system restarts during the upgrade. After restarting, the Rocky Linux 9 entry shows in the Grub menu.

Grub entry Rocky Linux 9

The entry indicates a successful upgrade from Rocky Linux 8 to 9.

Step 4: Post-Upgrade Steps

After the upgrade is complete, the system boots into Rocky Linux 9. Do the following:

1. Log in as the root user using the same credentials from the previous systems.

2. Clean up orphaned packages from Rocky Linux 8 with:

rpm -qa | grep -E 'el8[.-]' | xargs rpm -e

3. Continue using the system as usual and address any issues as they show up (such as missing dependencies or broken packages).

Conclusion

After going through the steps in this guide, you've successfully upgraded CentOS 7 to Rocky Linux 9. Read more about CentOS alternatives and why Rocky Linux is one of the best options.

phoenixNAP's knowledge base also features guides How to Migrate CentOS to AlmaLinux, How to Migrate CentOS to CentOS Stream, and How to Migrate CentOS to Ubuntu.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
Next you should read
What is Rocky Linux and Why Use It
November 10, 2022

This article gives information about Rocky Linux, an open-source CentOS successor. Learn the benefits of using Rocky Linux, its pros and cons, and whether it is the right choice for your business.
Read more
How to Install Docker on Rocky Linux
November 2, 2022

Docker is a Platform-as-a-Service tool for containerized app deployments. It uses Docker Engine to create and manage application containers...
Read more
How to Upgrade Rocky Linux 8 to 9
October 23, 2023

Rocky Linux is a distribution bug-for-bug compatible with RHEL 9. This tutorial shows how to upgrade from Rocky Linux version 8 to version 9.
Read more
Install Ansible on Rocky Linux
May 10, 2023

Ansible is an open-source Infrastructure-as-Code tool for infrastructure automation and application deployment. In this article, you will learn how to install...
Read more