1

I accidentally deleted the symbol link /lib64/libc.so.6 -> /lib64/libc-2.12.so with

$ sudo rm libc.so.6

Then I can not use anything including ls command. The error appears for any command I type

ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

I've tried

$ export LD_PRELOAD=/lib64/libc-2.12.so

After this I can use ls and ln ..., but still can not use sudo ln ..., sudo -E ln ..., sudo su or even su. I always get this err

sudo: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

or

su: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

It seems LD_PRELOAD works only for the current shell session of my account, but not for a new account like root or a new session.

It's a remote server so I can not use a live CD. I now have a ssh bash session alive but can not establish new ones. I have sudo privilege, but don't have root password.

So currently my problem is I need to run sudo sln -s libc-2.12.so libc.so.6 to re-create the symlink libc.so.6, but I can not run sudo without libc.so.6.

How can I fix it? Thanks~

4

The best thing to do in this case by far is to boot the server using a livecd, mount the applicable partitions, and create the symlink (be careful that the symlink points to exactly the right place when doing this, as if it points to a different absolute path than when you are running, it will not be helpful).

I can't think of a program you can run which will not require libc, nor a way to modify root's environment without root (by design the latter is impossible).

Also, you should really unbind the macro key which has sudo rm /lib64/libc.so.6, enter, your password, and enter bound to it. I can think of only a few more inconvenient accidental keypresses.

However, as a last ditch attempt, try using su with no options, which preserves most of your environment and sets your UID to root.

You may also be able to create the symlink in the current working directory and run things, though this doesn't always work.

  • su does not work either. It seems the only way is to wait until holiday ends and use the live cd. Thanks. – kangshiyin Jun 30 '13 at 6:50
  • Added one more thing I forgot about... – Falcon Momot Jun 30 '13 at 6:51
  • Yes, I found LD_PRELOAD allow me to run most of the applications. but still can not compile c code. It seems gcc and ld need the orignal /lib64/libc.so.6 when compiling. – kangshiyin Jun 30 '13 at 7:36
  • They need it (or a symlink) when linking if the linker links in libc (it does). It also has to be in the linker's library search path (specify with -l). – Falcon Momot Jun 30 '13 at 7:37
  • tried but failed. a lot of external dynamic libs and non-gcc compilers required by my code make things very complicated. – kangshiyin Jun 30 '13 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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