March 8, 2014 · debian hacks learnshell linux newbie programming raspberrypi raspbian rpi security server timemanagment tricks

Files list file missing final newline?

Just today I've encountered a strange problem while performing apt-get upgrade on my Raspberry Pi. Everything went fine, until the package manager made me stop for a while, staring at the screen with:

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

Mechanically, I've removed the <strong>/var/lib/dpkg/info/autotools-dev.list</strong> file to perform a reinstall of the broken package. Unfortunately, my problems didn't end there. More packages showed the same error or a different one:

files list file for package `*' contains an empty filename


I've tried adding some stuff at the end of the list files, all in vain.

Fortunately, I've come across a solution to this situation. I've found the workaround for this problem on launchpad (Bug #108189). It seems that the errors indicate that the file /var/lib/dpkg/info/PACKAGE_NAME.list is corrupted (empty or full of garbage). The reason may be a disk error, a memory error, a process being interrupted during unpack"¦ Since it happened on my Raspberry, I assume that it must have been a disk error, as the files were full of garbage, broken lines, cut words, etc.

To repair the files, you have to do two things.

First of all, we need to download the <strong>deb</strong> file in question with:

sudo apt-get install --reinstall --download-only packagename

Once you have a valid .deb file, you can reconstitute the file. First, become root by using

su -

(in case of Raspbian), and then use the following command:

dpkg -c /var/cache/apt/archive/PACKAGE_NAME.deb | \ 
awk '{if ($6 == './'){ print '/.'; } else if \ 
(substr($6, length($6), 1) == '/'){print \ 
substr($6, 2, length($6) - 2); } else { print \ 
substr($6, 2, length($6) - 1);}}' > \ 

The bash one-liner replaces the broken <strong>.list</strong> file with valid data and repairs the problem! Repeat if needed, replacing the PACKAGE_NAME with the name of broken package.

Though the workaround might be a tedious work, especially if a lot of packages get the problem, it's definitely worth doing if you don't want to lose any data while reflashing your SD card.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket