This site is now 100% read-only, and retired.

XML logo

So what do you do when you 'rm -f /bin/*' ?
Posted by Steve on Sat 26 Nov 2005 at 14:16
Tags: none.

Agh.

If you're at a root shell and you accidently run:

rm -f /bin/*

What do you do?

My solution was reasonably simple, and involved wget to find the bash .deb package, and then ar to extract the contents into the two files :

  • control.tar.gz - control information which I ignored.
  • data.tar.gz - The actual package contents.

(See working with Debian binary packages for details of how this is done.)

Of course you cannot gunzip, or untar, the resultant archives because /bin/gunzip and /bin/tar don't exist. So what then?

Well I used Perl to do the gunzip step, then loaded the data.tar file into Emacs.

Emacs has an "archive mode" which allowed me to write the individual files from the archive out to disk (/bin/bash + /bin/sh respectively - I didn't create a symbolic link immediately)

Once that was done I used scp to place tar, gunzip, etc into place and then reinstalled all packages.

I'm sure there are creative alternatives, but I couldn't think of one under pressure...

 

Comments on this Entry

Re: So what do you do when you 'rm -f /bin/*' ?
Posted by Anonymous (66.118.xx.xx) on Sun 27 Nov 2005 at 20:46
This reminds me of a way I found to recover from deleting libc or ld.so. Luckily I use zsh as my login shell, and zsh turns out to have an integrated ftp client which can be loaded from its zsh module file and run without forking any processes. It's then possible to use the ftp client to download enough files from another machine to get the broken one working again.

-- JoeyH

[ Parent ]

Re: So what do you do when you 'rm -f /bin/*' ?
Posted by Steve (82.41.xx.xx) on Sun 27 Nov 2005 at 20:55
[ View Weblogs ]

That is pretty cool!

One of my earlier approaches was to try to use Emacs to open an outgoing FTP connection - but that failed (as did trying to use netcat - as that lives in /bin.

Had I insalled the relevent perl modules I could have written a simple script to do the FTP, but I had no networking modules installed upon that particular host so I was thwarted!

Steve

[ Parent ]

Re: So what do you do when you 'rm -f /bin/*' ?
Posted by Anonymous (157.92.xx.xx) on Tue 29 Nov 2005 at 17:39
I've seen a similar situation but with /usr/bin and used locate to find missing files and dpkg -S to found the packages I needed to reinstall.

It was pretty straightforward, but I could use some scripting since /bin was still there.

Anyway I thought that the locate + dpkg -S trick was worth mentioning since it could save you from reinstalling lot of packages...

[ Parent ]

Re: So what do you do when you 'rm -f /bin/*' ?
Posted by Anonymous (194.109.xx.xx) on Wed 30 Nov 2005 at 14:15
I'm getting a:
bash: /bin/rm: No such file or directory

Please advice.


Sincerily,

Gerhard.

[ Parent ]