Recovering from a corrupted RPM database

Although everything is done to ensure that your RPM databases are intact, your RPM database may become corrupt and unuseable. This happens mainly if the filesystem on which the rpm db resides is suddenly inaccessible (full, read-only, reboot, or so on).

This recipe will show you the two ways in which you can attempt to restore your RPM database.

Getting ready

Verify that your system is backed up in some way.

How to do it…

We'll start with the easiest option and the one with the highest success rate in these steps:

  1. Start by creating a backup of your corrupt rpm db, as follows:
    ~]# cd; tar zcvf rpm-db.tar.gz /var/lib/rpm/*
    
  2. Remove stale lock files if they exist through the following command:
    ~]# rm -f /var/lib/rpm/__db* ...

Get Red Hat Enterprise Linux Server Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.