Linux Tricks and Techniques

For Linux Experts

Use the website for easy leaning of Linux

Friday, 17 June 2016

Segmentation Fault error during the Package Installation using RPM.

DB corruption recovery process - The RPM database has become corrupt and recovery is desired.

While configuring YUM server in one of the RHEL5.5 based server I was getting an Segmentation Fault error and tried all the ways but I was not able to resolve this. With the help of support team i came to know that the issue is related to DB corruption in the server.Before this when i was trying to install any package using rpm command it was showing the segmentation error which was due to corrupt DB. To recreate the DB follow the below steps and then tried with rpm and it was working then.

1. As always it best to start by taking a backup before attempting to repair.

# cd /var/lib
# tar -zcvf /var/preserve/rpmdb-$(date +%Y-%m-%d_%H-%M-%S).tar.gz rpm

Note: This tar backup can be used if the attempt to recover the RPM database has issues.

2. Verify integrity of the Packages file:

# cd /var/lib/rpm
# rm -f __db* # to avoid stale locks
# /usr/lib/rpm/rpmdb_verify Packages

If the last command shown in method 2 returns without any error, then we can be sure about the integrity of the rpm database. You can also issue the following command to be sure of the success of the rpmdb_verify command.

$ /usr/lib/rpm/rpmdb_verify Packages
$ echo $?

A return value of 0 from echo $? means that the last command has been executed successfully.

3. If the above verify reports success, go to step 6.

4. If the above verify reports any errors, a dump and load of the database is required.

# mv Packages Packages.orig
# /usr/lib/rpm/rpmdb_dump Packages.orig | /usr/lib/rpm/rpmdb_load Packages

5. Verify the newly loaded Packages file, as well as rpm output.

# /usr/lib/rpm/rpmdb_verify Packages
# rpm -qa >/dev/null # Validating there are no errors
# rpm -qa # Validating list of installed RPMs

6. If no errors and everything looks good, rebuild the RPM indexes

# rpm -vv --rebuilddb

7. Once again verify RPM database:

# cd /var/lib/rpm
# /usr/lib/rpm/rpmdb_verify Packages

If the above recovery steps fail or throw errors, restoring /var/lib/rpm directory from a recent system backup may be your best option. Remember to not overwrite the tar backup as it may still be valuable.

If you have another machine having the exactly same installed package set, you can rebuild the rpm db with Packages file on the machine.

If you have a rpm database in other directory except for /var/lib/rpm and it's corrupted, you will need to do the same things to the rpm database, not one in /var/lib/rpm. The rpm command has --root option to specify the root directory for the rpm database. Especially, please take care of therpm -vv --rebuilddb command to rebuild the rpm database. For example, if you are using /opt/var/lib/rpm for a directory including rpm database, run this command rpm -vv --rebuilddb --root /opt.


No comments:
Write comments