Skip to main content
added 105 characters in body
Source Link
  • Remove the flag indicating that the initial setup has been done.

rm /var/db/.AppleSetupDone

  • Reboot or shutdown.
  • Reboot or shutdown.
  • Remove the flag indicating that the initial setup has been done.

rm /var/db/.AppleSetupDone

  • Reboot or shutdown.
Source Link

The instructions below were tested on OS X 10.6 and 10.7.

Preflight

  1. Back up any data you wish to retain.
  2. Make backup copies of iLife applications (iPhoto, GarageBand, iMovie, iWeb, iDVD).
  3. Deactivate relevant licensed software such Adobe CS.
  4. Unregister the machine from your iTunes account.

OS Cleanup

  1. Boot from an external OS X install media, if you wish to completely wipe the hard drive. Boot from the recovery partition (hold ⌘-R on power-up) if you wish to retain the recovery partition as-is.

  2. If booting from external media, use the Disk Utility to repartition the hard drive with one partition. Note: With SSDs, you ideally should first use a utility that lets you do a secure erase of the medium instead.

  3. Use the Disk Utility to erase (zero out) the hard drive. This will take an hour or longer on a mechanical drive, and at least several minutes on an SSD. If it takes just a minutes, you didn't zero the disk!

  4. Reinstall the OS X. Create a user account called factory.

  5. Reinstall iLife either from media, or by copying it from the backup you've made in preflight.

  6. Perform all system updates.

Restoring the Out-Of-Box Experience

Boot into the single-user mode by holding down ⌘-S during boot. A bare console will appear in a dozen seconds or so.

  • Remount the root partition in read-write mode.

    /sbin/mount -uw /

  • Start the directory services.

    • OS X Lion and higher:

    launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist

    Ignore the error related to com.apple.DirectoryServicesLocal.plist

    • OS X Snow Leopard:

    launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServices.plist

  • Access the directory services command line utility and remove the factory user:

dscl . (that's dscl, space, period)

list /Users shows the user list. The factory user should be there. That's the only one we care about. The usernames starting with an underline, those are system accounts that have to be left alone. Same goes for the daemon, Guest, messagebus, nobody and root accounts.

read /Users/factory GeneratedUID shows the UID of the user, we'll need it below.

delete /Groups/admin GroupMembers <uid>, where UID is given above. Don't worry if you enter it wrong, you'll receive an error message. Press to go back and edit the command.

delete /Groups/admin GroupMembership factory

delete /Users/factory

exit

  • Remove the factory's home folder.

rm -R /Users/factory/

  • Remove the caches.

rm -R /Library/Caches/* rm -R /var/vm/swapfile*

  • Reboot or shutdown.

reboot or shutdown -h now