Red Hat Enterprise Linux Diagnostics and Troubleshooting
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_pipefsThe 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.
| Letter | File attribute |
|---|---|
| S | File size |
| M | Mode (permissions, including file type) |
| 5 | Contents (digest, formerly the MD5 checksum) |
| L | A symbolic link points to a different file location |
| U | User ownership |
| G | Group ownership |
| T | Modification 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.
| Letter | File type |
|---|---|
| c | Configuration file |
| d | Documentation file |
| l | License file |
| r | Readme file |
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 tunedS.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