Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
@Sebas, I think you meant all the Bash builtins, not just echo. –  Cristian Ciupitu May 10 at 18:25
@CristianCiupitu maybe, what is it? cat is disabled... actually everything was. –  Sebas May 10 at 18:27
@Sebas, that's because cat is an external program. The Bash Builtin Commands manual page has details about what could be available. –  Cristian Ciupitu May 10 at 18:30
I assume you mean GNU/Linux based systems when you say "Unix" as many other *nix systems have "rescue" versions of the standard utilities that are statically linked just for those "oops" moments. –  Chris S May 10 at 19:38
I adjusted the flags. Thank you –  Sebas May 10 at 20:13

6 Answers 6

up vote 58 down vote accepted

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*
lrwxrwxrwx. 1 root root      12 May 11 07:59 /lib/libc.so.6 -> libc-2.12.so

just tested it, as you see.

share|improve this answer
And, conveniently, the /sbin/ldconfig is statically linked. ldconfig is responsible for those symbolic links in the first place. –  etherfish May 11 at 8:49
That's not really just "convenient", a statically-linked binary is pretty much a necessary design component of the tool that maintains your dynamic libraries! But it is what makes it an ideal tool for fixing this problem, and IMHO the only "correct" way. The question here is really not about a deleted symlink (99.999% of those can be deleted without consequence), it's "I broke my system's dynamic library store". Making @natxo's suggestion, "fix it using the tool that manages that store", obvious and sensible. Anything else (manually recreating the link) is a hacky workaround. –  FeRD May 11 at 22:39
Yes, this is indeed more logical to proceed so even though the other answer was correct too. –  Sebas May 12 at 15:54

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
share|improve this answer
+1, just tested it after removing the symlink in a test vm, it woks in centos 6.5 –  natxo asenjo May 11 at 5:52
+1 This answers the generic question in the question title as well. –  MattBianco May 13 at 12:05

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...
share|improve this answer
interesting, it regroups with what the others said. –  Sebas May 10 at 20:13

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:


  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.
share|improve this answer
nice, I did not know this tool. In centos it is part of glibc, so it must be installed by default –  natxo asenjo May 12 at 11:31
thanks for your input –  Sebas May 12 at 15:55

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.

share|improve this answer
Then only way to boot off livecd and link file there in chroot. –  edvinas.me May 10 at 18:15
Also, you should just set LD_LIBRARY_PATH to include directory where libc.so.6 file is. This might let you use the commands as it should find the lib. –  edvinas.me May 10 at 18:20
darn, sorry I didn't think of this first. –  edvinas.me May 10 at 18:31
That doesn't work, becuase the file linked to isn't named libc.so.6. You'll need to set LD_PRELOAD as in my answer. –  Dennis Kaarsemaker May 10 at 19:39
I tried it on Fedora 20 and it didn't work. –  Cristian Ciupitu May 10 at 20:53

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

share|improve this answer
scp and sftp will not work as they will not be able to load that file either. –  Florin Asavoaie May 14 at 0:18
scp, sftp, ftp would be run from a remote host. This assumes that the daemon in the broken machine is running already. Other possibilities for file transfer are file systems that are already mounted, either local or remote. –  Robert Jacobs May 14 at 18:33
Please stop misinformation. SCP requires the scp binary to be present and will be executed on both hosts. SFTP also launches new processes out of OpenSSH that require the respective binary. Most of the FTP daemons do the same. –  Florin Asavoaie May 15 at 5:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.