The instructions below were tested on OS X 10.6 and 10.7.
Preflight
- Back up any data you wish to retain.
- Make backup copies of iLife applications (iPhoto, GarageBand, iMovie, iWeb, iDVD).
- Deactivate relevant licensed software such Adobe CS.
- Unregister the machine from your iTunes account.
OS Cleanup
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.
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.
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!
Reinstall the OS X. Create a user account called factory
.
Reinstall iLife either from media, or by copying it from the backup you've made in preflight.
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.
launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist
Ignore the error related to com.apple.DirectoryServicesLocal.plist
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/
rm -R /Library/Caches/*
rm -R /var/vm/swapfile*
reboot
or shutdown -h now