• 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. Configure MySQL Router to Auto Restart of Failure using systemd
  2. CentOS / RHEL 7 : How to create an Network Bonding (NIC teaming) using nmcli
  3. Troubleshooting Common GUI / X-Window Issues on CentOS/RHEL
  4. How to Extend the Last Existing Filesystem Partition with Parted
  5. CentOS / RHEL 7 : How to Change Timezone
  6. How to determine file and free space fragmentation of OCFS2
  7. How to Backup And Restore The RHEV Manager Engine
  8. RHEL 7 – RHCSA Notes : Create hard and soft links.
  9. RHEL 7 – RHCSA Notes (Cheat Sheets)
  10. How to change the default location (/var/cache/yum) of yum cache

You May Also Like

Primary Sidebar

Recent Posts

  • What are /dev/zero and /dev/null files in Linux
  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright