Weblog entry #47 for Steve
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
-- JoeyH
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | 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!
[ Parent | Reply to this comment ]
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 | Reply to this comment ]
bash: /bin/rm: No such file or directory
Please advice.
Sincerily,
Gerhard.
[ Parent | Reply to this comment ]