On Tue, 2002-11-12 at 13:38, David Guntner wrote:
> I'm getting an error when I try to run rpm on anything.  The message I get is:
> 
> rpmdb: region error detected; run recovery.
> error: db4 error(-30981) from dbenv->open: DB_RUNRECOVERY: Fatal error, run 
> database recovery
> error: cannot open Packages index using db3 -  (-30981)
> 
> 
> There doesn't seem to be a recover option for rpm.  "rpm --rebuilddb" gets 
> that same error message.  Anyone know what needs to be done to repair the RPM 
> database?
> 
>                   --Dave

David,

Some time back there were some peeps that encountered similar troubles. 
There was one fellow that developed a procedure for handling this
problem, and I haven't seen it discussed anywhere else except on the
Mandrake lists.  This recovery procedure would be a fantastic thing to
be worked into the Mandrake distro as a recovery tool, cause I don't
think any other distro has it.  Anyways, I searched the archives and dug
it up:

_____________________________________________________________________


 On one of my Mandrake Linux systems, I had once this problem: 
     [pascal@hermes pascal]$ su
     Password: 
     [root@hermes pascal]# rpm -q -a
     failed to open //var/lib/rpm/packages.rpm
 
     rpmQuery: rpmdbOpen() failed
     [root@hermes pascal]# rpm --rebuilddb
     failed to open //var/lib/rpm/packages.rpm
 
     [root@hermes pascal]# rpm --initdb
     [root@hermes pascal]# rpm -q -a
     failed to open //var/lib/rpm/packages.rpm
 
     rpmQuery: rpmdbOpen() failed
     [root@hermes pascal]# rpm --version
     RPM version 3.0.3


Well, clearly the RPM database was completely out of usage. I had to
rebuild it.
You may think that it's simply a matter of using : 

   rpm --rebuilddb

 However, I learned that --rebuilddb is REALLY AND COMPLETELY USELESS.
Maybe the
 authors and contributors to rpm could take some idea from this NFAQ to
actually
 implement a true --rebuilddb option. 

The main idea of the process is to use: 

    rm -f /var/lib/rpm/* ; rpm --initdb

 and: 

    rpm -i -v --nodeps --noscripts --notriggers --excludepath /
packages...

 to fill a package database without really installing anything (not
overriding
 installed files, not running any script, ...). This is done in the
seventh step;
 everything before I made to recover a list of installed packages. 

This is not perfect, since some packages I have upgraded or modified the
sources
and upgraded. I should have checked for /usr/src/RPMS too; I'll update
the
database later by hand to synchronize it with the handful of packages I
touched
after the initial installation. 



+------------------------------------------------------------------+
| COOKBOOK PROCEDURE TO REBUILD A RPM DATABASE DAMAGED BEYOND HOPE |
+------------------------------------------------------------------+          

####
#### BEWARE, THIS IS NOT AN AUTOMATIC SCRIPT!
####
#### Use this only as a guideline to rebuild your rpm database.
####


#####
# 1 # Find the files currently installed.
#   # ON THE HOST WHO LOST ITS RPM DATABASE.
#####

find / -print | sort > /tmp/dsk-contents



#####
# 2 # Find all the files installed by the installation RPMs, 
#   # with their corresponding RPM.
#####

losetup /dev/loop0  /mnt/usr3/mandrake/mandrake61-1.iso 
mount -o ro -t iso9660 /dev/loop0 /mnt/cdrom

cd /mnt/cdrom/Mandrake/RPMS
rm -f /tmp/rpm-contents
for f in *.rpm ; do 
    rpm -q -l -p $f \
    | awk -v pn=$f '{printf "%s:%s\n",pn,$0;}' >> /tmp/rpm-contents
done
sort -t: +1 -o /tmp/rpm-contents /tmp/rpm-contents



#####
# 3 # Obtain the actually installed RPMs.
#####



gzip -d < lgetvalue-src.tar.gz | tar xf -
cd lgetvalue-src
make all test


./lgetvalue    --field-separator=: \
               --key-position=2 \
               --value-position=1 \
               /tmp/rpm-contents /tmp/dsk-contents \
| sort -u > /tmp/rpm-installed



#####
# 4 # Reinitialize a new rpm database.
#####

mv /var/lib/rpm /var/lib/rpm-damaged-beyond-hope
mkdir /var/lib/rpm
rpm --initdb



#####
# 5 # Let rpm say what problems there may be 
#   # (trying to do a pseudo-installation.
#####

cd /mnt/cdrom/Mandrake/RPMS
rpm -i -v --noscripts --notriggers --excludepath /  `cat
/tmp/rpm-installed`



#####
# 6 # Correct the list of installed RPMs.
#####

emacs /tmp/rpm-installed


#####
# 7 # Rebuild the rpm data base, without installing any file 
#   # nor running any script.
#####

rpm -i -v --nodeps --noscripts --notriggers --excludepath /  \
    `cat /tmp/rpm-installed `


#####
# 8 # Check you have a valid rpm database.
#####

rpm -q -a 

____________________________________________________________________


Hope this helps...

--LX


-- 
���������������������������������������������������
Kernel  2.4.18-6mdk     Mandrake Linux  8.2
Enlightenment 0.16.5-11mdk    Evolution  1.0.2-5mdk
Registered Linux User #268899 http://counter.li.org/
���������������������������������������������������


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to