How to recover rpm database using /var/log/rpmpkgs?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux (RHEL) 4
  • Red Hat Enterprise Linux (RHEL) 5
  • Red Hat Enterprise Linux (RHEL) 6

Issue

  • How to recover rpm database from scratch from file /var/lib/rpm/Packages?
  • How to rebuild rpm database using the /var/log/rpmpkgs file?
  • Completed steps to rebuild rpm database as mentioned in How to rebuild RPM database on a Red Hat Enterprise Linux system? without any error message, but rpm database is not rebuilt and does not list all packages installed. How to rebuild rpm database?

Resolution

Note: In Red Hat Enterprise Linux 6, the daily cron file to create /var/log/rpmpkgs is provided by the rpm-cron package, available in the optional repository, not the main 'rpm' package. So, if you do not install the package, /var/log/rpmpkgs is not available on Red Hat Enterprise Linux 6.

Note: Even if /var/log/rpmpkgs is not available, the yumdb info command can output the installed package list (only for packages installed with yum). If no packages were installed with rpm, then a list of installed packages like /var/log/rpmpkgs can therefore be created from the output of 'yumdb info'.

  • Create the work directory:
# mkdir /var/tmp/recoverdb
  • Download all the necessary rpm files into the work directory:

    • For Red Hat Enterprise Linux 4 systems:

      # cat /var/log/rpmpkgs | sed 's,\.[^.]\+\.rpm$,,g' | while read nvr
          do
            up2date --tmpdir=/var/tmp/recoverdb --get $nvr
          done
      
    • For Red Hat Enterprise Linux 5 & 6 systems:

      • Confirm yum-utils package is installed on system.

        # yum install yum-utils
        
      • If this installation fails, download the package and install it manually:

        # rpm -Uvh --nodeps --force yum-utils*.rpm
        
      • Once yum-utils is installed, download all required packages.

        # cat /var/log/rpmpkgs | sed 's,\.[^.]\+\.rpm$,,g' | while read nvr
            do
              yumdownloader --destdir=/var/tmp/recoverdb $nvr
            done
        
  • Rebuild the rpm database:

# cd /var/tmp/recoverdb
# ls *.rpm > MANIFEST
# rpm -Uvh --noscripts --notriggers --force --justdb MANIFEST
  • Run yum / up2date to ensure the filesystem and the rpmdb are in sync.

    • For Red Hat Enterprise Linux 4 systems

      # up2date -uf
      
    • For Red Hat Enterprise Linux 5 & 6 systems

      # yum update
      
  • In the event of an error such as:

# rpm -Uvh --noscripts --notriggers --force --justdb MANIFEST
error: Failed dependencies:
        glibc-common = 2.3.4-2.57 is needed by (installed) glibc-2.3.4-2.57.i686
        glibc-headers = 2.3.4-2.57 is needed by (installed) glibc-devel-2.3.4-2.57.i386    

Download the missing rpms and place them in the directory.

Comment

Diagnostic Steps

  • If following packages are not present in the rpm database, then up2date will not work. Download and install them manually on the system
    basesystem, glibc, bash, mktemp, setup, redhat-release

e.g.,:

basesystem-8.0-4.noarch.rpm 
glibc-2.3.4-2.36.i686.rpm
bash-3.0-19.3.i386.rpm
mktemp-1.5-20.i386.rpm
setup-2.5.37-1.7.noarch.rpm
redhat-release-4AS-9.i386.rpm

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments