Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolaj86/8c36d132250163011c83bad8284975ee to your computer and use it in GitHub Desktop.
Save coolaj86/8c36d132250163011c83bad8284975ee to your computer and use it in GitHub Desktop.
How to create a bootable El Capitan Installer from MacOS. See https://bootableinstaller.com
################################################################################
# See bootableinstaller.com #
################################################################################
# set strict and verbose modes for bash
set -e
set -u
# If the script already ran once successfully, don't re-run
if [ -f "el-capitan.iso" ]; then
echo "'el-capitan.iso' already exists"
exit 0
fi
# Test for variations of InstallESD.dmg
my_installesd="./InstallESD.dmg"
if [ -f "./ElCapitanInstallESD.img" ]; then
my_installesd="./ElCapitanInstallESD.img"
fi
if [ -f "./ElCapitanInstallESD.dmg" ]; then
my_installesd="./ElCapitanInstallESD.dmg"
fi
if [ -f "./InstallESD.img" ]; then
my_installesd="./InstallESD.img"
fi
# Prompt the user to download InstallMacOSX.dmg if it doesn't exist
if ! [ -f "$my_installesd" ]; then
if ! [ -f "InstallMacOSX.dmg" ]; then
echo "Error: Did not find 'InstallMacOSX.dmg'"
echo " 1. Go to https://support.apple.com/en-us/HT206886 (How to upgrade to OS X El Capitan)"
echo " 2. Click the 'Download OS X El Capitan' link in Step 4"
echo " 3. Copy 'InstallMacOSX.dmg' to this folder ("$(pwd)")"
exit 1
fi
# show output of each command
set -x
# Mount the Full Installer and extract the Install System
hdiutil attach InstallMacOSX.dmg -noverify -nobrowse -mountpoint '/Volumes/Install OS X/'
pkgutil --expand '/Volumes/Install OS X/InstallMacOSX.pkg' './Install OS X/'
hdiutil detach '/Volumes/Install OS X'
mv './Install OS X/InstallMacOSX.pkg/InstallESD.dmg' "$my_installesd"
# Cleanup
rm -rf './Install OS X/'
else
# show output of each command
set -x
fi
# Mount DMG Installer
hdiutil attach "$my_installesd" -noverify -nobrowse -mountpoint '/Volumes/OS X Install ESD/'
# Create a DMG Disk
# (this exact file created by this command is included at bootableinstaller.com as 'empty.7900m.dmg.bz2')
# This is 656mb bigger than it needs to be, might might as well leave the excess for potential variation
if ! [ -f "el-capitan.dmg" ]; then
hdiutil create -o ./el-capitan -size 7900m -volname el-capitan -layout SPUD -fs HFS+J
fi
# Mount el-capitan.dmg disk to your macOS
hdiutil attach ./el-capitan.dmg -noverify -mountpoint /Volumes/el-capitan
# Create Installer Disk
# (in recovery mode the system is already mounted as 'OS X Base System', hence the weird stuff)
asr restore -source '/Volumes/OS X Install ESD/BaseSystem.dmg' -target /Volumes/el-capitan -noprompt -noverify -erase
hdiutil detach '/Volumes/OS X Base System' || true
hdiutil detach '/Volumes/OS X Base System 1' || true
hdiutil detach '/Volumes/el-capitan' || true
hdiutil attach ./el-capitan.dmg -noverify -mountpoint /Volumes/el-capitan
rm '/Volumes/el-capitan/System/Installation/Packages'
cp -rp '/Volumes/OS X Install ESD/Packages' '/Volumes/el-capitan/System/Installation/'
cp -rp '/Volumes/OS X Install ESD/BaseSystem.chunklist' '/Volumes/el-capitan'
cp -rp '/Volumes/OS X Install ESD/BaseSystem.dmg' '/Volumes/el-capitan'
hdiutil detach '/Volumes/el-capitan'
hdiutil detach '/Volumes/OS X Install ESD'
# Convert DMG Disk to ISO File
# (this turns out to be a straight copy, as the image was created in the correct format)
# hdiutil convert ./el-capitan.dmg -format UDTO -o ./el-capitan
# Move DMG to ISO, here
mv ./el-capitan.dmg el-capitan.iso
# Cleanup
# rm -f ./el-capitan.dmg
# Many thanks to https://techsviewer.com/install-macos-elcapitan-virtualbox-windows/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment