Last Updated: April 10, 2016
· blakemesdag

Slim your OS X CI virtual machines

If you're building VMs for CI with packer you can usually safely remove many extras. The desktop wallpapers and screensavers account for 440MiB and 140MiB on their own in El Capitan:

# Removes unneeded files from OS X, saves 2-3 GB disk space.

set -ex

echo "Removing unused directories..."
              "/Library/Desktop Pictures/" 
              "/Library/Screen Savers/" 

for i in "${directories[@]}"
   rm -rf "$i"

echo "Removing recovery disk..."
diskutil list

# Erase recovery disk
diskutil eraseVolume Free Space /dev/disk1s3

# Expand main volume to max size, to actually use the extra free space
diskutil resizeVolume /dev/disk1s2 R