Restoring /bin/bash after deletion

Q While experimenting with a Red Hat Enterprise Linux 3 installation and trying to break and fix things, I unintentionally deleted /bin/bash. The operating system obviously crashed but I found mysel at odds with what to do next. I was unable to boot the machine into runlevel 1 as this still, apparently just like everything else, uses Bash. I would appreciate any insight on what could be done should a similar situation ever happen on a live machine.

A Most of EL3's startup scripts require /bin/bash or /bin/sh, which is no more than a symbolic link to the former. At the kernel selection menu in Grub, hitting 'A' allows for parameters to be passed to the selected kernel. Adding init=/bin/bash would typically bypass all the init scripts and drop you straight into a shell. This is not much use if Bash has been deleted. However, most distributions include a number of other shells, including Ksh and Tcsh. In this case init=/bin/ash is a valid option. With the system booted straight into the chosen shell, the / partition finds itself mounted as read-only. The first task is to remount as read/write:

# mount -o rw,remount /dev/hda2 /

If the missing files are available they can be copied over and the right ownership and permissions set. Alternatively, mounting the installation media, the Bash RPM can be forcibly re-installed (the RPM with EL3 came on the second CD). Run

# mount /mnt/cdrom
# rpm -Uvh --force /mnt/cdrom/RedHat/RPMS/bash*.rpm

A somewhat more elegant way is to boot the server off the installation media into the Red Hat rescue mode (linux rescue). The rescue mode tries to mount the root partition as /mnt/sysimage. The Bash RPM could then be copied to /mnt/sysimage/tmp and installed form an alternative shell chrooted to /mnt/sysimage, thus:

# chroot /mnt/sysimage /bin/tcsh
# rpm -Uvh --force /tmp/bash*.rpm

Back to the list