How to create a symbolic link without using ln?
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.
Solution 1:
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.
Solution 2:
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
Solution 3:
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...
Solution 4:
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.