UPDATE 1/23/09: some commenters asked about cleanup of the LKDC (new in Leopard) – I’ve added that to the script.
At the Macworld Expo 2009 Power Tools System Imaging and Deployment session today, I was asked to share a “checklist” of cleanup steps I use when building images the “classic” way. (The InstaDMG methodology of image building makes cleanup steps unneeded.)
Here’s a cleaned-up version of the script I use, with site-specific stuff removed for the most part.
If you use this, you’ll need to modify the paths to any local user home directories for any local users you have on your image. There are generic examples for a local admin user named “admin” and the root user (which if you never login as root, you shouldn’t have to clean up!)
#!/bin/sh #this script does some cleanup in preperation for building an image #best to run this from single user mode, or at least right before you shutdown #run this as root, or with sudo rights #set machine names back to generic /usr/sbin/scutil --set ComputerName "OSX_Standard_Image" /usr/sbin/scutil --set LocalHostName "osximg" #delete swapfiles rm /private/var/vm/swapfile* #delete volume info DB rm /private/var/db/volinfo.database #cleanup local admin's home dir rm -rf /Users/admin/Desktop/* rm -rf /Users/admin/Documents/* rm -rf /Users/admin/Library/Caches/* rm -rf /Users/admin/Library/Recent\ Servers/* rm -rf /Users/admin/Library/Logs/* rm -rf /Users/admin/Library/Keychains/* rm -rf /Users/admin/Library/Preferences/ByHost/* rm -f /Users/admin/Library/Preferences/com.apple.recentitems.plist rm -rf /Users/admin/Movies/* rm -rf /Users/admin/Music/* rm -rf /Users/admin/Pictures/* rm -rf /Users/admin/Public/Drop\ Box/* #cleanup root's home dir rm -rf /private/var/root/Desktop/* rm -rf /private/var/root/Documents/* rm -rf /private/var/root/Downloads/* rm -rf /private/var/root/Library/Caches/* rm -rf /private/var/root/Library/Recent\ Servers/* rm -rf /private/var/root/Library/Logs/* rm -rf /private/var/root/Library/Keychains/* rm -rf /private/var/root/Library/Preferences/ByHost/* rm -f /private/var/root/Library/Preferences/com.apple.recentitems.plist rm -rf /private/var/root/Public/Drop\ Box/* #clean up global caches and temp data rm -rf /Library/Caches/* rm -rf /System/Library/Caches/* rm -rf /Users/Shared/* rm -f /private/etc/ssh_host* #network interfaces - this is regenerated on reboot and can differ on different hardware rm /Library/Preferences/SystemConfiguration/NetworkInterfaces.plist #Leopard - cleanup local KDC, see http://support.apple.com/kb/TS1245 /usr/sbin/systemkeychain -k /Library/Keychains/System.keychain -C -f rm -rf /var/db/krb5kdc /usr/bin/defaults delete /System/Library/LaunchDaemons/com.apple.configureLocalKDC Disabled #log cleanup. We touch the log file after removing it since syslog #won't create missing logs. rm /private/var/log/alf.log touch /private/var/log/alf.log rm /private/var/log/cups/access_log touch /private/var/log/cups/access_log rm /private/var/log/cups/error_log touch /private/var/log/cups/error_log rm /private/var/log/cups/page_log touch /private/var/log/cups/page_log rm /private/var/log/daily.out rm /private/var/log/ftp.log* touch /private/var/log/ftp.log rm -rf /private/var/log/httpd/* rm /private/var/log/lastlog rm /private/var/log/lookupd.log* rm /private/var/log/lpr.log* rm /private/var/log/mail.log* touch /private/var/log/lpr.log rm /private/var/log/mail.log* touch /private/var/log/mail.log rm /private/var/log/monthly.out rm /private/var/log/run_radmind.log rm -rf /private/var/log/samba/* rm /private/var/log/secure.log touch /private/var/log/secure.log rm /private/var/log/system.log* touch /private/var/log/system.log rm /private/var/log/weekly.out rm /private/var/log/windowserver.log touch /private/var/log/windowserver.log rm /private/var/log/windowserver_last.log rm /private/var/log/wtmp.*