Many files in /var/lib/dpkg/info/ corrupted; how to recover

5,836

In my case i got a lot of *.list files corrupted. If you do

file /var/lib/dpkg/info/<package_name>.list

you should usually get:

/var/lib/dpkg/info/<package_name>.list: ASCII text

but if your list files are corrupted you will get:

/var/lib/dpkg/info/<package_name>.list: data

I made two scripts to fix this problem.

The first script check for this and rename each corrupted .list file into *.list.broken

move_broken_list_files.sh

The second script cycle for each *.list.broken file and force reinstallation of the package.

install_missing_list.sh

sometimes the install fails because of problems with triggers:

fgets gave an empty string from '/var/lib/dpkg/info/libnih1:amd64.triggers'

in that case you have to move/rename that file like:

mv /var/lib/dpkg/info/libnih1:amd64.triggers /var/lib/dpkg/info/libnih1:amd64.triggers.broken

Hope this helps someone facing the same mess.

Share:
5,836

Related videos on Youtube

bguiz
Author by

bguiz

Writes Javascript, Java, Python &amp; C++

Updated on September 18, 2022

Comments

  • bguiz
    bguiz over 1 year

    When I run sudo apt-get (anything), I invariably get this error:

    dpkg: unrecoverable fatal error, aborting:
     files list file for package 'thunderbird-gnome-support' is missing final newline
    E: Sub-process /usr/bin/dpkg returned an error code (2)
    

    After some Googling, I learn that this is because /var/lib/dpkg/info/thunderbird-gnome-support.list is corrupt. I cat that file, and it most certainly is corrupt - it should be a plain text file containing a list of absolute file paths, but instead is a binary file.

    Now I inspect the other files in the same directory, and it appears that many of them are corrupt in the same way. This indicates that something went severely wrong in my file system, that caused many files to get corrupted. Unfortunately, it happened to affect system files.

    How do I recover from this?


    More details:

    Just prior to this, I installed a routine update when Ubuntu prompted me. It was a new Linux kernel, and some system file headers.

    After restarting, these were my specs:

    OS specs:

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 13.10
    Release:    13.10
    Codename:   saucy
    $ uname -a
    Linux brendang-linux 3.11.0-24-generic #41-Ubuntu SMP Mon Jun 9 20:36:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
    

    Immediately after restarting for the first time, the entire file system appeared to be mounted as read only (which has not been the case previously). Subsequently I have had to reboot several times before the system worked. I have done touch /forcefsck in between them to ensure that fsck runs, and am not sure what else needs to be done.

    • Admin
      Admin about 9 years
      Have same problem. Did you resolve this?
  • Julián Landerreche
    Julián Landerreche almost 4 years
    I was having the same exact issue OP reported. Your solution helped me recovering from this situation (on Debian Sid). I'm still planning to do a full OS reinstall though. I still wonder what might have caused all these files getting corrupted. I think it could have been my SSD going badly or a bad dpkg release.
  • TheTechRobo Stands for Ukraine
    TheTechRobo Stands for Ukraine almost 4 years
    Thank you for showing to use file -- I didn't even know it existed!! I just ran mv <NAME>.list <NAME>.list.BINARY for each (3) binary files. These were in /etc/apt/sources.list.d (and running nano on them just showed a bunch of ^@'s). Then I just ran cp <NAME>.list.save <NAME>.list and it seems to work! :D
  • TheTechRobo Stands for Ukraine
    TheTechRobo Stands for Ukraine almost 4 years
    Ye, it's working :D