If the local directory database is damaged, boot into single-user mode by holding down -S as the system starts up. Next, check to see if you have a backup of the NetInfo database. The daily periodic job backs up the database each time it is run. You can find the backup in /var/backups/local.nidump. If you don't have a backup, you won't be able to restore. The local.nidump file is overwritten each time the cron job runs, so make sure you back it up regularly (preferably to some form of removable media).
If your computer is generally not turned on at 3:15 a.m. (the default time for the daily periodic job), you'll never get a backup of your local directory. You can solve this problem by editing com.apple.periodic-daily.plist to run this job at a different time, or to run the job periodically with the command sudo periodic daily. See "Periodic Jobs" in Chapter 4 for more details.
If you totally mess up and find that you forgot to backup your NetInfo database, you can stop at step 5 and issue the command rm /var/db/.AppleSetupDone. This makes Mac OS X think that it's being booted for the first time when you restart, forcing it to run the Setup Assistant so you can create the initial user for the system, thus bringing your system to a usable state for further repairs.
After the system boots in single-user mode, you should:
Wait for the root# prompt to come up.
Fix any filesystem errors:
# /sbin/fsck -fy
Mount the root filesystem as read/write:
# /sbin/mount -uw /
Change directories and go to the NetInfo database directory:
# cd /var/db/netinfo/
Move the database out of the way and give it a different name:
# mv local.nidb/ local.nidb.broken
Start enough of the system to use NetInfo. The /etc/rc script also creates a blank NetInfo database when it sees that it no longer exists:
# sh /etc/rc
Wait for a while for the system to become ready just before it's ready, you should see the screen go blue as though it's going to show you the login window, However, it will return to the verbose boot screen with the black background, and you can press Control-L or Return to get your shell prompt back. Next, load the backup into NetInfo:
# /usr/bin/niload -d -r / . < /var/backups/local.nidump
When it saw that the NetInfo database needed to be recreated, /etc/rc deleted the .AppleSetupDone file, so you need to recreate it:
# touch /var/db/.AppleSetupDone
After you have completed these steps, reboot the system with the reboot command.