Migrating CentOS to Rocky Linux with migrate2rocky
Safer Ground
Red Hat's announced re-envisioning of the popular CentOS Linux distribution [1] caused a major disruption in the Linux space. According to some surveys [2], CentOS was actually the third most popular Linux distribution in the world (after Ubuntu and Debian), and all those CentOS instances weren't just running on desktops. CentOS has carved out a role as a distro of choice for web servers, file servers, and even high-performance computing systems.
If you're wondering how the world will get along without CentOS, the first thing to know is that Red Hat didn't eliminate the CentOS brand , but they did move it upstream. CentOS used to be based on Red Hat Enterprise Linux source code, which meant that all the testing, troubleshooting, and verification that went into Red Hat's flagship distro also applied to CentOS. Now the CentOS developers will pull code from the RHEL development pipeline at an earlier point in the process, so it won't receive the value-added testing and verification that goes into RHEL. The newly named CentOS Stream distribution will fall somewhere between Fedora and RHEL in the development cycle, which significantly reduces its value to enterprise customers. Those thousands of CentOS users are now searching for a solution. Luckily, the Linux community specializes in in-flight adaptations to adjust to changing times. CentOS is not the only distribution based on RHEL source code. Some existed previously, and a few others launched after Red Hat's announcement. One of the newcomers is Rocky Linux [3]. The Rocky project, which launched one day after Red Hat announced that it was moving CentOS upstream, was started by one of the founders of CentOS, who envisions it as an enterprise-ready (and cluster-ready) alternative to RHEL. By now, most CentOS users know the clock is ticking, and they will need to find an alternative. (See the box entitled "CentOS Versions.") The heat is on now for users who want to jump ship. Migrating a server is a delicate operation, and many things can go wrong. If you're thinking about making the jump to Rocky Linux, the good news is that the developers provide a script that will automatically transition your system from CentOS to Rocky. The migrate2rocky script described in this article [4] supports upgrades from CentOS 8, and another script called migrate2rocky9.sh supports RHEL 9-based distributions. If you are still using CentOS 7, the recommended solution is to set up a new server with either Rocky 8 or 9, and manually install all services that were running on your old CentOS 7 server. (The ELevate project [5], which is sponsored by AlmaLinux, is working on an automated alternative for CentOS 7 migration that is still under development.) For CentOS 8 and 9 users, the migrate2rocky* scripts provide a fast and convenient way to escape the abandoned CentOS for higher ground.
CentOS Versions
The only CentOS version still receiving maintenance updates is CentOS 7, which is a relatively ancient system. CentOS 7 first appeared in 2014 and stopped receiving full updates in mid-2020. Still, you can find it on many servers, and several hosting providers offer images allowing you to start new projects on CentOS 7 servers. But because CentOS 7 is basically an old system, running the 3.x kernel, it is not supported by Rocky Linux – Rocky has no equivalent to CentOS 7.
CentOS 8 was the last version of the CentOS distribution, released in September 2019. This version corresponds to RHEL 8 (with 4.x kernels), of which multiple minor versions have been released since. Rocky Linux 8.4 appeared over a month after RHEL 8.4, whereas 8.5 and 8.6 were released less than a week after Red Hat's releases. RockyLinux 8 will be supported until June 2029.
In May 2021, Red Hat released RHEL 9 based on CentOS Stream and including Linux kernel 5.14. Two months later Rocky Linux 9 appeared. The distribution will be supported until the end of May 2032. If you are starting a new project and are considering using Rocky Linux, you should probably install the most recent version, Rocky 9. However, if you are migrating from CentOS 8, setting up Rocky 8 with the migrate2rocky script is a convenient option.
Preparing for Migration
If you are running CentOS 8 or one of the other distributions based on RHEL 8, the migration process is fairly simple. The first step is to make sure you have enough space on your partitions: 250MB on /usr , 1.5GB on /var , and 50MB on /boot . Failure to ensure you have enough disk space will break the migration process and might render your server unusable. Depending on the combination of packages, unexpected problems can arise, so it is important to make a full backup of the server before attempting the migration. All the following operations should run as root.
Connect to your server and fire up a session manager such as tmux or screen . You can install screen with:
dnf -y install screen
And then run it by typing:
screen -S migration
A tool like tmux
and screen
will allow the migration process to continue if anything happens to your connection (unlike plain SSH, which could terminate the migration process if your connection is cut short). To reconnect with a running session, enter:
screen -r migration
The next step is to make sure the system is up to date by running:
dnf update
If you see a message saying there is nothing to update, you are good to go. Otherwise, wait for the process to finish, then reboot the machine. The reboot will ensure that all system files have actually been updated.
The migrate2rocky script relies on the original CentOS repositories being present. If you haven't modified the default repositories, you should be fine. Otherwise, you need to make sure at least /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
is present and enabled.
Installing migrate2rocky
The best way to obtain migrate2rocky is using Git. If Git is not installed, set it up with:
dnf -y install git
Next, clone the repository that includes the migration script:
git clone https://github.com/rocky-linux/rocky-tools.git
If you are not particularly concerned with security, you can download the script directly using a tool such as Curl or Wget:
wget https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/migrate2rocky/migrate2rocky.sh
If you used the Git method, you need to change the directory:
cd rocky-tools/migrate2rocky/
Finally, make it executable with:
chmod u+x migrate2rocky.sh
Running the Migration Script
The script has only three options: -h to display a short help message, -r to start the conversion, and -V to verify the system. If you completed all the previous steps, you are now ready to start the main migration process (Figure 1):
migrate2rocky.sh -r
If you migrate a freshly installed server, the script should run without any trouble. On the other hand, very few people need to migrate a freshly installed CentOS 8 server because, if you are setting up a server now, it would make more sense to install Rocky Linux directly instead of installing CentOS. It is safe to assume the typical user of the migration script is working with a CentOS system that has been in use for a while and has some services that were originally installed a few years ago. It is impossible to test every possible combination of packages and custom software, but in our tests, migrate2rocky performed surprisingly well and managed to update a system with a number of customizations without any problems.
In our lab, we used a system with the Apache, PHP, MariaDB, and NGINX acting as a reverse proxy, as well as an ancient version of MongoDB from MongoDB repository left over from CentOS 7. The script replaced all relevant packages correctly (Figure 2) and everything worked fine after the reboot, including MongoDB.
Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.