Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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? :/

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

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|improve this answer
    
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! +++ –  Wiggler Jtag Mar 5 '13 at 23:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.