Recovering from Corrupted Packages in Debian


It always happens. The people at Debian figure out a problem and fix it long before I even realize it exists.

 

Not too long ago, I was working on one of our Xen DOM0 servers, trying to convert a Paravirutalized server into an HVM. I was moving/copying/whatevering in the drive, mounted on /media/source, trying to move things to /media/target. Not sure how, but somehow, I moved the wrong thing to the wrong place and ended up overwriting several of my 64 bit applications with their 32bit version.

 

I thought I was going to have to reformat/re-install, until Dave gave me some pointers, and I ended up with the following. It is possible, actually easy, to tell apt (the Debian package manager) do download and re-install a set of packages. The command is:

apt-get install --reinstall package1 package2 packagex
# this is the approved version

or, alternately

apt-get install --force-reinstall true package1 package2 packagex 
# this is the Dangerous, undocumented version

 

The only question now is, what packages to re-install. debsums is your friend. If you have not installed it, but have the ability to do so, (your package manager still works), issue the following command:

apt-get install debsums
debsums_init #install does an init, but there is a reason to run it manually

Look at the output of debsums_init. It will tell you which packages do not have checksums. I recommend including those in the reinstall if there is any question about their state.

With debsums installed and initialized, you can now see which packages fail the checksum. Issue the command:

debsums -c

Now, all you need to do is reinstaill them. Fortunately, the apt developers realized this might be needed and included a --reinstall flag. You can simply enter the command:

apt-get install --reinstall packagea packageb

with the list of packages coming from the output of debsums. However, if you want, simply put it all in one command:

apt-get install --reinstall $(dpkg -S $(debsums -c) | cut -d : -f 1 | sort -u)

here is a brief explanation:

  • $(debsums -c) returns a list of all packages which do not have a matching checksum
  • dpkg -S $(debsums -c)  passes the list to dpkg, finding the source package they came from
  • This is then cut on a colon, field 1, which is the name of the package, then sorted uniquely (to remove dups)
  • This list is then returned to apt-get install --reinstall, which reinstalls all the packages found

The result is, all corrupted packages are now reinstalled and your system is a lot closer to being in good shape.

Last update:
2013-09-18 07:27
Author:
Rod
Revision:
1.0
Average rating:0 (0 Votes)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.

Records in this category

Tags