1

sudo apt-get update hangs and suggests running sudo apt-get -f install, but that fails on a duplicate declaration. How can I fix this?

The following NEW packages will be installed:
libfont-afm-perl liblcms2-2
0 updgaded, 2 newly installed, 0 to remove and 10 not upgraded.
Need to get 0 B// 135 kB of archives.
After this operation, 396 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
dpkg: error: parsing file '/var/lib/dpkg/status near line 5174 package 'liburi-perl': duplicate value for 'Installed-Size' field
E: Sub-process /usr/bin/dpkg returned an error code (2)

Here is the file from vi:

Priority: optional
Section: perl
Installed-Size: 226
Maintainer: Debian Perl Group <pkg-perl-maintainers@lists.alioth.debian.org>
Architecture: all
Version: 1.60-1
Depends: perl, libmime-base64-perl, libnet-perl
Suggests: libwww-perl
Description: module to manipulate and access URI strings
 URI is a collection of Perl modules that represent and manipulate Uniform
 Resource Identifier (URI) references as specified in RFC 2396.
 .
 URI objects can be used to access and manipulate the various components
 that make up these strings.  There are also methods to combine URIs in
 various ways.
 .
 The URI class replaces the URI::URL class that used to be distributed with
 libwww-perl. This package al: perl
Installed-Size: 120
Maintainer: Debian Perl Group <pkg-perl-maintainers@lists.alioth.debian.org>
Architecture: all
Version: 1.20-1
Depends: perl (>= 5.6.0-16)

here is the new output from sudo apt-get -f install:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  mime-support
The following NEW packages will be installed:
  mime-support
0 upgraded, 1 newly installed, 0 to remove and 9 not upgraded.
21 not fully installed or removed.
Need to get 35.5 kB of archives.
After this operation, 197 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main mime-support all 3.52-1 [35.5 kB]
Fetched 35.5 kB in 1s (34.3 kB/s) 
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 13018 package 'zenity':
 missing description
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 13018 package 'zenity':
 missing maintainer
dpkg: error: parsing file '/var/lib/dpkg/status' near line 13018 package 'zenity':
 missing version
E: Sub-process /usr/bin/dpkg returned an error code (2)
  • 3
    Can you post the output of ls /etc/apt/sources.list.d and the exact error message? What OS are you running? and what version of the OS? – Steve Robillard Oct 25 '12 at 5:41
  • Did you tried also sudo aptitude -f install? (If you have aptitude, I mean...) – Avio Oct 25 '12 at 10:01
  • @SteveRobillard The file isn't there. I have added the error message. Wheezy 9-18-12 from raspberrypi.org. I tried aptitude and received a similar error... – shaun5 Oct 25 '12 at 16:45
  • Can you post the contents of /var/lib/dpkg/status (especially the lines around line 5174). Can you also try the following and post any errors etc. sudo dpkg --remove liburi-perl sudo apt-get -f install – Steve Robillard Oct 25 '12 at 18:34
1

The first (and best) thing to try should be to edit /var/lib/dpkg/status and see if there is really a duplicate Installed-Size field for package liburi-perl. But let's make a backup first:

sudo cp /var/lib/dpkg/status /var/lib/dpkg/status-backup-20121025
sudo cp /var/lib/dpkg/status-old /var/lib/dpkg/status-old-backup-20121025

Then edit:

sudo vi /var/lib/dpkg/status +5174

This is the snippet I have for liburi-perl:

Package: liburi-perl
Status: install ok installed
Priority: optional
Section: perl
Installed-Size: 226
Maintainer: Debian Perl Group <pkg-perl-maintainers@lists.alioth.debian.org>
Architecture: all
Version: 1.60-1
Depends: perl, libmime-base64-perl, libnet-perl
Suggests: libwww-perl
Description: module to manipulate and access URI strings
 URI is a collection of Perl modules that represent and manipulate Uniform
 Resource Identifier (URI) references as specified in RFC 2396.
 .
 URI objects can be used to access and manipulate the various components
 that make up these strings.  There are also methods to combine URIs in
 various ways.
 .
 The URI class replaces the URI::URL class that used to be distributed with
 libwww-perl. This package also includes an emulation of the old URI::URL
 interface, which implements both the old and the new interface.
Homepage: http://search.cpan.org/dist/URI/

If there is a duplicate line, you can delete it pressing dd (d two subsequent times). Then save the file with ESC:wq.

If there is not a duplicate line, probably the only thing you can do is:

sudo cp /var/lib/dpkg/status-old-backup-20121025 /var/lib/dpkg/status

Then, in both cases, you can try to update and install a package you don't have (for example pv):

sudo apt-get update && sudo apt-get install pv

Let us know if it worked, and good luck!

EDIT-1:

Ok, so even /var/lib/dpkg/status-old is corrupted. Now you'll have to go through all the available backups, hoping that one (not to distant in time) is good. Take a look into the /var/backups/ directory:

ls -l /var/backups/

You should see a bunch of dpkg.status.<number>.gz like these:

-rw-r--r-- 1 root root   2484469 ott 25 12:02 dpkg.status.0
-rw-r--r-- 1 root root    644487 ott 24 14:12 dpkg.status.1.gz
-rw-r--r-- 1 root root    644226 ott 22 17:35 dpkg.status.2.gz
-rw-r--r-- 1 root root    642999 ott 19 16:14 dpkg.status.3.gz
-rw-r--r-- 1 root root    641905 ott 18 10:44 dpkg.status.4.gz
-rw-r--r-- 1 root root    641014 ott 17 09:35 dpkg.status.5.gz
-rw-r--r-- 1 root root    640965 ott 15 18:25 dpkg.status.6.gz

The first one isn't compressed so it's the first to be tried:

sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status

and then:

sudo apt-get update && sudo apt-get install pv

If even this one is corrupted, you can try to roll-back with the others:

sudo zcat /var/backups/dpkg.status.1.gz > /var/lib/dpkg/status

and then:

sudo apt-get update && sudo apt-get install pv

You can try with every backup you have, but you must remember that the more distant in the past the backup is, the more mismatching between its state and the actual state of your system there will be.

This means that if you restore a backup dated back to a week ago, every package that has been installed since then will not be in the database. But the package has been indeed installed, so its files will be scattered throughout the filesystem.

In a similar way, every package that has been removed since then will be in the database again, but it's files wont be on your system. So if you install other packages that depend on it, it won't be pulled in again and the newly installed application won't be eventually able to load some libraries.

So, if you succeed in recovering one of the old package databases, make a diff between it and your broken backup, in this way:

diff /var/lib/dpkg/status-backup-20121025 /var/lib/dpkg/status > ~/dpkg-status-diff.pat

Watching at the diff you'll be able to understand what has been installed/disinstalled and take the correct steps to update the database accordingly (i.e. repeat the sequence of installations/disinstallations that led to your actual filesystem).

| improve this answer | |
  • it looks to me like the file is missing some additional information that file, but now I am getting a different error – shaun5 Oct 25 '12 at 23:19
  • What have your done then? Have you made the backups? You have to tell us what you did, posting the new error doesn't provide enough information. – Avio Oct 26 '12 at 9:00
  • I did everything in your answer. – shaun5 Oct 26 '12 at 11:03
  • Ok, there is another piece of solution. One of the backup archives should be good. Hope it won't be too far in the past. – Avio Oct 26 '12 at 11:44
  • Where are the backups located, because in the directory /var/lib/dpkg/ there were only current and an old? – shaun5 Oct 26 '12 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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