新聞中心
centos 7 64 位系統(tǒng),為了測試,把/usr/lib64重命名成了/usr/lib64.bk,結(jié)果發(fā)現(xiàn),在運(yùn)行vi命令的時(shí)候報(bào)錯:

為炎陵等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及炎陵網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計(jì)制作、做網(wǎng)站、炎陵網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
-bash: /usr/bin/vi: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory
想把它重命名回來,發(fā)現(xiàn)在運(yùn)行mv命令的時(shí)候,也是一樣的報(bào)錯。除此之外,ls,cp,ftp,wget,rz,7z,unzip,tar什么的統(tǒng)統(tǒng)運(yùn)行不了,就連重新ssh遠(yuǎn)程都遠(yuǎn)程不了。。。
這下悲劇了,難道僅僅因?yàn)橐粋€(gè)很小的mv操作,整個(gè)shell都崩潰了?
然后開始baidu,很多都是設(shè)置LD_LIBRARY_PATH, LD_PRELOAD這兩個(gè)環(huán)境變量,來改變應(yīng)用程序所調(diào)用庫文件的路徑(因?yàn)槟J(rèn)的庫文件路徑/usr/lib64被我改成了/usr/lib64.bk)。于是嘗試:
export LD_LIBRARY_PATH=/usr/lib64.bk
export LD_PRELOAD=/usr/lib64.bk
然后執(zhí)行cp,結(jié)果還是一樣的問題。
似乎這兩個(gè)環(huán)境變量只對應(yīng)用程序有效,對shell命令不起作用啊。后來發(fā)現(xiàn),/lib64/ld-linux-x86-64.so.2只是個(gè)軟鏈,真實(shí)文件是/usr/lib64/ld-2.17.so。而ld-2.17.so本身并不是庫文件,可以把它理解為庫文件的管理程序,而且它很特別。國外有個(gè)牛人是這么說的:
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是操作系統(tǒng)的核心,并不受LD_LIBRARY_PATH環(huán)境變量的影響。如果想改變其調(diào)用方式,請查看man文檔。
于是乖乖的去看文檔??赡苁沁@個(gè)文檔太老了,在服務(wù)器上怎么man都沒有,只有網(wǎng)上有:
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這個(gè)文件可以當(dāng)命令來用。于是在服務(wù)器上嘗試執(zhí)行:
/usr/lib64.bk/ld-2.17.so
果不其然,服務(wù)器沒有再返回那條可惡的錯誤提示,取而代之的是,一連串幫助信息:
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
而這個(gè)-library-path參數(shù),應(yīng)該就是用來指定自定義庫文件的路徑。于是嘗試通過ld-2.17.so來調(diào)用cp:
/usr/lib64.bk/ld-2.17.so --library-path /usr/lib64.bk /usr/bin/cp /usr/lib64.bk/ /usr/lib64 -fr
終于成功了!再ls了一下,發(fā)現(xiàn)提示:
Segmentation fault
這應(yīng)該是會話緩存的問題。于是嘗試連接新的ssh,正常;再執(zhí)行其他任意命令,也都正常。問題終于解決了!
本文標(biāo)題:CentOS7/lib64被重命名后的解決
轉(zhuǎn)載源于:http://m.5511xx.com/article/cddhcig.html


咨詢
建站咨詢
