Skip to content

Instantly share code, notes, and snippets.

@baseboxorg
Forked from un33k/osx_bootable_iso.sh
Last active May 22, 2016 08:03
Show Gist options
  • Save baseboxorg/336b3ed406124aed024f842df3541a60 to your computer and use it in GitHub Desktop.
Save baseboxorg/336b3ed406124aed024f842df3541a60 to your computer and use it in GitHub Desktop.
Create bootable OSX ISO
#!/bin/bash
# Use with care ...
# -----------------------------------------
# Mountain Lion, Mavericks, Yosemite ..
OS="El Capitan"
IMG_SIZE=8g
BUILD_MNT=/tmp/"$OS"_Build
INSTALL_MNT=/tmp/"$OS"_Install
INSTALL_DMG=/Applications/Install\ OS\ X\ "$OS".app/Contents/SharedSupport/InstallESD.dmg
OS_CDR=/tmp/"$OS"
# Mount the installer image
hdiutil attach "$INSTALL_DMG" -noverify -nobrowse -mountpoint "$INSTALL_MNT"
# Convert the boot image to a sparse bundle
hdiutil convert "$INSTALL_MNT"/BaseSystem.dmg -format UDSP -o "$OS_CDR"
# Increase the sparse bundle capacity to accommodate the packages
hdiutil resize -size $IMG_SIZE "$OS_CDR".sparseimage
# Mount the sparse bundle for package addition
hdiutil attach "$OS_CDR".sparseimage -noverify -nobrowse -mountpoint "$BUILD_MNT"
# Remove Package link and replace with actual files
rm -rf "$BUILD_MNT"/System/Installation/Packages
cp -rp "$INSTALL_MNT"/Packages "$BUILD_MNT"/System/Installation/
# Unmount the installer image
hdiutil detach "$BUILD_MNT"
# Unmount the sparse bundle
hdiutil detach "$INSTALL_MNT"
# Resize the partition in the sparse bundle to remove any free space
hdiutil resize -size `hdiutil resize -limits "$OS_CDR".sparseimage | tail -n 1 | awk '{print $ 1}' `b "$OS_CDR".sparseimage
# Convert the sparse bundle to ISO/CD master
hdiutil convert "$OS_CDR".sparseimage -format UDTO -o "$OS_CDR"
# Remove the sparse bundle
rm "$OS_CDR".sparseimage
# Rename the ISO and move it to the desktop
mv "$OS_CDR".cdr ~/Desktop/"$OS".iso
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment