I usually prefer to fix a Linux system than to reinstall from scratch. My computers have seen many distribution upgrades and a list of PPAs or third-party repositories. APT usually makes sure that everything works in the end. However, the fact that the package manager thinks that all required packages are 'installed' does not guarantee that all the files are present on the file system.
Such a such situation may occur if you have to work-around dependency problems with dpkg --force-*
. One could also reproduce such a situation by deleting a file from /usr
as root.
Is there a simple way to verify whether all files belonging to an installed package are present?
If a such a problem package is found, aptitude reinstall
fixes the problem.
From the
debsums
man page:I just ran this on my system because the disk content was randomly corrupted while I was experimenting with a beta OS. Here's what I did (and it seems to have worked well):
First, I installed 'debsums' and ran it to see if I had any corrupt files on my system:
As you can see, I have five corrupt files so I need to reinstall them. This is how I found which packages contain the corrupt files:
Then I repaired the corruption by reinstalling the damaged packages:
Finally, I checked to make sure that no corrupt files remain:
There was no output from this command, which means that no errors were found. :-)
One final note: you should also check your packages' config files to make sure they're OK. This can be more difficult because config files often change, and the changes are legitimate, so you'll need to manually inspect each changed config file to determine whether or not it's actually corrupt. This is how you get a list of changed config files:
The script given by PeniWize works great for corrupted files, but does not take care of packages with missing files, because debsums reports them to stderr. To reinstall packages with missing files, this worked for me:
The question has been answered elsewhere:
Is there a Ubuntu sanity check?: package debsums can compute MD5 hashes and compare against the deb package.
Is there a safe way to reinstall via the package manager: Yes, but not recommended.
I crafted the following script to restore missing files using various tricks.
Save it to file
dpkg-fix.sh
, make itchmod a+x dpkg-fix.sh
and runsudo ./dpkg-fix.sh -x
.Disclaimer/Note that
-x
option restores config files (in /etc) which are not restored by default. It can hose your system. It is very tricky to make any automated tool to restore that correctly, as config files are frequently customized. You should make backups and after restoring compare differences with your latest backup and make some judgement calls. Even after that, devise a plan how to test each change as it is possible to badly break things without means to recover.Using the dpkg program along with some Bash scripting should be able to this for you. The only caveat would be if someone replace "clean" versions of the files with "malicious" ones. For that you would need to get valid MD5 checksums from a pristine package. Anyways, here is the shell code to achieve what you want:
The script would only print out if a file or directory that was defined in the package was missing. Also you would need to replace the 'PACKAGE_NAME' variable with the package that you would want to inspect. Hope this helps.