0

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.

waltinator
  • 36,399
  • Use /use/bin/bash. And restore the removed symlinks.. – Artur Meinild May 10 '23 at 19:51
  • Yeah, added that in edit, sorry.

    I did try to do that first, but it also fails

    – Lnuynxa May 10 '23 at 19:58
  • 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? – steeldriver May 10 '23 at 19:58
  • 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 May 10 '23 at 19:59
  • 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 May 10 '23 at 20:05
  • 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

    – Lnuynxa May 10 '23 at 20:11
  • 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 ? – steeldriver May 10 '23 at 20:18
  • 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?

    – Lnuynxa May 10 '23 at 20:22

0 Answers0