I just deleted "/bin". What's the best way to recover?

In general, I'd lean towards a reinstall (from the backups you are absolutely supposed to have). But I'm feeling hackish, so here's another way (assuming that your system is mounted under /target):

  1. Get a list of all the installed packages that have files in /bin:

    grep ^/bin/ /target/var/lib/dpkg/info/*.list | sed 's%^.*/\([^/\.]*\).list%\1%' >/tmp/pkglist
    

    (On my Debian Squeeze system that's a total of 34 packages, pretty much all of which are core)

  2. Download each of those packages (I couldn't be bothered to script this bit, so just hit up packages.ubuntu.com and download them into somewhere under /target). If you're lucky some of the packages might still be floating around in /target/var/cache/apt/archives.

  3. For each package, run /target/usr/bin/dpkg -x <package> /target. I'm fairly certain dpkg is all self-contained these days, and shouldn't call out to anything in /bin itself.

Once you've got the system back on it's feet, you should make sure and run an apt-get --reinstall install <all the packages from step 1>, because (since you're running a pre-release, which Sysadmin Cat says is a no-no on production systems) the versions of the packages you just extracted are likely to be different from those that were on the system before, and you'll want to make sure the system knows exactly what's what.


While your strategy may work (there are good chances for it, more if once you copy back the bin directory, you do an apt-get reinstall of all the packages in you system), it can yield problems in the future because you may get an unstable server.

If that would have happened to me, I would reinstall and restore from the daily backup. You have a daily backup - a disaster recovery plan - don't you?

In case you didn't have a disaster recovery plan, I would suggest to backup all the config files and the data you want to preserve and go ahead with a reinstall. That way you'll be sure that you'll end with a stable server again.


I would try creating a VM then copying the contents of /bin to your damaged machine. That should get you up and running. Then run

dpkg --get-selections  | awk '{print $1}' | xargs -l1 aptitude reinstall

which should reinstall all the packages that were on your system.

Tags:

Linux

Ubuntu