CentOS 7 /lib64被重命名后的解决

CentOS 7 64 位系统,为了测试,把/usr/lib64重命名成了/usr/lib64.bk,结果发现,在运行vi命令的时候报错:

-bash: /usr/bin/vi: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory

想把它重命名回来,发现在运行mv命令的时候,也是一样的报错。除此之外,ls,cp,ftp,wget,rz,7z,unzip,tar什么的统统运行不了,就连重新ssh远程都远程不了。。。

这下悲剧了,难道仅仅因为一个很小的mv操作,整个shell都崩溃了?

然后开始baidu,很多都是设置LD_LIBRARY_PATH, LD_PRELOAD这两个环境变量,来改变应用程序所调用库文件的路径(因为默认的库文件路径/usr/lib64被我改成了/usr/lib64.bk)。于是尝试:

export LD_LIBRARY_PATH=/usr/lib64.bk
export LD_PRELOAD=/usr/lib64.bk

然后执行cp,结果还是一样的问题。

似乎这两个环境变量只对应用程序有效,对shell命令不起作用啊。后来发现,/lib64/ld-linux-x86-64.so.2只是个软链,真实文件是/usr/lib64/ld-2.17.so。而ld-2.17.so本身并不是库文件,可以把它理解为库文件的管理程序,而且它很特别。国外有个牛人是这么说的:

ld-linux-x86-64.so.2 is a pretty core part of your OS. It actually runs every (64 bit) dynamic application. It’s not a library as much as an app itself, a handler that is called when you run an app.

Basically, when you run a dynamic app, the kernel first runs ld-linux.so (or whatever name it is for your bitsize, distro, etc). ld-linux.so then peers into your app, sees the libraries that you need, sees any hard coded paths for the libraries (e.g. rpath’s) checks LD_LIBRARY_PATH, and then goes looking for all those libraries, makes sure they match bitsizes, names, what have you. It then collects all of those, loads them, and runs your app. If it can’t find the libs, it doesn’t run your app.

ld-linux.so can not be affected by LD_LIBRARY_PATH because it is run by the kernel, and the kernel does not load libraries like ld-linux.so does, it just has the one it’s configured to run. Again, not a library, so don’t use library semantics (LD_LIBRARY_PATH) to change how it’s called. It does have environment variables that affect it running – see man ld-linux.so for details.

大意是,ld-linux-x86-64.so.2是操作系统的核心,并不受LD_LIBRARY_PATH环境变量的影响。如果想改变其调用方式,请查看man文档。

 于是乖乖的去看文档。可能是这个文档太老了,在服务器上怎么man都没有,只有网上有:

http://www.man7.org/linux/man-pages/man8/ld.so.8.html

文档里有这么一段:

 /lib/ld-linux.so.* [OPTIONS] [PROGRAM [ARGUMENTS]]

      –library-path path Use path instead of LD_LIBRARY_PATH environment variable

setting (see below).

貌似ld-2.17.so这个文件可以当命令来用。于是在服务器上尝试执行:

/usr/lib64.bk/ld-2.17.so

果不其然,服务器没有再返回那条可恶的错误提示,取而代之的是,一连串帮助信息:

You have invoked `ld.so’, the helper program for shared library executables. This program usually lives in the file `/lib/ld.so’, and special directives in executable files using ELF shared libraries tell the system’s program loader to load the helper program from this file.  This helper program loads the shared libraries needed by the program executable, prepares the program to run, and runs it.  You may invoke this helper program directly from the command line to load and run an ELF executable file; this is like executing that file itself, but always uses this helper program from the file you specified, instead of the helper program file specified in the executable file you run.  This is mostly of use for maintainers to test new versions of this helper program; chances are you did not intend to run this program.  –list                list all dependencies and how they are resolved  –verify              verify that given object really is a dynamically linked                        object we can handle  –inhibit-cache      Do not use /etc/ld.so.cache  –library-path PATH  use given PATH instead of content of the environment                        variable LD_LIBRARY_PATH  –inhibit-rpath LIST  ignore RUNPATH and RPATH information in object names                        in LIST  –audit LIST          use objects named in LIST as auditor

而这个-library-path参数,应该就是用来指定自定义库文件的路径。于是尝试通过ld-2.17.so来调用cp:
/usr/lib64.bk/ld-2.17.so  –library-path /usr/lib64.bk /usr/bin/cp /usr/lib64.bk/ /usr/lib64 -fr
终于成功了!再ls了一下,发现提示:
Segmentation fault
这应该是会话缓存的问题。于是尝试连接新的ssh,正常;再执行其他任意命令,也都正常。问题终于解决了!

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/219882.html<

(0)
运维的头像运维
上一篇2025-04-14 07:49
下一篇 2025-04-14 07:50

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注