如何创build一个不使用ln的符号链接?

我删除了一个关键的符号链接libc.so.6 。 我有它应该指向的文件,但基本的命令,如lnwget将不再工作,由于缺less链接。 但是, echo或其他Bash内置工作。

我正在寻找一种方法来重新创build这个符号链接。

你可以使用ldconfig,它重新创build符号链接:

 # rm /lib/libc.so.6 rm: remove symbolic link `/lib/libc.so.6'? y # ls -l /lib/libc* ls: error while loading shared libraries: libc.so.6: cannot open shared object file: # ldconfig # ls -l /lib/libc* [skip] lrwxrwxrwx. 1 root root 12 May 11 07:59 /lib/libc.so.6 -> libc-2.12.so 

只是testing它,如你所见。

CentOS 6通常带有busybox ,一个静态链接的Unix工具集,安装在/sbin 。 你可以像这样运行它:

 /sbin/busybox ln -s libc-2.12.so /lib/libc.so.6 

设置LD_PRELOAD以预加载相关库。 我尝试了libpthread它似乎工作:

 root@spirit:~# mv /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0-bak root@spirit:~# chattr chattr: error while loading shared libraries: libpthread.so.0: cannot open shared object file: No such file or directory root@spirit:~# LD_PRELOAD=/lib/x86_64-linux-gnu/libpthread.so.0-bak chattr Usage: chattr [-RVf] [-+=AaCcDdeijsSu] [-v version] files... 

sln服务正是为了这个目的:当你不能使用常规的ln时修复符号链接,因为你破坏了一个基本的符号链接。 引用其手册页:

描述

  The sln program creates symbolic links. Unlike the ln(1) program, it is statically linked. This means that if for some reason the dynamic linker is not working, sln can be used to make symbolic links to dynamic libraries. 

您可以将LD_LIBRARY_PATHvariables设置为包含real libc.so.6所在的目录:

  export LD_LIBRARY_PATH="/dir/for/libc.so.6/:$LD_LIBRARY_PATH" 

另外,执行ldconfig来重新创build链接。 这应该使命令工作,以便您可以使用ln命令来修复您的系统。

另一种方法是通过LiveCD启动并链接文件。

使用scp或sftp复制ln的静态链接版本。 确保它是可执行的。 然后用它来修复文件。