Migrate to Rocky Linux
This guide walks you through using the official Rocky Linux migration tool migrate2rocky.sh to migrate from CentOS 8, CentOS Stream, RHEL, AlmaLinux, Oracle Linux, and other EL-compatible distributions to Rocky Linux.
Prerequisites
Section titled “Prerequisites”Before starting the migration, confirm the following:
- Operating system version: CentOS 8, CentOS Stream 8/9, RHEL 8/9, AlmaLinux 8/9, Oracle Linux 8/9, or other EL8+ compatible systems
- Disk space: At least 5 GB of free space on the
/varpartition - Network connectivity: The server must be able to access the internet to download Rocky Linux packages
- Root privileges: The migration process requires root or sudo privileges
- Full backup: Be sure to create a system snapshot or full backup before migrating
Important:
migrate2rocky.shcurrently supports EL8 and EL9 systems only. CentOS 7 users need to upgrade to EL8 first before using this tool.
Record the Current System State
Section titled “Record the Current System State”$ cat /etc/os-release$ rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' | sort > ~/packages-before-migration.txt$ systemctl list-units --type=service --state=running > ~/services-before-migration.txt$ cp -a /etc/yum.repos.d/ ~/yum.repos.d.bak/$ sudo lvcreate --size 10G --snapshot --name pre_migration_snap /dev/mapper/centos-rootDownload the migrate2rocky.sh Tool
Section titled “Download the migrate2rocky.sh Tool”migrate2rocky.sh is officially maintained by Rocky Linux and hosted on GitHub.
$ sudo dnf install -y curl gitThere are two ways to obtain the migration script:
Option 1: Download the Script Directly
Section titled “Option 1: Download the Script Directly”$ curl -O https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/migrate2rocky/migrate2rocky.shOption 2: Clone the Entire Repository
Section titled “Option 2: Clone the Entire Repository”$ git clone https://github.com/rocky-linux/rocky-tools.git$ cd rocky-tools/migrate2rocky/$ ls -la migrate2rocky.shPerform the Migration
Section titled “Perform the Migration”Basic Migration (CentOS 8 / CentOS Stream 8)
Section titled “Basic Migration (CentOS 8 / CentOS Stream 8)”$ sudo bash migrate2rocky.sh -rThe -r flag performs a full migration (including dnf distro-sync). The script automatically completes the following steps:
- Detects the current operating system and version
- Checks for known incompatibilities
- Downloads Rocky Linux GPG keys
- Replaces system identifier packages (
*-release,*-logos,*-gpg-keys, etc.) - Runs
dnf distro-syncto synchronize all packages to Rocky Linux versions
Migrating EL9 Systems
Section titled “Migrating EL9 Systems”For CentOS Stream 9, AlmaLinux 9, and other EL9 systems:
$ curl -O https://raw.githubusercontent.com/rocky-linux/rocky-tools/main/migrate2rocky/migrate2rocky9.sh$ sudo bash migrate2rocky9.sh -rMigration Path for CentOS 7
Section titled “Migration Path for CentOS 7”CentOS 7 cannot be directly migrated to Rocky Linux. You need to use the ELevate project to upgrade to EL8 first.
$ sudo yum install -y http://repo.almalinux.org/elevate/elevate-release-latest-el7.noarch.rpm$ sudo yum install -y leapp-upgrade leapp-data-rocky$ sudo leapp preupgrade$ sudo cat /var/log/leapp/leapp-report.txt$ sudo leapp upgradeAfter reboot, the system will boot directly into Rocky Linux 8.
Handling Third-Party Repositories
Section titled “Handling Third-Party Repositories”Third-party repositories are the most common source of issues during migration. It is recommended to handle them properly before migrating.
Disable Third-Party Repositories Before Migration
Section titled “Disable Third-Party Repositories Before Migration”$ dnf repolist --enabled$ sudo dnf config-manager --set-disabled epel epel-modular 2>/dev/null$ sudo dnf config-manager --set-disabled remi* ius* rpmfusion* elrepo*Restore Third-Party Repositories After Migration
Section titled “Restore Third-Party Repositories After Migration”After migration, install the third-party repository packages for the corresponding Rocky Linux version:
$ sudo dnf install -y epel-release$ sudo dnf install -y epel-release$ sudo dnf install -y https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpmHandling Katello / Satellite Managed Systems
Section titled “Handling Katello / Satellite Managed Systems”If the system is managed by Katello or Red Hat Satellite:
$ sudo subscription-manager unregister$ sudo subscription-manager cleanReconfigure management tools as needed after migration.
Post-Migration Verification
Section titled “Post-Migration Verification”Confirm the System Version
Section titled “Confirm the System Version”$ cat /etc/os-releaseExpected output:
NAME="Rocky Linux"VERSION="8.9 (Green Obsidian)"ID="rocky"$ rpm -qa | grep rocky-releaseCheck for Leftover Packages
Section titled “Check for Leftover Packages”$ rpm -qa --qf '%{NAME} %{VENDOR}\n' | grep -v -i rocky | grep -v "(none)" | sort$ rpm -qa | grep -i centos$ sudo dnf remove centos-logos centos-indexhtml centos-backgrounds 2>/dev/nullSynchronize All Packages
Section titled “Synchronize All Packages”$ sudo dnf distro-sync -yRebuild GRUB Boot Configuration
Section titled “Rebuild GRUB Boot Configuration”$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg$ sudo grub2-mkconfig -o /boot/efi/EFI/rocky/grub.cfgReboot and Final Verification
Section titled “Reboot and Final Verification”$ sudo reboot$ uname -r$ systemctl list-units --type=service --state=failed$ rpm -qa --queryformat '%{NAME}\n' | sort > ~/packages-after-migration.txt$ diff ~/packages-before-migration.txt ~/packages-after-migration.txtCommon Issues
Section titled “Common Issues”Script reports “Unsupported OS”
Section titled “Script reports “Unsupported OS””migrate2rocky.sh only supports EL8 systems. If you are running CentOS 7, you need to use the ELevate project to upgrade to EL8 first. For EL9, use migrate2rocky9.sh.
$ rpm -E %{rhel}Error: “Could not download Rocky Linux GPG keys”
Section titled “Error: “Could not download Rocky Linux GPG keys””Network issues preventing GPG key download.
$ curl -I https://dl.rockylinux.org/$ sudo rpm --import https://dl.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-8If the server is in China, consider using a mirror for faster access.
dnf distro-sync reports package conflicts
Section titled “dnf distro-sync reports package conflicts”$ sudo dnf distro-sync -y --allowerasing 2>&1 | tee /tmp/distro-sync.log$ sudo dnf distro-sync -y --exclude=<problematic-package-name>$ sudo dnf clean all$ sudo rm -rf /var/cache/dnf$ sudo dnf makecache$ sudo dnf distro-sync -ySSH connection drops after migration
Section titled “SSH connection drops after migration”If SSH disconnects during migration, reconnect through the console (IPMI / KVM / cloud platform console).
Recommendation: Run the migration script inside a
screenortmuxsession to prevent network interruptions from terminating the migration process.
$ tmux new -s migration$ sudo bash migrate2rocky.sh -rIf the tmux session disconnects, reattach:
$ tmux attach -t migrationSystem fails to boot after migration
Section titled “System fails to boot after migration”Refer to the Boot Issues Troubleshooting page. Typically, the kernel and GRUB need to be reinstalled from rescue mode.
Next Steps
Section titled “Next Steps”- Post-Migration Checklist — Complete post-migration verification steps
- Migration Overview — Compare migration options