Score:0

Ubuntu 22.04 after "rm /*" symlink /bin is gone, bash complain: /bin/bash: bad interpreter

bo flag

Mistakenly ran rm /* as root.

In result, it did remove all files from linux root dir, but preserved folders. (which is good news)

lrwxrwxrwx   1 root root    7 Aug  5  2020 bin -> usr/bin
lrwxrwxrwx   1 root root    7 Aug  5  2020 lib -> usr/lib
lrwxrwxrwx   1 root root    9 Aug  5  2020 lib32 -> usr/lib32
lrwxrwxrwx   1 root root    9 Aug  5  2020 lib64 -> usr/lib64
lrwxrwxrwx   1 root root   10 Aug  5  2020 libx32 -> usr/libx32
lrwxrwxrwx   1 root root    8 Aug  5  2020 sbin -> usr/sbin

Because in Ubuntu 22.04 /bin is symlink to /usr/bin, it was also removed. So if i try to run any command via bash, it fails due error:

If i will try to use /usr/bin/bash, it fails:

# /usr/bin/bash
bash: /usr/bin/bash: No such file or directory

But file does exist:

/usr/bin/bash/
bash: /usr/bin/bash/: Not a directory

# /usr/bin/bas
base32    base64    basename  basenc    bash      bashbug

It seems, that main issue is that current bash tries to run use /bin/bash in order to run commands:

# ldd ls
bash: /usr/bin/ldd: /bin/bash: bad interpreter: No such file or directory

It seems, that bash tries to execute command via /bin/bash interpreter, but fails because this symlink is gone.

Saw answer https://askubuntu.com/a/906692, but fails on first steps:

#sudo /proc/$$/exe
bash: /usr/bin/sudo: No such file or directory

or

/proc/$$/exe
bash: /proc/1872780/exe: No such file or directory

Again, due issue with /bin/bash: bad interpreter

Is there any way to run command in bash using different interpreter or change interpreter path somehow?

Shebangs doesn't seems to work, or may be i'm using them wrong.

Also, i understand that it's possible to restore using liveCD, but it's remote system, and i can't get to it for another month.

Artur Meinild avatar
vn flag
Use `/use/bin/bash`. And restore the removed symlinks..
Lnuynxa avatar
bo flag
Yeah, added that in edit, sorry. I did try to do that first, but it also fails
hr flag
I wonder if the more fundamental issue is the (presumably also stomped) symlink from `/lib64` to `usr/lib64`? That might mean that none of your executables can find `/lib64/ld-linux-x86-64.so.2`. Does `/usr/lib64/ld-linux-x86-64.so.2 /usr/bin/bash -c 'echo $0'` work?
Lnuynxa avatar
bo flag
It seems, no `/usr/lib64/ld-linux-x86-64.so.2 /usr/bin/bash -c 'echo $0' bash: /usr/lib64/ld-linux-x86-64.so.2: No such file or directory `
Lnuynxa avatar
bo flag
Edit Actually, it fails because /usr/lib64 is empty: If i will try to use some different dir: `# /usr/lib/ld-musl-x86_64.so.1 /usr/bin/bash -c 'echo $0' Error loading shared library libtinfo.so.6: No such file or directory (needed by /usr/bin/bash) Error relocating /usr/bin/bash: __snprintf_chk: symbol not found Error relocating /usr/bin/bash: tputs: symbol not found Error relocating /usr/bin/bash: __vfprintf_chk: symbol not found` It seems to fails to other errors
Lnuynxa avatar
bo flag
Small fixes to again avoid aliases, and it did work, thank `# /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /usr/bin/bash -c '/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /usr/ bin/ls -alh /' total 1.1G drwxr-xr-x 19 root root 4.0K May 10 17:30 . drwxr-xr-x 19 root root 4.0K May 10 17:30 .. drwxr-xr-x 4 root root 4.0K May 9 06:05 boot drwxr-xr-x 23 root root 5.3K May 10 16:55 dev`
hr flag
Apologies, it never occurred to me that you might be using musl - anyhow, can you get the same trick to work for `/usr/bin/sudo ln` ?
Lnuynxa avatar
bo flag
No, musl is not a problem, here. (i just tried to check first ld binary i found) Problem was: `/usr/lib64/ld-linux-x86-64.so.2` -> `/lib/x86_64-linux-gnu/ld-2.31.so` Where `/lib/` -> `usr/lib` So, we just need to remove all links and use `/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2` directly It's was a great suggestion. Maybe, you can make it in separate answer, so i can approve it?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.