How to recover from a corrupted glibc on Ubuntu 20.04 server

Given a second chance I would double check it, but I accidentally run sudo ln -sf something /usr/lib/x86_64-linux-gnu/libc-2.31.so. And there is not another copy of glibc because this is the real shared object instead of a symlink.

So how can I recover from it? I think I may have to get another copy glibc, boot the machine from a usb device, and copy the clean libc-2.31.so to /usr/lib/x86_64-linux-gnu.

What is the correct way to do it? Do I also have to rebuild the symlinks libc.so.6 under /lib/x86_64-linux-gnu and /usr/lib/x86_64-linux-gnu?


Solution 1:

Do not create symlinks in the folders which are controlled by APT!!!
You will break the system and/or create a nightmare for its future maintenance!!!

To recover the situation reinstall the libc6 package by

sudo apt-get update
sudo apt-get install --reinstall libc6 

and do not touch symlinks next time.
If you want to play with the system - do this in /usr/local/bin which is outside of APT control.


Note: on the fresh minimal 20.04 LTS there is only one file named libc-2.31.so - see

# find / -name libc-2.31.so
/usr/lib/x86_64-linux-gnu/libc-2.31.so

and one named libc.so.6:

 # find / -name libc.so.6
 /usr/lib/x86_64-linux-gnu/libc.so.6

while they are symlinked as follows (central part is replaced by (...)):

 # ls -al /usr/lib/x86_64-linux-gnu/libc-2.31.so /usr/lib/x86_64-linux-gnu/libc.so.6
 -rwxr-xr-x (...) /usr/lib/x86_64-linux-gnu/libc-2.31.so
 lrwxrwxrwx (...) /usr/lib/x86_64-linux-gnu/libc.so.6 -> libc-2.31.so

Both are provided by libc6 deb-package.