Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis
Last active March 14, 2016 11:59
Show Gist options
  • Save cellularmitosis/6e902579296e82ec6273 to your computer and use it in GitHub Desktop.
Save cellularmitosis/6e902579296e82ec6273 to your computer and use it in GitHub Desktop.
create_yosemite_iso.sh: Create a bootable .iso OS X Yosemite installer (for use with e.g. VirtualBox)
#!/bin/bash
# create_yosemite_iso.sh: Create a bootable .iso OS X Yosemite installer (for use with e.g. VirtualBox)
# See https://gist.github.com/cellularmitosis/6e902579296e82ec6273
# This is a (slightly) edited version of IOOI SqAR's script.
# See http://sqar.blogspot.de/2014/10/installing-yosemite-in-virtualbox.html
# Changes from IOOI SqAR's script include:
# * Use 'hdiutil makehybrid' to convert the .cdr image to a "real" .iso image.
# * Don't continue executing if you hit an error (set -e)
# * Verbose mode (set -x)
# * Place the .iso in the current directory (rather than ~/Desktop)
set -e
set -x
# Mount the installer image
hdiutil attach /Applications/Install\ OS\ X\ Yosemite.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
# Convert the boot image to a sparse bundle
hdiutil convert /Volumes/install_app/BaseSystem.dmg -format UDSP -o /tmp/Yosemite
# Increase the sparse bundle capacity to accommodate the packages
hdiutil resize -size 8g /tmp/Yosemite.sparseimage
# Mount the sparse bundle for package addition
hdiutil attach /tmp/Yosemite.sparseimage -noverify -nobrowse -mountpoint /Volumes/install_build
# Remove Package link and replace with actual files
rm /Volumes/install_build/System/Installation/Packages
cp -rp /Volumes/install_app/Packages /Volumes/install_build/System/Installation/
# Copy Base System
cp -rp /Volumes/install_app/BaseSystem.dmg /Volumes/install_build/
cp -rp /Volumes/install_app/BaseSystem.chunklist /Volumes/install_build/
# Unmount the installer image
hdiutil detach /Volumes/install_app
# Unmount the sparse bundle
hdiutil detach /Volumes/install_build
# Resize the partition in the sparse bundle to remove any free space
hdiutil resize -size `hdiutil resize -limits /tmp/Yosemite.sparseimage | tail -n 1 | awk '{ print $1 }'`b /tmp/Yosemite.sparseimage
# Convert the sparse bundle to ISO/CD master
hdiutil convert /tmp/Yosemite.sparseimage -format UDTO -o /tmp/Yosemite
# Remove the sparse bundle
rm /tmp/Yosemite.sparseimage
# Convert the .cdr to .iso
# Note: if I don't run this as sudo, I get the following error:
# hdiutil: makehybrid failed - Operation not permitted
sudo hdiutil makehybrid -iso -joliet -o Yosemite.iso /tmp/Yosemite.cdr
sudo chown ${USER} Yosemite.iso
# Remove the .cdr file
rm /tmp/Yosemite.cdr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment