четверг, 14 января 2016 г.

Migrate from Oracle Linux 6.7 to CentOS 6.7

Source. My big thanks to author.

The following howto will show you how to migrate an Oracle Linux 6.7 OS instance to CentOS 6.7. In my tests I used a fully patched Oracle Linux 6.7 VM running Oracle Unbreakable Enterprise Kernel (UEK2) and the default package selection for Software Development Workstation.

1. Update the OS, make sure kernel-uek is the default and reboot into runlevel 3


yum update
sed -i 's/DEFAULTKERNEL=kernel/DEFAULTKERNEL=kernel-uek/' /etc/sysconfig/kernel
sed -i 's/id:5/id:3/' /etc/inittab
init 6

After reboot login as root and run the following commands:

2. Remove Oracle logos, release notes and other RPMs that may cause dependency issues later in the process (those will be automatically reinstalled)


rpm -e --nodeps `rpm -qa | grep rhn` oracle-logos oraclelinux-release \
oraclelinux-release-notes redhat-indexhtml dmidecode kpartx netxen-firmware \
redhat-release-server

3. Import the CentOS GPG keys


rpm --import http://mirror.centos.org/centos/6.7/os/x86_64/RPM-GPG-KEY-CentOS-6
rpm --import http://mirror.centos.org/centos/6.7/os/x86_64/RPM-GPG-KEY-CentOS-Debug-6

4. Install CentOS release files that include repository configuration


rpm -Uvh http://mirror.centos.org/centos/6.7/os/x86_64/Packages/centos-release-6-7.el6.centos.12.3.x86_64.rpm

At this stage the OS info has already changed (/etc/redhat-release has been updated with CentOS version and the yum repositories point to CentOS URLs) but we first need to update yum before we go on.
 

5. Installing new yum


cd /root
wget http://mirror.centos.org/centos/6.7/os/x86_64/Packages/yum-3.2.29-69.el6.centos.noarch.rpm
wget http://mirror.centos.org/centos/6.7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm

The yum package has one dependency yum-plugin-fastestmirror so we need to install that first.
 
yum --disablerepo=* localinstall yum-plugin-fastestmirror-1.1.30-30.el6.noarch.rpm

Now we can install the new yum. Note that we don’t actually update the already installed package, instead we are downgrading it. We do that because the Oracle Linux yum RPM has an additional suffix added to its %{RELEASE} tag which makes it higher in version than the CentOS package which means we cannot update the former with the latter, but we are allowed to downgrade. As you will see below, there are more packages with the modified RELEASE tag in Oracle Linux 6.
 
yum --disablerepo=* downgrade yum-3.2.29-69.el6.centos.noarch.rpm

Now the Oracle yum RPM has been replaced by the CentOS package so after cleaning up the old cache we should be able to access the new repositories.
 
yum clean all
yum repolist

6. Downgrade packages with changed suffix

As said above there are more packages with modified RELEASE tags. I identified 130 RPMs which have different tags compared to the CentOS version. The two possible additional tag suffixes are 0.1 or 0.2. We’re going to query all RPMs and downgrade them together with a few more RPMs that I found to be causing dependency issues (again, those will be automatically reinstalled later in the migration process).

rpm -qa | egrep "\.0\.(1|2)\.el6" >> to_downgrade
cat to_downgrade | while read package; do rpm -q $package --qf '%{NAME}\n' >> dgrlist; done
yum downgrade `cat dgrlist` dbus-glib-devel.x86_64 dbus-glib.x86_64 kexec-tools

7. Reinstall remaining Oracle packages


A complete migration means we get rid of all Oracle packages and replace them with their corresponding CentOS version. To do that we’ll use yum‘s reinstall function. Basically an installed package can be reinstalled if the same version is found in the available repositories. We’re using this yum feature to identify all packages by Vendor (Oracle America) and have them replaced with the same package versions from the CentOS repository.
rpm -qa --qf '%{NAME}:%{VENDOR}\n' |  grep  Oracle >> oraclepacks
cat oraclepacks | awk -F":" '{print $1}' >> oraclepacks2
yum reinstall `cat oraclepacks2`
On my machine there were 1350 packages to reinstall. This can take some time as yum needs to download all packages.

8. Update the OS


After all packages have been either downgraded or reinstalled we need to perform a full OS update to ensure there were no leftovers in the migration process and we run the latest RPMs available in the CentOS repositories.
yum update

9. Reboot to CentOS kernel


At this point the only remaining Oracle RPMs should be the kernel-uek packages. Those were not processed since we were running kernel-uek. We need to boot into a newly-installed CentOS kernel and then we’ll be able to remove kernel-uek.
  • sed -i 's/DEFAULTKERNEL=kernel-uek/DEFAULTKERNEL=kernel/' /etc/sysconfig/kernel
  • modify /etc/grub.conf and set a new default CentOS kernel
  • init 6

10. Finally we can remove kernel-uek and install new kernel headers


rpm -e --nodeps `rpm -qa | grep kernel-uek`
yum install kernel-headers

We can perform a final check to ensure there are no problems with the installed packages:

yum check
 
That’s it, the migration is complete. Hope this helps.