I'm ready to resell my Mac, and I'd like to prepare it for the new user, giving them factory-like out of box experience. Even better, I'd like the system to be fully updated, yet come up with no user accounts, starting into the initial setup as if one just unboxed it. Of course performing the updates and software preinstallation requires to set up a temporary user account :(
The instructions below were tested on OS X 10.6 and 10.7.
- 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.
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
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.
- 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
dscl .(that's dscl, space, period)
list /Usersshows the user list. The
factoryuser 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 GeneratedUIDshows 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
Remove the factory's home folder.
rm -R /Users/factory/
Remove the caches.
rm -R /Library/Caches/*
rm -R /var/vm/swapfile*
Remove the flag indicating that the initial setup has been done.
Reboot or shutdown.
shutdown -h now
If you're on 10.7 or later and you don't need to perform any updates or install any software, you should normally just erase and reinstall OS X from the recovery partition.
- Hold command-R on startup
- Erase either the OS X partition or the whole drive from Disk Utility. If you don't have an SSD, press the "Security Options..." button and choose the single pass option. If you have an SSD, the "Security Options..." button is grayed out, but http://support.apple.com/kb/ht3680 says that "a standard erase makes it difficult to recover data from an SSD".
- Choose Install OS X.
See these Apple KB articles:
- OS X Mavericks: Erase and reinstall OS X
- OS X Mountain Lion: Erase and reinstall OS X
- OS X: How to erase and install
I'm not sure if you should erase the whole drive or just the OS X partition. The Apple KB articles tell you to erase the "startup disk", which generally means the OS X partition. If you have other partitions like a Windows partition, you should probably erase the whole drive.
If you erase the whole drive, the recovery partition (which is hidden from Disk Utility) is also erased. If you don't restart, the contents of the recovery partition will stay in memory and you can continue to the step for reinstalling OS X, which will also create a new recovery partition. If you do restart, your Mac can still download the contents of the recovery partition from Apple's servers if it supports Internet Recovery mode.