32

I deleted a critical symbolic link - libc.so.6. I have the file it should point at, but the basic commands such as ln or wget won't work anymore due to the link missing. However, echo or other Bash builtins work.

I am looking for a way to recreate this symbolic link.

Sebas
  • 545

6 Answers6

57

you can use ldconfig, it recreates the symlink:

# 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

just tested it, as you see.

fedorqui
  • 278
natxo asenjo
  • 5,909
44

CentOS 6 generally comes with busybox, a statically-linked set of Unix tools, installed in /sbin. You can run it like this:

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

Set LD_PRELOAD to preload the relevant library. I tried it out with libpthread and it seems to work:

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

sln serves exactly that purpose: to fix symbolic links when you can't use regular ln because you broke an essential symlink. To quote its man page:

DESCRIPTION

  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.
Léo Lam
  • 231
aru
  • 231
  • 1
  • 2
8

You can set LD_LIBRARY_PATH variable to include the directory where real libc.so.6 is:

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

Also, execute ldconfig for it to recreate the links. This should make the commands work so you can then use ln commands to fix your system.

Another way would be to boot via LiveCD and link file there.

ek9
  • 2,131
-4

Use scp or sftp to copy a statically linked version of ln. Make sure it is executable. Then use it to fix the file.