Bookmark this page

Identifying and Recovering RPM Managed Files

Objectives

  • Identify and restore changed files with package management tools.

Verifying Installed Packages

A major advantage of RPM package management is the useful data that is stored in the system's RPM database. Every time that an RPM package is installed, including EPEL and third-party RPM packages, package and transaction information is recorded in the RPM database. This information includes file sizes, creation timestamps, content checksums, permissions, and user or group ownerships. Use RPM database content to verify existing files from RPM packages.

Verifying an installed package compares current file attributes with the stored information in the RPM database. The rpm -V command verifies a specified package, and rpm -Va verifies every installed package on the system.

The rpm command generates no output unless it finds discrepancies between the current files and the RPM database. When a difference is found, rpm prints the file name as a string to indicate which file attributes are different.

[root@host ~]# rpm -Va
SM5....T.  c /etc/ssh/sshd_config
....L....  c /etc/rc.d/rc.local
S.5....T.  c /etc/systemd/logind.conf
.M.......    /var/lib/nfs/rpc_pipefs

The first character string is a mask of the file's attributes. Periods represent attributes that match file information in the database. The table lists common file attribute flags.

LetterFile attribute
SFile size
MMode (permissions, including file type)
5Contents (digest, formerly the MD5 checksum)
LA symbolic link points to a different file location
UUser ownership
GGroup ownership
TModification time

The single character in front of the file name is the RPM file type that the RPM package builder specifies. The type designates files that need special RPM package handling, and that are not related to Linux file types. If no character is displayed, then the file is a normal file without any additional package handling designation. The table lists common RPM file type characters.

LetterFile type
cConfiguration file
dDocumentation file
lLicense file
rReadme file

Recovering RPM Managed Files

Use the rpm --setperms option to restore file permissions to the recorded values in the RPM database. In this example, files from the setup package are compared, and permissions are modified when different.

[root@host ~]# rpm -V setup
.M....G..  c /etc/motd
[root@host ~]# rpm --setperms setup
[root@host ~]# rpm -V setup
......G..  c /etc/motd

The group ownership setting is not modified by resetting the permissions. Use the rpm --setugids option to restore user and group file owership settings to the original values.

[root@host ~]# rpm --setugids setup
[root@host ~]# rpm -V setup

Use the yum reinstall command to recover a package's modified files, by replacing the current file with one from the original package. This command works for packages that support only one installed package version at a time, and does not work for install-only packages such as the Linux kernel.

In this example, yum reinstall restores a modified executable. The first rpm -V command shows that the /usr/sbin/tuned size, contents, and timestamps changed from original values. The later rpm -V command displays nothing, and verifies that the file matches the original attributes, because the file was reinstalled.

[root@host ~]# rpm -V tuned
S.5....T.    /usr/sbin/tuned
[root@host ~]# yum reinstall tuned
...output omitted...
   Reinstalling     : tuned-2.15.0-2.el8.noarch                            1/2
   Verifying        : tuned-2.15.0-2.el8.noarch                            2/2
...output omitted...
[root@host ~]# rpm -V tuned

Note

Files from application deployment formats other than RPM cannot be restored by the rpm or yum reinstall commands.

Many data files are either not provided by RPM or YUM, or are empty when first installed. Typically, these data files are created when the application first runs. Such data files also cannot be restored by the rpm or yum reinstall commands, but can be recovered from backups.

References

rpm(8) and yum(8) man pages

Revision: rh342-8.4-6dd89bd