Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 66 lines (47 sloc) 2.097 kb
#!/usr/bin/env bash
if [[ ! "$1" || "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
Create an OS X "USB Install Stick" from InstallESD.dmg
http://benalman.com/
Usage: sudo $(basename "$0") source_image target_path
Before running this script, open Disk Utility and partition a USB Stick like:
* 1 Partition
* Options -> GUID Partition Table
* Mac OS Extended (Journaled)
* Name: Foobar
Then run this script like: sudo $(basename "$0") InstallESD.dmg /Volumes/Foobar
Copyright (c) 2012 "Cowboy" Ben Alman
Licensed under the MIT license.
http://benalman.com/about/license/
HELP
[[ "$1" ]]; exit; fi
dmg_path="$1"
usb_path="${2%/}"
[[ $UID != 0 ]] && echo "Error: please run with sudo" && exit 1
[[ ! -e "$dmg_path" ]] && echo "Error: source \"$dmg_path\" not found" && exit 2
[[ ! -e "$usb_path" ]] && echo "Error: target \"$usb_path\" not found" && exit 3
usb_device="$(df | grep -w "$usb_path" | awk '{print $1}')"
# Mount image (invisibly)
dmg_mount="$(hdiutil attach "$dmg_path" -nobrowse | perl -ne 'm#(/Volumes/.*)# && print $1')"
# Restore image
asr -restore -source "$dmg_path" -target $usb_device -erase -format HFS+
# Unmount image
hdiutil detach "$dmg_mount"
# Mount usb stick (invisibly)
hdiutil attach $usb_device -nobrowse
usb_name="$(diskutil info $usb_device | perl -ne 'm#Volume Name:\s+(.*)# && print $1')"
usb_mount="$(diskutil info $usb_device | perl -ne 'm#Mount Point:\s+(.*)# && print $1')"
final_name="$(basename "$usb_mount/Install "*.app .app)"
# Add a drive icon (note: 1024x1024 icons don't appear in the boot screen on older macs)
srcicon=("$usb_mount"/*.app/Contents/Resources/InstallAssistant.icns)
volicon="$usb_mount/.VolumeIcon.icns"
cp "$srcicon" "$volicon"
# Set some properties to ensure the icon works
SetFile -c icnC "$volicon"
SetFile -a C "$usb_mount"
# Give it the proper boot screen name and keep the folder from auto-opening
bless --folder "$usb_mount" -label "$final_name"
# Rename drive
diskutil rename "$usb_name" "$final_name"
# Re-mount usb stick so that it's visible
diskutil unmount $usb_device
hdiutil attach $usb_device
Jump to Line
Something went wrong with that request. Please try again.