May 19

Recovering from a corrupt rc.conf

Sometimes we may make a mistake in the rc.conf file – either a syntax error or loading something which causes the system to crash. In such a case we need to fix the rc.conf file so that the system can boot normally.

The steps to do this are given below:

  • Boot into single user mode
  • When prompted for a shell pathname,  press Enter
  • Type mount -urw / to re-mount the root file system in read/write mode.
  • Type mount -a -t ufs to mount the current file system so that you can runyour preferred editor eg. vi
  • Edit /etc/rc.conf as required and save it
  • Restart the system
Apr 21

Always Keep root shell as part of base OS

Most people keep bash as their preferred shell program in FreeBSD. The problem with bash is that it does not come as part of the default FreeBSD package – it has to be installed as a third party application either using pkg_add or by compiling it from ports.

chsh -s /usr/local/bin/bash

If for some reason your ports tree has corruption or the bash port or a supporting port has not been updated properly, you might get locked out from the system the next time you try to log in. The problem would be that root uses bash for login and bash is not working in the ports so you can’t get in.

The way around such a case is to log in to single user mode and set the root shell back to something like sh or tcsh.

To prevent such a thing from happening in the first case, always keep the root shell as something which is not dependent on third party libraries. If you must keep bash then link it statically from ports by specifying WITH_STATIC_BASH during building.

My own preference is install bash but keep csh as the root shell. Once I have logged in to root, I manually run bash and then continue using bash.