How to recover after deleting the symbolic link li

2019-02-01 20:52发布

问题:

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

/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.

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)?

[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

回答1:

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



回答2:

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

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


回答3:

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.



回答4:

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.



回答5:

Note, for 64 bit:

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



回答6:

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

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

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

I just did this and it worked.

In short, never delete the link. Bad idea.



回答7:

Thanks you very much for below answer. It worked well with root ID. We unlink libc.so.6 to link with higher version but suddenly after unlink libc.so.6 server become unresponsive. ln -s command 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.

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