Reinstalling packages with missing/corrupt files

Following an unclean shutdown and a colourful fsck, a whole bunch of files have gone missing. The output of ‘rpm -Va’ is several hundred lines long (mostly missing files but also some checksum and other mismatches). Is there an easy way to reinstall packages which have missing and/or corrupt files?

The OS in question is Fedora 22.

For reference and completeness sake, one command that would be able to achieve what initially asked for would be something like this (quickly fiddled together, but it’s working)

rpm -qf $(rpm -Va 2>&1 | grep -vE '^$|prelink:' | sed 's|.* /|/|') | sort -u

Here’s a short explanation of the various parts:

rpm -Va 2>&1

Will run a complete verification on all packages currently installed / listed in rpm database. It will also redirect stderr to stdout, as here on my box some errors which are caused by prelink being enabled are reported as errors but we want them on stdout.
Attention: Needs to run as root to be able to check all files, permissions and owner/group.

grep -vE '^$|prelink:'

suppresses display of emtpy lines and such of the prelink errors (example of such an error:
prelink: /tmp/#prelink#.B14JBi: Recorded 10 dependencies, now seeing -1 )

sed 's|.* /|/|')

will filter the rpm -Va output to only show filenames

rpm -qf $()

will query for all the obtained filenames in which package those are contained, and output the package name and version

| sort -u

will suppress duplicate package name/version combinations.

Altogether you will receive a list of packages which failed verification.

rpm -Va might still show some unrelated issues, as it also checks dependencies between packages, which might need to be suppressed by adding --nodeps.

Answered By: doktor5000

I recently had a similar problem with missing files on openSUSE 13.2 and fixed it with:

rpm -Va --nodeps --nodigest --noscripts --nosignature --nofiledigest --nosize --nomode --nordev --nouser --nogroup --nomtime
| awk -e '($1=="missing") && ($2=="d") {system("rpm -qf "$3);}; ($1=="missing") && ($2!="d") && ($2!="c") {system("rpm -qf "$2);}'
| sort -u | xargs zypper in -f

The options to rpm and the call to awk are intended to save time in my case, because no corruption occurred.

Answered By: auxsvr

I had a same issue on CentOS 7 and achieve to fix it with a little custom of the @auxsvr answer’s :

rpm -Va --nodeps --nodigest --noscripts --nosignature --nofiledigest --nosize --nomode --nordev --nouser --nogroup --nomtime |egrep 'manque|missing' |awk '$2=="d"{print "rpm -qf "$3}' |sh  |sort -u |xargs yum -y reinstall
Answered By: Bertrand Cebador
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.