Search code examples
libcchrootcentos-6.9

Accidently renamed libc.so.6 and cannot chroot within rescue mode


We have accidently renamed shared library /lib64/libc.so.6 to be /lib64/libc.so_6. Right after previous command the system (CentOS 6.9) throws the following error :

error while loading shared libraries: /lib64/libc.so.6: cannot open shared object file: No such file or directory

When logged in within rescue mode I followed the following commands :

mount /dev/md2 /mnt
mount /dev/md1 /mnt/boot
mount -t dev -o bind /dev /mnt/dev
mount -t proc -o bind /proc /mnt/proc
mount -t sys -o bind /sys /mnt/sys
chroot /mnt
</Code>

Then i get the following error :

/bin/bash: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

I also tried the following commands :

chroot /mnt /bin/bash
chroot /mnt/root/tmp /bin/bash
chroot /mnt/root/tmp /mnt/bin/bash

Then get another error

chroot: failed to run command ‘/mnt/bin/bash’: No such file or directory

Now the system is down and I only have ssh which failed once "libc.so.6" renamed, and rescue mode. How could I enter to system so that i can rename "libc.so_6" back to "libc.so.6"? Is there a work-around to bypass checking for "libc.so_6"?


Solution

  • For the sake of clarity, will post the answer here (in case someone else encounter similar trouble).

    When in rescue mode:

    mount /dev/md2 /mnt
    mv /mnt/lib64/libc.so_6 /mnt/lib64/libc.so.6
    

    Alternatively:

    • restore system from backup
    • try booting from some live USB (as Topper Harley proposed in comments)