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 ...