Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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]

share|improve this question
    
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 Answers 2

up vote 2 down vote accepted

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
share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.