Lost /var/lib/dpkg on Debian?
Monday, October 31st, 2005[Note: I had originally added this in September 2004. Re-added to the website on 31 Oct 2005.]
What do you do if you accidentally lost /var/lib/dpkg on your Debian installation?
apt would be stranded if you’ve lost your package selection data, which resides in /var/lib/dpkg/status . This has information about which all packages have been installed on your system. If you only lost this file /var/lib/dpkg/status due to some reason, look for /var/lib/dpkg/status-old (backup file.) If it’s not there, or if you lost /var/lib/dpkg (or worse, /var) itself, then read on.
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.
- Recovery 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
Of course, do analyze each of the above scripts to figure what it attempts to do. Systems’ configurations differ - it may or may not suit yours.
Any other tips? Do let me know.