rhel 7 to centos 7 migration: the road to happiness

So in my professional life I do a lot of work with Red Hat Enterprise Linux. It’s stable, rock-solid (mostly) and easy to use… but however unlike many distros, it comes with a subscription. This is fine: developers gotta eat, and however many anti-capitalist rants people like to go off on, if Linux wasn’t making money then it wouldn’t be as good as it is – a lot of the kernel is written by engineers at giant conglomerates.

But on the other hand… subscriptions need to be managed and you can’t just hand them out like candy. If you install RHEL on every single machine you have, that’s a lot of subscriptions and as soon as you do that, the finance department will come after you for the amount of shrapnel you’re dropping on keeping all those machines in subscription so you can patch and maintain them.

If, however,you have an old server you need to keep alive but also need to migrate away from RHEL as you can’t justify keeping it up and running with a subscription, you’re in luck. CentOS is basically RHEL, but with all the branding stripped out and most importantly, it doesn’t cost anything so you can preserve said old server. Migration is indeed possible! However, it can be somewhat confusing as to how to convert a RHEL installation to a CentOS one. Perhaps, uh… unintentionally the RHEL migration guide has fallen out of being updated and so it can be a bit difficult to get it going.

Here on The Answer’s 42 I have a habit of writing these “the road to happiness” posts which are generally posts about annoying little niggly things that I’ve encountered in development work, or in getting things installed… and this is very much worth of a “road to happiness” as the RHEL to CentOS migration can make you very unhappy. It drove me up the wall for an afternoon as I kept on getting things wrong and having to restore back to the snapshot of the machine I’d taken, which leads me to my first point…

If you’re going to do this, take a snapshot of your VM, or image your hard drive. It’s easy to fuck things up.

I typed that in bold, because I spent enough time swearing at my terminal as I tried uninstalling things and reinstalling them, and ending up with an unholy shitstorm of an installation. Technically this was a production machine, but also a machine that needed to be migrated and so luckily no-one was that bothered that it was messed up. But on the other hand, if you bring down say your main Jenkins server… yeah, have that backed up.

Another tip I have: if you’re using VMware VSphere (or anything with cloning functionality), clone the VM first. This is a huge advantage to have if the VM you’re trying to migrate is a) important and b) prone to “novel” behaviour. It’s always good to have something to practise on that’s as close to the real thing you can get, and if you’re just messing up a clone you’re going to delete anyway to learn things, then no harm done if you make it unbootable. Just restore from a snapshot and try again!

Also, before commencing down the road to RHEL migration happiness… YMMV on this. I was fortunate in that my installation was very well maintained, and didn’t have much of a mess before I came along. If you have additional interesting things happening on your RHEL installation you may have to do some extra steps here. This is just my experience (but I hope it will help someone out there trying to do the same thing).

So, to start with we need to remove all of the Red Hat repos and other assorted gubbins from the system:

# remove redhat stuff
yum remove rhnlib redhat-support-tool redhat-support-lib-python
# remove further redhat stuff... probably bad form to use --nodeps but I needed it...
rpm -qa| egrep "rhn|redhat" | xargs rpm -e --nodeps
# remove the redhat directories as they will fight anything else we try to install
rm -rf /usr/share/redhat-release* /usr/share/doc/redhat-release*

Once the Red Hat stuff has been removed, we then want to install the CentOS 7 key and install the CentOS 7 repos:

rpm --import http://mirror.centos.org/centos/7/os/x86_64/RPM-GPG-KEY-CentOS-7
# install the needed repos to replace RHEL stuff - used version_number here to stop it aging so badly
yum localinstall -y http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-(version_number).el7.noarch.rpm
yum localinstall -y http://mirror.centos.org/centos/7/os/x86_64/Packages/centos-logos-(version_number).el7.centos.noarch.rpm
yum localinstall -y http://mirror.centos.org/centos/7/os/x86_64/Packages/centos-release-(version_number).2.el7.centos.x86_64.rpm

This should have downloaded and installed all the repos you need to convert the Red Hat installation to being a CentOS one. Next, we need to get rid of the subscription manager… otherwise it’ll be annoying us by telling us that we are not subscribed for the rest of time.

vim /etc/yum/pluginconf.d/subscription-manager.conf
# set enabled = 0 in subscription-manager.conf

Once this has been done, we just need to clear the existing packages, and then update the system using the new ones installed, then update the GRUB config to reflect that it’s now a CentOS installation:

# clean yum database
yum clean all
# update packages
yum update
# run grub to update the records
grub2-mkconfig -o /boot/grub2/grub.cfg

So, you’ve managed to remove the Red Hat branding, silenced the subscription manager and installed the CentOS packages you need. The next step is to reboot, and hopefully you should see something like this:

Image result for centos grub screen

which will show that you’ve successfully changed your Red Hat installation over to a (free) CentOS one! Hopefully, following this (or one of several articles) has made your migration process as pain-free as possible.

And there, my friends, is (hopefully) the RHEL to CentOS migration road to happiness.

Advertisement

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s