1

So, recently I was doing the Linux from scratch project and I had multiple terminals open, so I was continuing to make it, and by accident I typed the line in another terminal tab (root), and it messes up symlinks completely!, I can't run any commands on bash.

    case $(uname -m) in
 i?86) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
 ;;
 x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
 ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
 ;;
esac

I'm on arch linux, when I restarted the computer, also the kernel panic happened and it says: "switch_root: failed to execute /sbin/init: Too many levels of symbolic links."

Any solutions? I hope if someone helps.

3
  • You will need to get to a root shell to recover, if it's even possible... maybe try booting your kernel with init=/bin/sh. Nov 8, 2021 at 15:53
  • @rfmodulator that won't do anything if the system is using an initrd image (the switch_root call suggests that it does), and /bin/sh is itself dynamically linked and it will immediately fail with the same error, causing a panic. I suggest the OP to boot from a usb stick, mount the root filesystem and fix from there the /lib64/ld-linux-x86-64.so.2 symlink.
    – user313992
    Nov 8, 2021 at 16:21
  • @UncleBilly Thanks for the clarification ...but the fact remains that OP needs a root shell to recover. Nov 8, 2021 at 20:38

1 Answer 1

0

What to recover

The LFS variable was presumably unset when you ran this command. So it modified /lib64/ld-linux-x86-64.so.2 and /lib64/ld-lsb-x86-64.so.3.

You've corrupted the dynamic loader. As a consequence, you can't run any dynamically linked program. Pretty much every program is dynamically linked, including bash, init, ln, etc.

/lib64/ld-linux-x86-64.so.2 is the important one. It's the dynamic loader used by 64-bit Arch programs. The symbolic link is provided by the glibc package. From a working Linux system, run

ln -snf ld-2.33.so /lib/ld-linux-x86-64.so.2

Note: the number 2.33 will change over time! Check what file /lib/ld-*.so exists on your system.

/lib64/ld-lsb-x86-64.so.3 is for compatibility with programs not built for Arch. It's provided by the ld-lsb package. If this package is installed, restore the link:

ln -snf ld-linux-x86-64.so.2 /lib/ld-lsb-x86-64.so.3

If ld-lsb is not installed, remove /lib/ld-lsb-x86-64.so.3.

Self-contained recovery with advance planning

When dynamic libraries are corrupted, you can still run statically linked executables. If you're running any kind of unstable or rolling-release system, I recommend having a basic set of statically linked utilities. (Not just a shell: a statically linked bash is of no help to create symbolic links, for instance.) Arch Linux doesn't appear to have one. You can copy the executable from Debian's busybox-static or zsh-static: both include a shell as well as built-in core utilities such as cp, ln, etc.

With such advance planning, provided you still have a running root shell, you can run busybox-static and

ln -snf ld-2.33.so /lib/ld-linux-x86-64.so.2

Or run zsh-static and

zmodload zsh/files
ln -snf ld-2.33.so /lib/ld-linux-x86-64.so.2

If you've rebooted and are stuck because /sbin/init won't start, boot into the static shell: follow the steps in Crash during startup on a recent corporate computer under “Useful debugging techniques:”, starting with “press and hold Shift”. On the linux command line, add init=/bin/busybox-static (or whatever the correct path is).

Repairing from a recovery system

Without advance planning, you'll need to run a working Linux system to repair yours. The Arch wiki suggests booting a monthly Arch image. You can also use SysRescueCD. Either way, use your written notes, lsblk, fdisk -l, lvs, or whatever helps you figure out what your root partition is, and mount it with mount /dev/… /mnt. Then repair the symbolic link:

ln -snf ld-2.33.so /mnt/lib/ld-linux-x86-64.so.2
2
  • Thank you so much, I'll give it a go, oh man I forgot to export the LFS path, the system was restarted! Such a dumb mistake tbh. Thank you for your help!!!
    – kalix
    Nov 8, 2021 at 19:49
  • Thank you!! It worked!
    – kalix
    Nov 8, 2021 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .