Getting a Terminal window on start up (X with root permissions)

There are times when you need to get a terminal window during system start up but the system must not be booted into a user environment. That is to say, that you want it to be in the root “x windows” session similar to the one that is launched when you just installed the Mac.

A way to get to this state is to ensure that the /var/db/.AppleSetupDone file DOES NOT exist. Once that file is removed, the machine would boot up into the Setup Assistant. However, You do not want the default Setup Assistant to run. Instead, you want a terminal window.

In order to achieve this, all that has to be done is to replace the Setup Assistant binary file with a script. The Setup Assistant resides in /System/Library/CoreServices/Setup Assistant.app/Contents/MacOS. Move the original as a backup and replace it with a script that does this. Remember to make it executable.

#!/bin/sh
open -a "Terminal.app"
while [ `ps -ef | grep Terminal | wc -l` -gt 1 ]; do
  sleep 5;
done

Reboot the system and you should have a nice Terminal started with ROOT permissions.

Just Remember to move the original Setup Assistant binary when you are done.