The Problem
rpm commands issue the following error:
rpm: error while loading shared libraries: /usr/lib64/liblzma.so.0: invalid ELF header
The Solution
In this instance, either liblzma.so or the link to it (/usr/lib64/liblzma.so.0) had gotten overwritten.
$ rpm -qa | grep binutils rpm: error while loading shared libraries: /usr/lib64/liblzma.so.0: invalid ELF header
To resolve this issue, the liblzma.so file and associated soft link need to be restored. Follow the steps outlined below in order to restore the .so file and associated soft links.
1. Ensure that the softlink /usr/lib64/liblzma.so.0 exists and points to liblzma.so.0.0.0.
# ls -l /usr/lib64/liblzma.so.0 lrwxrwxrwx 1 root root 16 Mar 31 15:42 /usr/lib64/liblzma.so.0 -> liblzma.so.0.0.0
# file /usr/lib64/liblzma.so.0.0.0 ./usr/lib64/liblzma.so.0.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
2. If the softlink does not exist try the following:
– Try to use yum to reinstall the xz-libs. However, if rpm is having a problem, yum likely will too.
# yum reinstall xz-libs
3. If that does not work, unpack the rpm and copy the new shared library file over the invalid file. As rpm is having trouble, unpacking the rpm will likely need to be done on a different system.
– Download the appropriate xz-libx rpm from the source respository and use the rpm2cpio and cpio commands to unpack the rpm.
# rpm2cpio xz-libs-4.999.9-0.5.beta.20091007git.el6.x86_64.rpm | cpio -idv ./usr/lib64/liblzma.so.0 ./usr/lib64/liblzma.so.0.0.0 ./usr/share/doc/xz-libs-4.999.9 ./usr/share/doc/xz-libs-4.999.9/COPYING.GPLv2 ./usr/share/doc/xz-libs-4.999.9/COPYING.GPLv3 ./usr/share/doc/xz-libs-4.999.9/COPYING.LGPLv2.1 421 blocks
4. Copy the liblzma.so.0.0.0 from the unpacked rpm over the existing shared library file:
# cp -pv ./usr/lib64/liblzma.so.0.0.0 /usr/lib64/liblzma.so.0.0.0 cp: overwrite '/usr/lib64/liblzma.so.0.0.0'? y './usr/lib64/liblzma.so.0.0.0' -> '/usr/lib64/liblzma.so.0.0.0'
# file /usr/lib64/liblzma.so.0.0.0 /usr/lib64/liblzma.so.0.0.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
5. Test that rpm works as expected.
# rpm -qf /usr/lib64/liblzma.so.0.0.0 xz-libs-4.999.9-0.5.beta.20091007git.el6.x86_64