FreeBSD 8.2, deleted /bin/sh, can’t boot

freebsdsh

I made a really bad decision on one of my servers.

I deleted /bin/sh. I restarted the server and the server won't run because it needs /bin/sh to start the rc scripts. I can't access single user mode either because sh is needed.

Is there any easy way to reinstall the bourn shell?

I tried copying sh from a live cd, it failed on the ld-elf.so.1 library. So I copied that to /libexec from the livecd to my / partition. It then needs the libedit.so library and I copied that to /libexec but it isn't working this time.

I tried a symlink to /usr/local/bin/bash but that still presents me with "can't find sh" type error. I'm assuming that is because /usr isn't mounted yet because it is done from an rc script.

Any help is greatly appreciated.

Best Answer

You need to replace /bin/sh with something; that's the key. If you can get into the FreeBSD loader during startup (with an "ok" prompt) try something like this:

set init_shell=/bin/csh
unset init_script
unset init_path

I got this information from loader(8) from the FreeBSD manual pages (online). I've not done this, but it should work (assuming that /bin/csh is present and executable).

If you have a FreeBSD 8.2 server up and running elsewhere, you could try stealing the /bin/sh from that source and putting that into the system where needed.

Alternately, get a statically built /bin/sh and put that in instead; there won't be any library problems with a statically-built binary.

EDIT: I should have noted: if you boot into /bin/csh, you still have to get something to use instead of /bin/sh. You can get it over the Internet or copy it from another CD or a package or something; using /bin/csh to boot gets you into the machine. Copying over the network requires that you bring up the network; otherwise, copy from a CDROM.

The best ways to avoid this in the future:

  1. Don't delete from /bin! (that's the easy part)
  2. Have a statically built /bin/sh, not dynamically linked.
  3. Have a backup sh such as /bin/sh.static.

Do all three.

Related Topic