SolengTech‎ > ‎Open Source‎ > ‎

HowTo: Repair Ubuntu dpkg status file

My Ubuntu 10.04.02 installs starting losing /var/lib/dpkg/status, and you can't update without it...
Thanks to capink, but I ended up re-installing anyway so unfortunately losing this file you are near the end of the line.
Using the script below will generate a new status file in your current directory (usually your home dir). Use this file in place of your status file after backing it up:


get_control_info ()
for i in /var/lib/apt/lists/*_Packages
sed '/Package: '"$1"'$/,/^$/!d' $i

for i in /var/lib/dpkg/info/*.list
package_name=`basename $i | sed 's/.list$//'`
get_control_info $package_name >> status-new

sed -i -e '/^Filename: .*/d' -e '/^MD5sum:/d' -e '/^SHA1:/d' -e '/^SHA256:/d' status-new
sed -i '/^Package: /a\Status: install ok installed' status-new

The new status file will not be prefect but it is a place to start from. Two problems I am aware of are:

1. The new status file will have all the packages marked as installed including those you uninstalled. This can be corrected later using your original status file.

2. The new status file will miss the field of Confiles. While not absolutely essential, it is very important field. Again this can be corrected using your old status file. But this will need some manual editing.

Note: The script will take long time to complete. On my machine it took about one hour.