29

Whenever I type sudo apt-get remove and then press the Tab key for auto-completion I get the following message:

grep-status: /var/lib/dpkg/status:15945: expected a colon
.

I don't see anything especially strange at line 15945 in the status file. It's a dot character in the description field of a mono library package and inserting a colon did not help. Removing the line containing the dot did not work either. Overwriting the file with status-old resulted in the same message.

Is there some way to rebuild the status file?

David Foerster
  • 36,890
  • 56
  • 97
  • 151
Ramón
  • 1,647

8 Answers8

26

You should be able to work with a previous known good status file and update from there. Every time you do an install or a update, the status file is saved to a gzipped backup under /var/backups. Doing an ls -l dpkg * on the directory shows:

-rw-r--r-- 1 root root   2266732 2010-09-30 08:35 dpkg.status.0
-rw-r--r-- 1 root root    624182 2010-09-29 08:49 dpkg.status.1.gz
-rw-r--r-- 1 root root    623844 2010-09-28 08:55 dpkg.status.2.gz
-rw-r--r-- 1 root root    620358 2010-09-24 11:04 dpkg.status.3.gz
-rw-r--r-- 1 root root    619021 2010-09-23 15:34 dpkg.status.4.gz
-rw-r--r-- 1 root root    619013 2010-09-23 08:03 dpkg.status.5.gz
-rw-r--r-- 1 root root    618968 2010-09-21 08:33 dpkg.status.6.gz

There's also a backup of the file created in the /var/lib/dpkg/ directory named status-old. Doing an ls -l status* on the directory shows:

-rw-r--r-- 1 root root 2266732 2010-09-30 08:35 status
-rw-r--r-- 1 root root 2267191 2010-09-30 08:35 status-old

So, to recover from a corruption, you should be able to do the following:

1. Make a backup of the corrupt status file:

mv /var/lib/dpkg/status /var/lib/dpkg/status_bkup

2. Copy an recent dpkg status file into place from either of the sources above:

either

cp /var/lib/dpkg/status-old /var/lib/dpkg/status

or

cp /var/backups/dpkg.status.#.gz /var/lib/dpkg/
gunzip -d /var/lib/dpkg/dpkg.status.#.gz 
mv /var/lib/dpkg/dpkg.status.# /var/lib/dpkg/status

3. Then run apt-get update:

sudo apt-get update

That should do it.

Jim
  • 471
7

I have finally fixed my system of this. Restoring a backup of the status file didn't work as I've had the issue for so long, it's in all of my backups.

The fix involves grepping for the actual formatting breaks and fixing them manually. It's not as hard as it sounds.

http://thepcspy.com/read/fixing-dpkg-status-corruption/

Oli
  • 299,380
7

Try a "dpkg -P " for the offending package. That will purge it from the local repository, removing all traces. On my system, that was the fix for removed (but not yet purged) packages that produced that error.

6

I was able to fix this problem by removing the packages which had corrupted entries in the status file.

sudo dpkg -r handbrake-cli

The accepted solution via pcregrep didn't work (pcregrep didn't find anything).

gap
  • 209
5

In this case I would back up the corrupted /var/lib/dpkg/status file and then correct it manually (around the lines 1888 and 9550) using the information from

apt-cache show libssl0.9.8
apt-cache show udev
arrange
  • 15,219
3

This has been a bug (supposed to be fixed): Launchpad Bug 613018

Upstream: Debian Bug 590885

This should be a workaround (backup, "fix" version string):

cp /var/lib/dpkg/status ~/dpkg-status.back
sudo sed -i "s/56127_Ubuntu_karmic/56127Ubuntukarmic/" /var/lib/dpkg/status
htorque
  • 66,086
2

Son of a...

Okay, the actual error was on line 15266 despite it being reported some 700 lines further down. The problematic entry in the status file was caused by a deb I installed to get my Lexmark printer working a long time ago. The entry was for the package lexmark-inkjet-08-driver. The Description field did not have a . in the place of a line break. This caused the parsing error.

To find this, I resorted to a shotgun troubleshooting method and started trying things pretty much randomly. One of my goofy attempts was grep-status -P e figuring that e was the most common letter in the alphabet. Dumb, I know, but the last status record printed out before it complained about a missing colon was for the lexmark package and I noticed the lack of a . character after a few minutes of staring at the screen.

If possible, I would like another answer that could describe a better method for finding this sort of issue in case someone runs into a similar problem in the future. Thanks.

Ramón
  • 1,647
2

Because my status-old was too problematic even with apt-get update,

This worked pretty well for me:

(as root)

cd /var/lib/dpkg 

cp -avf status status.corrupt

tr -cd '\11\12\15\40-\176' < status.corrupt > status

This command uses the -c and -d arguments to the tr command to remove all the characters from the input stream other than the ASCII octal values that are shown between the single quotes. This command specifically allows the following characters to pass through this Unix filter:

octal 11: tab

octal 12: linefeed

octal 15: carriage return

octal 40 through octal 176: all the "good" keyboard characters

All the other binary characters -- the "garbage" characters in your file -- are stripped out during this translation process.

CREDIT: http://alvinalexander.com/blog/post/linux-unix/how-remove-non-printable-ascii-characters-file-unix

If you're curious what's changed or where would be the damage: (possibly long)

diff /var/lib/dpkg/{status-old,status} |less
Marcos
  • 730