Debian removed /var/lib/dpkg/info/, is there a way to save the system?

7,584

You should be able to regenerate the directory using something like this:

for i in $(dpkg -l|awk '/^ii/ {print $2}')
do
    apt-get --reinstall -y install $i
done

What that snippet should do is reinstall every package you already have installed. It will also upgrade everything. If you don't want to do that, you'll have to extend the script to install the specific version you currently have installed, which is not guaranteed to work as those packages may no longer exist in the repository.

More info and a slightly different approach: http://people.adams.edu/~cdmiller/posts/Ubuntu-dpkg-recovery/

EDIT: Important tip from the above linked article:

Some packages will still not install correctly as more stuff is missing from /var/lib/dpkg. In particular the package "ucf" is important to enable the kernel and possibly some others to install correctly.

Without /var/lib/dpkg/info/ucf.templates the kernel install produces this error:

failed to install/upgrade: User postinst hook script [/sbin/update-grub] exited with value 10

Install ucf:

apt-get --reinstall install ucf

That article describes recovering from completely deleting all of /var/lib/dpkg, so this extra step may not apply to your situation.

Share:
7,584

Related videos on Youtube

Wiggler Jtag
Author by

Wiggler Jtag

Updated on September 18, 2022

Comments

  • Wiggler Jtag
    Wiggler Jtag over 1 year

    Removed accidentally /var/lib/dpkg/info/, now I am having problems with installing/removing packages, it prompts errors, cause can not find the info about installed packages.

    Is there any way to save the system or need to reinstall debian completely? :/

  • Wiggler Jtag
    Wiggler Jtag about 11 years
    Thanks a lot for your reply! You saved my day! The script was running over 4 hours, but it done like 95% of the job! +++
  • womble
    womble over 4 years
    As far as I can tell, you weren't facing the same problem as described in the question.