• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Recover Deleted rpm Package Files(libraries, configuration files) in CentOS/RHEL 7

by admin

Question: Certain system-related files or directories have been erroneously removed/deleted. How to recover them?

In this instance, the following system files are missing:
– /etc/nsswitch.conf
– /lib64/libc.so.6

Identify which system files/directories have been removed

The following step relies on the RPM database (rpmdb) to identify missing files and directories. Therefore, the procedure is only applicable for files/directories that are installed via an RPM package.

Perform the following to identify which files/directories have been erroneously removed:

# for i in `rpm -qa | sort`
do 
    echo "### $i: 'rpm -Vv $i' >> 'hostname'-'date %+F-%T'-rpm-Vv.txt
done

The command above performs an inventory of all files/directories based on the currently installed package set. Reviewing the resultant file produces output such as the following:

# cat localhost-2020-12-11-11:45:27-rpm-Vv.txt

### glibc-2.12-1.212.0.3.el6_10.3.x86_64: ......... c /etc/gai.conf
......... c /etc/ld.so.conf
......... /etc/ld.so.conf.d
missing c /etc/nsswitch.conf
......... c /etc/rpc
......... /lib64/ld-2.12.so
......... /lib64/ld-linux-x86-64.so.2
......... /lib64/libBrokenLocale-2.12.so
......... /lib64/libBrokenLocale.so.1
......... /lib64/libSegFault.so
......... /lib64/libanl-2.12.so
......... /lib64/libanl.so.1
......... /lib64/libc-2.12.so
missing /lib64/libc.so.6
......... /lib64/libcidn-2.12.so
......... /lib64/libcidn.so.1
......... /lib64/libcrypt-2.12.so
......... /lib64/libcrypt.so.1
......... /lib64/libdl-2.12.so
......... /lib64/libdl.so.2
......... /lib64/libm-2.12.so
......... /lib64/libm.so.6
...
......... /usr/sbin/iconvconfig.x86_64
......... /usr/share/doc/glibc-2.12
......... d /usr/share/doc/glibc-2.12/BUGS
......... d /usr/share/doc/glibc-2.12/CONFORMANCE
......... d /usr/share/doc/glibc-2.12/COPYING
......... d /usr/share/doc/glibc-2.12/COPYING.LIB
......... d /usr/share/doc/glibc-2.12/FAQ
......... d /usr/share/doc/glibc-2.12/INSTALL
......... d /usr/share/doc/glibc-2.12/LICENSES
......... d /usr/share/doc/glibc-2.12/NEWS
......... d /usr/share/doc/glibc-2.12/NOTES
......... d /usr/share/doc/glibc-2.12/PROJECTS
......... d /usr/share/doc/glibc-2.12/README
......... d /usr/share/doc/glibc-2.12/README.hesiod
......... d /usr/share/doc/glibc-2.12/README.libm
......... /var/cache/ldconfig

From above output, it is evident that file /lib64/libc.so.6 installed from package glibc-2.12-1.212.0.3.el6_10.3.x86_64 is missing from the system. Review the entire log to identify all missing files/directories and their originating packages. Refer to the rpm man page for definitions of rpm validation file attributes.

# man rpm

Re-install/restore the missing files/directories

Having identified the list of packages for which files/directories are missing, reinstall those exact package versions to the affected system. For example:

# yum reinstall glibc-2.12-1.212.0.3.el6_10.3.x86_64

Once complete, perform Step 1 again to confirm the previously removed files/directories are no longer missing e.g.:

### glibc-2.12-1.212.0.3.el6_10.3.x86_64: ......... c /etc/gai.conf
......... c /etc/ld.so.conf
......... /etc/ld.so.conf.d
......... c /etc/nsswitch.conf 
......... c /etc/rpc
......... /lib64/ld-2.12.so
......... /lib64/ld-linux-x86-64.so.2
......... /lib64/libBrokenLocale-2.12.so
......... /lib64/libBrokenLocale.so.1
......... /lib64/libSegFault.so
......... /lib64/libanl-2.12.so
......... /lib64/libanl.so.1
......... /lib64/libc-2.12.so
......... /lib64/libc.so.6 
......... /lib64/libcidn-2.12.so
......... /lib64/libcidn.so.1
......... /lib64/libcrypt-2.12.so
......... /lib64/libcrypt.so.1
......... /lib64/libdl-2.12.so
......... /lib64/libdl.so.2
......... /lib64/libm-2.12.so
......... /lib64/libm.so.6
...
......... /usr/sbin/iconvconfig.x86_64
......... /usr/share/doc/glibc-2.12
......... d /usr/share/doc/glibc-2.12/BUGS
......... d /usr/share/doc/glibc-2.12/CONFORMANCE
......... d /usr/share/doc/glibc-2.12/COPYING
......... d /usr/share/doc/glibc-2.12/COPYING.LIB
......... d /usr/share/doc/glibc-2.12/FAQ
......... d /usr/share/doc/glibc-2.12/INSTALL
......... d /usr/share/doc/glibc-2.12/LICENSES
......... d /usr/share/doc/glibc-2.12/NEWS
......... d /usr/share/doc/glibc-2.12/NOTES
......... d /usr/share/doc/glibc-2.12/PROJECTS
......... d /usr/share/doc/glibc-2.12/README
......... d /usr/share/doc/glibc-2.12/README.hesiod
......... d /usr/share/doc/glibc-2.12/README.libm
......... /var/cache/ldconfig
...

Filed Under: CentOS/RHEL, CentOS/RHEL 7

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to find UUID of a device or filesystem
  2. How to work with multiple java versions under Linux
  3. Understanding Live Merge in RedHat Virtualization (RHV)
  4. How to Create, restore, and delete snapshots of virtual machine images in RedHat Virtualization
  5. How To Enable PHP 7.0 And httpd24 On Oracle Linux 7
  6. lvremove failing to remove volume after using ‘shred’ command
  7. Understanding dm-Multipath Identifiers in Linux
  8. Starting udev: udevd inotify_init failed: too many open files
  9. Allow cronjobs to run by pam even if user password is expired
  10. How To Add Timestamps To dmesg Kernel Boot Log in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • cf: Command-line tool to manage apps and services on Cloud Foundry
  • certutil: Manage keys and certificates in both NSS databases and other NSS tokens
  • cdk: A CLI for AWS Cloud Development Kit (CDK)
  • cd: Change the current working directory

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright