Recovering after /var/lib/dpkg is lost on Debian
What do you do if you accidently lose /var/lib/dpkg on your Debian installation?
Yes, the sin is grave. Try using apt after this and figure out yourself. ;-)
/var/lib/dpkg/status file is important - as it stores the information about which packages are present on your system. apt would be stranded without this information.
Fortunately, there are ways you can attempt to rebuild the structure.
- Debian and Carelessness Mix Well is a good attempt at documenting these ways.
- debian-package-database-rebuild is a shell script example which can be used to make an attempt to rebuild /var/lib/dpkg. There is also a modified version of this script, which you can take a look at and compare.
- Recovering using data from /usr/share/doc is another way.
- And if only the status file has been corrupted/deleted, try this perl script to recover the information using /var/lib/dpkg/available and /var/lib/dpkg/info/*.list.
Note: It is recommended to analyze each of the above scripts to figure what it attempts to do. Systems’ configurations differ - it may or may not suit yours.
Good Luck.