Linux Software & Blog
Upgrade CentOS 4.8 to 5.3
Traditionally, the dist upgrade path that many were familiar with from the RH8/9->Fedora or similarly Fedora dist upgrades, have applied more or less to RHEL/CentOS but with the release of 4.5 and early releases of 5.0 the actual dist upgrade path was messy or nearly impossible. The early versions of 5.0 (up to 5.2) had excessive dependency issues with versions later than 4.4 for straight dist upgrades that would often result in a box blowing up on you or forcing a messy downgrade attempt of 4.5+ to 4.4 to try get things to dist upgrade. With more recent release updates the gap has closed and now dist upgrades on are far more reasonable to complete with little in the way of problems.
If you are currently running a version of RHEL/CentOS earlier than 4.8 (cat /etc/redhat-release) then please do a proper ‘yum update’ and get yourself on 4.8. Although this is intended for CentOS it “should” (read: at own risk) work on RHEL systems as well, in the unfortunate situation that something does blow up please post a comment and I will try to assist.
The first thing we must do is make sure none of our core binaries, libraries or other content is set immutable as this will cause a package to fail on installation. If you are running an earlier version of LES or you use immutable bits on system paths (sbin/bin/share/include/libexec/etc) then you should run the following:
wget http://www.rfxn.com/downloads/disable.les.rpmpkg
sh disable.les.rpmpkg
Once that is done we should go ahead and have a quick run through of cleaning up yum cache, double check that any pending updates are installed and rebuild the rpmdb:
rpm --rebuilddb
yum clean all
yum update
If for some reason the rpm rebuild hangs for more than a few minutes then you may need to manually clear the rpmdb files:
rm -f /var/lib/rpm/__db.00*
rpm --rebuilddb
If you run into any minor dependency issues for packages that are not essential, such as syslinux and lftp then you can either exclude them or better yet remove them. If you are not sure what a package does, then you should query it for description details and make an educated choice (rpm -qi PACKAGE):
rpm -e lftp syslinux mkboot
OR (but not recommended)
yum update --exclude=syslinux --exclude=lftp --exclude=mkboot
At this point you should be able to run a ‘yum update’ command with optional exclude and receive no errors (again, I recommend you remove conflicts items instead of using exclusions).
# yum update –exclude=nagios-plugins
Setting up Update Process
Setting up repositories
Reading repository metadata in from local files
Excluding Packages in global exclude list
Finished
No Packages marked for Update/Obsoletion
Now we are ready to get going, I have put together a small package that contains the needed packages for this upgrade in addition to a few that you might require to resolve dependency conflicts:
wget http://www.rfxn.com/downloads/CentOS-5up.tar.gz
tar xvfz CentOS-5up.tar.gz
cd CentOS-5up
We need to go ahead and setup the centos-release package as follows:
rpm -Uhv centos-release-*
If you see that CentOS-Base.repo was created as /etc/yum.repos.d/CentOS-Base.repo.rpmnew then go ahead and move it into the proper place:
mv /etc/yum.repos.d/CentOS-Base.repo.rpmnew /etc/yum.repos.d/CentOS-Base.repo
Now we are ready to go with kernel changes, this is an important part so pay attention. The key to successful upgrade is that you remove ALL OLD KERNELS as many packages will fail to install during the upgrade if they detect a release 4.x kernel due to minimum kernel version dependency checks. We will start with first installing the new kernel so it preserves grub templating:
rpm -ivh kernel-2.6.18-164.el5.i686.rpm kernel-devel-2.6.18-164.el5.i686.rpm --nodeps
NOTE: release 5.x has smp support integrated into the standard kernel, so no -smp version is required for mp systems
If you are running an older system the chances are you got allot of older kernel packages installed so make sure you get them all out of the way:
rpm -e $(rpm -qa | grep kernel | grep -v 2.6.18 | tr '\n' ' ')
You may end up with a few dependencies coming up such as lm_sensors and net-snmp if the list is fairly small and packages you do not recognize as critical (if unsure always query the package for info ‘rpm -qi PACKAGE’, remember you can reinstall them later):
# rpm -e $(rpm -qa | grep kernel | grep -v 2.6.18)
error: Failed dependencies:
kernel-utils is needed by (installed) lm_sensors-2.8.7-2.40.5.i386
The command the ended up being required on most of my servers to get the kernel packages and related dependencies came out to the following:
rpm -e $(rpm -qa | grep kernel | grep -v 2.6.18 | tr '\n' ' ') lm_sensors net-snmp net-snmp-devel net-snmp-utils
That said and done you should now only have 2 kernel packages installed which are the 2.6.18 release 5.x kernels, DO NOT under any circumstance continue if you still got 2.6.9 release 4.x kernels packages still installed, remove them!
# rpm -qa | grep -i kernel
kernel-2.6.18-164.el5
kernel-devel-2.6.18-164.el5
A cleanup of /etc/grub.conf may be required, though if all went as planned then the rpm command should have done this up for us but review it anyways for good measure. You should find that 2.6.18-164.el5 is the only kernel in the file, if it is not go ahead and clean it by removing all older entries for 2.6.9 kernels.
There is a known bug with python-elementtree package versions which cause yum/rpm to think the release 4.x version is newer than the 5.x version, to get around this without blowing up the entire python installation we need to remove the package from just the rpmdb as follows:
rpm -e --justdb python-elementtree --nodeps
We can now go ahead and use yum to start the upgrade process, this is a dry run and will take a few minutes to compile list of available packages and associated dependency checks. You should carry the exclude options, if any, that you used during the ‘yum update’ process as so to avoid unresolvable dependencies:
yum clean all
yum upgrade --exclude=nagios-plugins
You will end up with a small list of dependency errors, these should be resolved by again evaluating a packages need as a critical system component and either removing it with ‘rpm -e’ or excluding it with ‘–exclude’ (remember to query description with ‘rpm -qi PACKAGE’ if you are unsure what something does). In my case the packages that threw up red flags were stuff I had manually installed over time such as iftop and mrtg in addition to default installed samba, these can all safely be removed or excluded as you prefer (removal always safest to prevent dependency chain issues).
Error: Missing Dependency: libpcap.so.0.8.3 is needed by package iftop
Error: Missing Dependency: perl(Convert::ASN1) is needed by package samba
Error: Missing Dependency: libevent-1.1a.so.1 is needed bypackage nfs-utils
Error: Missing Dependency: perl-Socket6 is needed by package mrtg
Error: Missing Dependency: perl-IO-Socket-INET6 is needed by package mrtg
rpm -e iftop samba nfs-utils mrtg system-config-samba
At this point we should be ready to do a final dry run of with yum and see where we stand on dependencies, rerun the earlier ‘yum upgrade’ while making sure to carry over any exclude options you are using.
yum upgrade --exclude=nagios-plugins
You should now end up with a summary of actions that yum needs to perform, go ahead and kick it off… this will take a bit to complete so go grab some coffee/jolt/redbull and maybe a small snack cause it could be a long night if this blows up on you.
Transaction Summary
=============================================================================
Install 183 Package(s)
Update 327 Package(s)
Remove 0 Package(s)
Total download size: 299 M
Is this ok [y/N]:
Once yum has completed (hopefully without major errors) we need to fix a few things, the first is the rpmdb needs a rebuild due to version changes that will cause any rpm commands to fail:
# rpm -qa
rpmdb: Program version 4.3 doesn’t match environment version
error: db4 error(-30974) from dbenv->open: DB_VERSION_MISMATCH: Database environment version mismatch
error: cannot open Packages index using db3 – (-30974)
error: cannot open Packages database in /var/lib/rpm
This can be fixed by running the following to manually rebuild the rpmdb:
rm -f /var/lib/rpm/__db.00*
rpm --rebuilddb
yum clean all
The next issue on the list is python-elementtree and python-sqlite, one or both of these may have ended up in a broken state that will cause all yum commands to break, so we will go ahead and reinstall both of these for good measure:
rpm -e --justdb python-elementtree --nodeps
rpm -ivh python-elementtree-1.2.6-5.el5.i386.rpm
rpm -ivh python-sqlite-1.1.7-1.2.1.i386.rpm --nodeps --force
The yum command should now work, go ahead and run it with no options, if you do not get any errors you are all sorted.
Hopefully the install went well for you, the only thing left to do is go ahead and reboot the system; this is the last point at which you have to make backups (but we all maintain backups right?). For the sake of avoiding a heart attack if the system goes into an fsck, we will reboot with the -f option to skip fsck:
shutdown -rf now
That’s a wrap, I hope you found this HowTo useful, if you did run into any issues then go ahead and post them into the comments field and I will try to assist but when in doubt typically google is the fastest alternative.
| Print article | This entry was posted by Ryan M. on October 20, 2009 at 3:10 am, and is filed under HowTo. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 2 months ago
This works perfectly fine still even going to CentOS 5.5. Of course the kernel that this installs is from 5.3 but it still has no issues as such, as once you get to the end of the howto, that will in turn get replaced with the latest 5.5 kernel.
about 2 months ago
Nevermind about publish dates, I see it now
[QUOTE]
This entry was posted by Ryan M. on October 20, 2009 at 3:10 am, and is filed under HowTo
[/QUOTE]
about 2 months ago
Hey Ryan, I ran across the following copy of your howto:
http://planet.admon.org/howto/update-centos-4-to-centos-5-remotely/
I know your article was published first but cannot verify since your articles have no publish dates (which drives me nuts).
I haven’t yet tried this but have a few candidates for it so may soon.
about 2 months ago
many many thanks, this project with a little tweaking made it possible for to install centos 5.4 and BlueOnyx on to my Cobalt RaQ550
I intend to publish my method and will use some of this post and I will give credit to you
once again many many thanks
about 9 months ago
Hi Ryan,
You’re right, I forgot udev and similar can/will cause issues and prevent booting.
Regards
about 9 months ago
Ricardo,
Rebooting the system to the new kernel is done last as it is a major release change from CentOS 4.x’s 2.6.9 kernel tree to 5.x’s 2.6.18 kernel tree. Some software such as udev may not operate properly on the new kernel till all associated packages are updated to 5.x versions , this can leave the server in an unusable state if rebooting before that point or lock it up on boot during the udev initialization process.
about 9 months ago
One more thing: shouldn’t you reboot into the new 2.6.18 kernel before removing the 2.6.9 versions?
I know it’s not necessary, but removing the currently running kernel gives me the creep
about 9 months ago
Hi, just a small thing, I think rpm -q should be rpm -qi as you intend to view the info of the package and not only its name. At least on 5.x it works that way, I haven’t tried 4.x.
Also, users might want to reinstall some of the packages uninstalled during the update process, so they should take note of what they remove.
Regards,
about 9 months ago
many many thanks, this project with a little tweaking made it possible for to install centos 5.4 and BlueOnyx on to my Cobalt RaQ550
I intend to publish my method and will use some of this post and I will give credit to you
once again many many thanks