3

In a misguided attempt to recompile ld with debug symbols, I ended up with a /lib64 that was not symlinked to /lib (Debian 64-bit libs are in in /lib/x84_64-linux-gnu). I attempted to reinstall libc6 using apt, which errored out complaining about the above.

I (mistakenly) figured I could just mv /lib64 /tmp && ln -s /lib /lib64; the first command worked, leaving a broken system (/bin/ld not found etc.).

Is there any way to fix this in-place? (i.e. without running a rescue disk)

If I could have posted this anonymously, I would have ... [sigh]

mikewaters
  • 1,135
  • 1
  • 14
  • 26
  • Probably not, I suspect a boot off restore media is in order, unless you happen to have a big build of busybox hanging around somewhere? – Zoredache Jan 29 '12 at 21:26

2 Answers2

3

Not sure if this would have helped with part of it, but if you ever find you've moved the runtime linker so that things like mv,cp,ln,rm no longer work, you can still run them (and hopefully rescue yourself) by specifying the runtime linker explicitly. E.g.

    mv /lib64 /tmp
    ln -s /lib /lib64   # fails, no runtime linker
    /tmp/lib64/ld-2.13.so /bin/ln -s /lib /lib64    # should succeed
Don Hatch
  • 146
  • 5
0

If anyone else ever has this problem; once I had used a recovery disc to put the files back where they belonged, the following script allowed me to reinstall libc:

#!/bin/bash

# Fix symlinks in a b0rked /lib64 (Debian).
# Libs in /lib64 should be symlinked to /lib/x86_64-linux-gnu;
# if a symlink is found in /lib64, try to redirect it to a
# file of the same name in /lib/x86_64-linux-gnu.
# Then remove the old symlink destination.
#
# The Problem:
# me@box # ls -l /lib64
# -rwxr-xr-x 1 root root  156683 2011-12-29 19:11 ld-2.13.so
# lrwxrwxrwx 1 root root      10 2011-12-29 19:11 ld-linux-x86-64.so.2 -> ld-2.13.so
#
# The Solution:
# lrwxrwxrwx 1 root root      10 2011-12-29 19:11 ld-linux-x86-64.so.2 -> /lib/x86_64-linux-gnu/ld-2.13.so
#

set -e

libs=(/lib64/*)
bak=$HOME

for l in ${libs[@]}; do
    src=$(ls -l $l |awk '{print $10}');
    if [[ ! -z "$src" ]]; then
        if [[ ! -f "/lib64/$src" ]] || [[ ! -f "/lib/x86_64-linux-gnu/$src" ]]; then
            echo "error: $l src or dest not found:"
            echo `ls -l "/lib64/$src"` > /dev/null
            echo `ls -l "/lib/x86_64-linux-gnu/$src"` > /dev/null
            continue
        fi
        ln -si "/lib/x86_64-linux-gnu/$src" "$l";
        mv "/lib64/$src" $bak/;
    fi
done
mikewaters
  • 1,135
  • 1
  • 14
  • 26