Thursday, June 18, 2009

How to fix a corrupted RPM database

When I originally tried out Fedora 7, I experienced lots of problems. One of the biggest was that ACPI didn't work. ACPI is the component that lets you know (among other things) when your laptop is on battery power, plugged in, how much time you have left on your battery, etc. So one time, I was plugged into the network, downloaded half a gigabyte worth of updates, and started updating my system. Halfway through the update, my laptop crashed! Why? Because I had plugged it in but forgot to turn the switch on :( The net result, of course, was that I corrupted lots of files, including my rpm databases. If this ever happens to you, you are probably wondering exactly what I was - what can I do to fix my RPM database without reinstalling my OS?

After some googling, I have found the answer for you. All you need is a bit of command line wizadry, so first of all open up a terminal (you will need root privileges for this). Following this, run the following 3 commands:
  • rm -f /var/lib/rpm/__db*
  • /usr/lib/rpm/db_verify /var/lib/rpm/Packages
  • rpm --rebuilddb
This first of all removes your old, corrupted databases. Then it procedes to work out exactly what is installed on your computer, and rebuild your RPM databases with these packages.

Hope this is helpful to someone (note that I haven't tested this with newer version of Fedora, but it should still work just the same).