Wednesday, December 24, 2008

Recovering from corrupted RPM database

When accessing the yum command, the error we got was similar to this.

error: rpmdb: damaged header #67 retrieved -- skipping.
Traceback (most recent call last):
File "/usr/bin/yum", line 29, in ?
yummain.main(sys.argv[1:])
File "/usr/share/yum-cli/yummain.py", line 82, in main
base.getOptionsConfig(args)
File "/usr/share/yum-cli/cli.py", line 206, in getOptionsConfig
errorlevel=opts.errorlevel)
File "/usr/lib/python2.4/site-packages/yum/__init__.py", line 132, in doConfigSetup
self.conf = config.readMainConfig(startupconf)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 598, in readMainConfig
yumvars['releasever'] = _getsysver(startupconf.installroot, startupconf.distroverpkg)
File "/usr/lib/python2.4/site-packages/yum/config.py", line 667, in _getsysver
hdr = idx.next()
StopIteration

Solution is straight enough, to repair the RPM database. So how do we repair the RPM database. The straight forward method is to, remove the /var/lib/rpm/__db* and the run

rpm --rebuilddb
I believe I discussed this issue earlier in this blog itself. But that didn't fix in the first go and had to reissue the command again. And that time it did fix it.

Another solution to fix the issue is using the db_dump and db_load from the db4-utils package. This process involve re-building master package metadata file /var/lib/rpm/Packages

mv Packages Packages-BAKUP
db_dump Packages-BAKUP | db_load Packages
rpm -qa
rpm --rebuilddb

/usr/lib/rpm/rpmdb_verify Packages

That should fix it. Check out http://people.redhat.com/berrange/notes/rpmrecovery.html for yet another solution. Complicated and may not need it.

No comments: