3

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

2 Answers 2

11

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.

1
  • 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! +++ Mar 5, 2013 at 23:34
0

Well, this day is been like any other, why? because I was facing an issue a little bit similar but this time related to just some packages with the following message :

Log started: 2019-09-22  16:12:10
dpkg: unrecoverable fatal error, aborting:
 reading files list for package 'apt': Bad address
Log ended: 2019-09-22  16:12:10

The way how I resolved it, was a little bit similar but with some differences such as:

Instead to rename the whole directory "/var/lib/dpkg/info/", I just moved the files (package names) that were causing me troubles, which in this case were the "apt" package(s).

  • so I first filtered the packages related to the pattern '^apt' :
mlazo@mlazo-pc:~$ dpkg -l|awk '/^ii  apt/ {print $2}'
apt
apt-config-icons
apt-config-icons-hidpi
apt-config-icons-large
apt-config-icons-large-hidpi
apt-transport-https
apt-utils
apt-xapian-index
aptdaemon
aptdaemon-data
  • Being in the directory "/var/lib/dpkg/info", I created a directory and moved the files that matched with the previous list :
cd /var/lib/dpkg/info
mdkir ../info_back
mv -v $(ls |grep -i "^apt") ../info_back/
  • Once the files were moved, I proceed to execute the reinstall process :
for x in  $(dpkg -l| awk '/^ii  apt/ {print $2}'); do apt-get install --reinstall ${x} -y ; done
  • While it was processing, I was checking the "/var/log/apt/term.log", getting the following confirmations :
mlazo@mlazo-pc:~$ tail -n 20000  /var/log/apt/term.log |grep -i "preparing to unpack .../apt"
Preparing to unpack .../apt-config-icons_0.12.0-3ubuntu1_all.deb ...
Preparing to unpack .../apt-config-icons-hidpi_0.12.0-3ubuntu1_all.deb ...
Preparing to unpack .../apt-config-icons-large_0.12.0-3ubuntu1_all.deb ...
Preparing to unpack .../apt-config-icons-large-hidpi_0.12.0-3ubuntu1_all.deb ...
Preparing to unpack .../apt-transport-https_1.6.12_all.deb ...
Preparing to unpack .../apt-utils_1.6.12_amd64.deb ...
Preparing to unpack .../apt-xapian-index_0.47ubuntu13_all.deb ...
Preparing to unpack .../aptdaemon_1.1.1+bzr982-0ubuntu19.1_all.deb ...
Preparing to unpack .../aptdaemon-data_1.1.1+bzr982-0ubuntu19.1_all.deb ...

  • Once the reinstall process finished, I proceed to execute the upgrade process, getting the successful outcome :
root@mlazo-pc:/var/lib/dpkg/info# apt-get upgrade
..
..
..
Processing triggers for initramfs-tools (0.130ubuntu3.8) ...
update-initramfs: Generating /boot/initrd.img-5.0.0-25-generic
Processing triggers for libvlc-bin:amd64 (3.0.8-0ubuntu18.04.1) ...

With the steps I previously executed it was completed in an interval of 30 minutes maybe than 4 hours.

Hope the previous steps could be helpful for someone.

Best regards,

Manuel Lazo

2
  • 1
    As far as I can tell, you weren't facing the same problem as described in the question.
    – womble
    Sep 23, 2019 at 1:06
  • I have fixed my answer, thanks for ur views. Sep 24, 2019 at 2:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .