Linux 删除符号链接libc.so.6后如何恢复?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12249547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:14:36  来源:igfitidea点击:

How to recover after deleting the symbolic link libc.so.6?

linuxshared-librariesglibc

提问by perreal

In our server the symbolic link to libc.so.6has been deleted. Now none of the binaries in the system work. To fix this, I tried:

在我们的服务器中,指向的符号链接libc.so.6已被删除。现在系统中的所有二进制文件都不起作用。为了解决这个问题,我试过:

/bin/ln -s /lib/libc-2.11.3.so /lib/libc.so.6

which, as expected, gives me:

正如预期的那样,它给了我:

/bin/ln: error while loading shared libraries: libc.so.6: 
    cannot open shared object file: No such file or directory

I also tried:

我也试过:

/lib/ld-linux-x86-64.so.2  --inhibit-rpath /lib/libc.so.6 \
   --library-path /lib/libc-2.11.3.so \
   /bin/ln -s /lib/libc-2.11.3.so /lib/libc.so.6

with the same result. Further unsuccessful attempts include cp, mv, cat.

结果相同。进一步失败的尝试包括 cp、mv、cat。

I'm connected via ssh and I believe I will not be able to open another session after closing this one. Is there a way to fix this system (using bash built-ins perhaps)?

我通过 ssh 连接,我相信关闭这个会话后我将无法打开另一个会话。有没有办法修复这个系统(也许使用 bash 内置函数)?

[edit] I did:

[编辑]我做了:

while read line; do echo $line; done < /lib/libc-2.11.3.so > libc.so.6

to copy the file and tried with:

复制文件并尝试:

/lib/ld-linux-x86-64.so.2  --inhibit-rpath libc.so.6 --library-path . \
  /bin/ln -s /lib/libc-2.11.3.so /lib/libc.so.6

and got:

并得到:

/bin/ln: error while loading shared libraries: ./libc.so.6: ELF file OS ABI invalid

采纳答案by Simon Richter

You could simply run ldconfig. Most distributions ship this as a static binary.

你可以简单地运行ldconfig. 大多数发行版将其作为静态二进制文件发布。

回答by wollud1969

Boot using a live cd like Knoppix or whatever and fix the missing link after mounting the disk with the "broken" system out of the running live system.

使用 Knoppix 之类的 live cd 或其他任何东西启动,并在将带有“损坏”系统的磁盘安装到正在运行的实时系统之外后修复丢失的链接。

回答by Adam

This helped in my case (the actual version depends on your library):

这对我有帮助(实际版本取决于您的库):

ldconfig -l -v /lib/libc-2.13.so

回答by Kumar Sukhani

Try:

尝试:

LD_PRELOAD=/lib/libc-2.17.so ln -s /lib/libc-2.17.so /lib/libc.so.6

Note: The actual version depends on your library.

注意:实际版本取决于您的库。

回答by malc

Note, for 64 bit:

请注意,对于 64 位:

LD_PRELOAD=libc-2.13.so ln -s libc-2.13.so libc.so.6

LD_PRELOAD=libc-2.13.so ln -s libc-2.13.so libc.so.6

This worked great for me

这对我很有用

If you are not in that directory of course it will be something like:
LD_PRELOAD=/lib/x86_64-linux-gnu/libc-2.13.so ln -s /lib/x86_64-linux-gnu/libc-2.13.so /lib/x86_64-linux-gnu/libc.so.6

如果您不在该目录中,当然它会是这样的:
LD_PRELOAD=/lib/x86_64-linux-gnu/libc-2.13.so ln -s /lib/x86_64-linux-gnu/libc-2.13.so /lib/x86_64-linux-gnu/libc.so.6

回答by manoj

If you had done an ls command previously and know what the version of the libc is,

如果您之前执行过 ls 命令并且知道 libc 的版本是什么,

ldconfig -l -v /lib64/libc-2.x.so

where xis your version works. Note that it could be a lib64 or lib depending on your version.

x你的版本在哪里工作。请注意,它可能是 lib64 或 lib,具体取决于您的版本。

I just did this and it worked.

我只是这样做了,它奏效了。

In short, never delete the link. Bad idea.

简而言之,永远不要删除链接。馊主意。

回答by Devdatta

Thanks you very much for below answer. It worked well with root ID. We unlink libc.so.6to link with higher version but suddenly after unlink libc.so.6 server become unresponsive. ln -scommand was not working. No other users were able to ssh to server. But when we ran below command it worked. (with libc version exist on server) server started to behave normally.

非常感谢您的以下回答。它适用于根 ID。我们取消链接libc.so.6到更高版本的链接,但在取消链接 libc.so.6 服务器后突然变得无响应。 ln -s命令不起作用。没有其他用户能够通过 ssh 连接到服务器。但是当我们在命令下运行时它起作用了。(服务器上存在 libc 版本)服务器开始正常运行。

Below one is correct command and life saving too....

下面一个是正确的命令和救生也是......

LD_PRELOAD=/lib/libc-2.17.so ln -s /lib/libc-2.17.so /lib/libc.so.6

Note: The actual version depends on your library

注意:实际版本取决于您的库

回答by Rural Hunter

If you are using Ubuntu, ldconfig won't work. Just run:

如果您使用的是 Ubuntu,ldconfig 将不起作用。赶紧跑:

/sbin/ldconfig.real