Archived - Mac OS X, Mac OS X Server: How to Replace the NetInfo Database

This document explains how to replace the NetInfo database in the event that you need to either restore it from a backup copy or replace it with the default version.

This document applies to Mac OS X and Mac OS X Server versions 10.2 and later.

This article has been archived and is no longer updated by Apple.


    1. Creating a new NetInfo database from the default data erases all changes that you have made to NetInfo since installation. If you have invested a lot of time configuring a NetInfo database, you should revert to default only as a last resort. When possible, it is generally easier to restore the contents of the NetInfo database from backup.

    2. If you are not very familiar with NetInfo, this is something you should only do when instructed by a knowledgeable person. Otherwise, this is not a recommend part of normal troubleshooting. When possible, this procedure should be performed by someone who has experience using the command line interface. Misuse of commands such as "rm" may result in data loss. Be sure to type commands exactly. You may verify spacing by copying and pasting the commands into a text editor.

    3. This procedure will not work if you deselected the BSD package as part of a custom installation. In that scenario, the create_nidb script is not installed.

I. Start up the computer in single-user mode

Whether you are restoring from a backup or replacing with default values, you will need to start up the computer in single-user mode by pressing the Command-S key combination during startup. For more information, see technical document 106388, "

Mac OS X: How to Start Up in Single-User or Verbose Mode



Once started up in single-user mode, the file system is available as read only. You must access it as read-write, and you should also run fsck for safety. Follow these steps:

    1. At the prompt (#), type:

    /sbin/fsck -fy

    2. Press Return. fsck will then run.
    3. At the next prompt, type:

    /sbin/mount -uw /

    4. Press Return.


The file system is now available as read-write. Steps for restoring from a backup and replacing with default differ, and each is described in its own section below. In the following sections, each line that begins with the prompt (#) is a command that you should execute by typing and pressing Return.

II. Restoring from a backup

A backup of your NetInfo database(s) is made at 03:15 any day that the computer is on at that time. This backup is stored at /var/backups/. If you have accidentally made catastrophic changes to your NetInfo configuration, you can restore the last backed-up version. If your computer is a server that is always on, then you should have a backup less than 24 hours old. If you must use Step 3 of this section to restore a network database, you should save a copy of the file described in Section IV before starting up into single-user mode.


    1. Start up the computer in single-user mode as described above.
    2. These commands rename the current local NetInfo database and replaces it with the archived copy:

    # mv /var/db/netinfo/local.nidb /var/db/netinfo/local.nidb.bad
    # /usr/libexec/create_nidb

    Note: Skip to Step 4 if you do not have a network database to restore. You would only have a network NetInfo database if you have created a network level NetInfo domain.

    3. To restore the network database, you must first save a copy of the script text found in Section IV of this document. The following group of commands makes the text file you created executable and then executes it. The script creates a skeletal NetInfo domain with the user and machine entries needed to start up the NetInfo database and restore the backup. Where the commands say "yourhostname", substitute your computer's actual hostname, likewise for "youripaddress". For "yourpath", substitute the actual path to the location to which you saved create_restore_nidb.

    # cd /var/db/netinfo
    # mv network.nidb network.nidb.bad
    # chmod u+x /yourpath/create_restore_nidb
    # /yourpath/create_restore_nidb yourhostname youripaddress

    4. These commands will start the network, the NetInfo system, and load the local database with the back up data. You will see a number of messages output.

    In 10.2:


    # /usr/libexec/kextd 
    # /usr/sbin/configd 
    # /sbin/SystemStarter 
    # /usr/bin/niload -d -r -t / localhost/local < /var/backups/local.nidump

    In 10.3:


    # /usr/libexec/kextd
    # /usr/sbin/configd
    # /usr/sbin/lookupd
    # cd /var/db/netinfo
    # /usr/sbin/netinfod -s local
    # /usr/bin/niload -d -r -t / localhost/local < /var/backups/local.nidump

    In 10.4:


    # sh /etc/rc
    # /usr/bin/niload -d -r -t / localhost/local < /var/backups/local.nidump

    5. Optional - execute this command if you have network NetInfo database and completed step 4 (the niload command in step 4 is optional if you are only restoring the network domain and not the local domain). Otherwise, go to Step 6.

    In 10.3


    # cd /var/db/netinfo
    # /usr/sbin/netinfod -s network
    # /usr/bin/niload -d -r -t / yourhostname/network < /var/backups/network.nidump

    In 10.2 and 10.4


    # /usr/bin/niload -d -r -t / yourhostname/network < /var/backups/network.nidump
    6. This restarts the computer with your NetInfo database restored.

    # reboot

III. Restoring from defaults

If you do not have a good backup or just want to start over, you can restore from defaults. Follow these steps:


1. Start up the computer in single-user mode, as described above.


2. This command renames the current NetInfo database, so that it may subsequently be automatically replaced:

# mv /var/db/netinfo/local.nidb /var/db/netinfo/local.nidb.bad

3. Optional - if you have a network domain:

# mv /var/db/netinfo/network.nidb /var/db/netinfo/network.nidb.bad

Note: You may also want to move any other nibd folders in /var/db/netinfo that are not being restored.


4. Remove the AppleSetupDone file:

# rm /var/db/.AppleSetupDone

5. Restart the computer:

# reboot

This sets your computer back to a default NetInfo configuration, as it was when you first installed Mac OS X. When the computer is finished starting up, the Setup Assistant will appear.

IV. create_restore_nidb script

To save a copy of the script, follow these steps:


1. Copy below this line:


# Create a barebones NetInfo database that can be restored from niload. 
# Usage: create_restore_nidb masterhostname ipaddress 
# The default tag is network. 

use Sys::Hostname; 

my $usage = "Usage: create_restore_nidb masterhostname ipaddress [tag]\nThe default tag is network\n"; 

my $nipath = "/var/db/netinfo"; 

if ($ARGV[0]) { $master = $ARGV[0]; } 
    die $usage 

if ($ARGV[1]) { $ipaddress = $ARGV[1]; } 
    die $usage 

if ($ARGV[2]) { $tag = $ARGV[2]; } 
    $tag = network 

my $nidb = "${NIPATH.EN_US}/${TAG.EN_US}.nidb"; 

die "Error: database ${NIDB.EN_US} exists\n" if (-d ${NIDB.EN_US}); 

my $nicl = "nicl -q -raw ${NIDB.EN_US}"; 

# For debugging: 
open(NICL, ">/dev/tty");  

# Create the database 

system("${NICL.EN_US} -create"); 
open(NICL, "|${NICL.EN_US}"); 

# Setup root directory 

print NICL "create / master ${MASTER.EN_US}/${TAG.EN_US}\n"; 

print NICL "create /users\n"; 
print NICL "create /machines\n"; 

# Create a root user 

print NICL "cd /users\n"; 
    print NICL "create root\n"; 
    print NICL "cd root\n"; 
    print NICL "create . passwd *\n"; 
    print NICL "create . uid 0\n"; 
    print NICL "create . gid 0\n"; 
    print NICL "create . change 0\n"; 
    print NICL "create . expire 0\n"; 
    print NICL "create . realname \"System Administrator\"\n"; 
    print NICL "create . home /var/root\n"; 
    print NICL "create . shell /bin/tcsh\n"; 
    print NICL "create . _writers_passwd root\n"; 
    print NICL "cd ..\n"; 

# Create an entry for this machine 
print NICL "cd /machines\n"; 
print NICL "create $master ip_address $ipaddress\n"; 
print NICL "create $master serves ./${TAG.EN_US} ${MASTER.EN_US}/local\n"; 

print NICL "quit\n"; 
close (NICL); 


Stop copying above this line.


2. In Terminal (/Applications/Utilities/), type:


3. Press Return. This opens the pico text editor within Terminal.


4. Paste the copied text into pico.


5. Press the up arrow key to scroll to the top of the copied text in pico. You will find two blank lines at the top, which you must delete.


6. Press the Control-O key combination to write out (save) the file.


7. When prompted for the name, type:


8. Press Return. You should see a message indicating that the file was written.


9. Press Control-X to exit pico.


You now have a copy of the file create_restore_nidb in the directory in which you are working in Terminal, which is your Home directory by default. You may verify the location of the file by looking in your Home directory in a Finder window. When the file is there, it has a pathname of: ~/create_restore_nidb


You may use that pathname in Step 3 of Section, for example:

# chmod u+x ~/create_restore_nidb


You may use text editors other than pico, but you should use pico for best results. When copying and pasting from a Web browser, unintended characters may be inserted when using a text editor other than pico, preventing the script from working.

Last Modified: Jul 11, 2012
Not helpful Somewhat helpful Helpful Very helpful Solved my problem
Print this page
  • Last Modified: Jul 11, 2012
  • Article: HT2600
  • Views:

  • Rating:
    • 61.0

    (531 Responses)

Additional Product Support Information

Start a Discussion
in Apple Support Communities
See all questions on this article See all questions I have asked