Skip to content

Instantly share code, notes, and snippets.

@un33k
Last active March 6, 2018 21:17
Show Gist options
  • Save un33k/31ae31805d829272d883 to your computer and use it in GitHub Desktop.
Save un33k/31ae31805d829272d883 to your computer and use it in GitHub Desktop.
Create bootable OSX ISO
#!/bin/bash
# Use with care ...
# -----------------------------------------
# Mountain Lion, Mavericks, Yosemite ..
OS=Yosemite
# Mount the installer image
hdiutil attach /Applications/Install\ OS\ X\ "$OS".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/"$OS"
# Increase the sparse bundle capacity to accommodate the packages
hdiutil resize -size 8g /tmp/"$OS".sparseimage
# Mount the sparse bundle for package addition
hdiutil attach /tmp/"$OS".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/
# 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/"$OS".sparseimage | tail -n 1 | awk '{ print $1 }'`b /tmp/"$OS".sparseimage
# Convert the sparse bundle to ISO/CD master
hdiutil convert /tmp/"$OS".sparseimage -format UDTO -o /tmp/"$OS"
# Remove the sparse bundle
rm /tmp/"$OS".sparseimage
# Rename the ISO and move it to the desktop
mv /tmp/"$OS".cdr ~/Desktop/"$OS".iso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment