Rescue Lost Directories using Debian aptitude and dpkg
We all do stupid things sometimes. I’ve just deleted the contents of my /bin/ directory. Luckily we’ve got the Debian package manager to save the day. Because it has super cow powers. Mooh!
Okay, with a lost /bin/ directory we haven’t got our shell anymore so we’ll have to boot using a Debian rescue image. I’ve used bootp to boot my machine into Debian rescue, but you can use any medium your machine can boot from. I’ve tarred a working /bin/ directory from another box into an archive and put it back, so the machine could be used again. I’ve used wget for this, but some kind of USB storage device will also work. Make sure the donor box is running the same architecture you’re using.
Now we can boot back into our broken Debian system. But we’re not quite there yet. These binaries in /bin/ might be Slackware or Gentoo binaries, who knows. Well, you, but you still might miss some binaries. We want all of our own Debian binaries back. Here’s a quick three-line solution how to refill your /bin/ (or any other directory for that matter) with Debian’s files. You can replace /bin with any directory you’d like, and dpkg will restore it for you.
cd /tmp
for package in `dpkg -S /bin |awk -F”:” ‘{print $1}’`; do aptitude download `echo $package | sed -e ’s/\,//’`; done
dpkg -i *.deb
Tomorrow: how to make dpkg order a pizza for you while doing the laundry.
Ghehe, speaking ’bout Debby, we are installing her at my work, on a server which is about to be used for the following tasks: Firewall, Gateway, Proxy, SMB server, and SSH server. I`ll let you know how it goes.
Anyway, my first impression of Debby is mighty, as you might expect ;)