Linux – unable to execute: Too many levels of symbolic links

bashlinuxshsymbolic-link

By mistake, I executed these commands :

sudo ln -sf bash /bin/sh 
sudo ln -sf bash /bin/bash

When I rebooted the Linux server in recovery mode I got this message:

init : Failed to spawn friendly-recovry pre-start process: unable to execute: Too many levels of symbolic links

And Linux doesn't run.

any help is greatly appreciated

Best Answer

I think you somehow ended up with

sh -> bash
bash -> bash

When the system is first trying to run a shell, it will go into a loop resolving bash, which is, according to the symlink,
the same as bash, which is the same as bash, which is the same as bash, which is the same as bash... until memory allowed for this runs out.


To fix the problem, we need to know what /bin/sh was before, normally it points to bash or to dash. Which Linux distribution do you use?

There are other shells installed normally, like dash, or zsh, but as the system looks for sh when starting, I see no way to make use of these without external help.

I think you will need to boot a live system from a CD, or connect the harddisk to another computer;
And from there, mount the root disk, and fix the link.
If the shell was really deleted by the "force" in ls -sf, you need to get the shell binary from somewhere.

Could also work to link /bin/sh to a similar shell, not the one it was pointing to - (but that seems to be what you were doing last.)


The

sudo ln -sf bash /bin/bash

could have deleted /bin/bash - but when I try something similar, I get an error:

ln: bash and /bin/bash are the same file

Are you sure about the commands? In which directory did you run them?