Last active
August 29, 2015 14:12
-
-
Save mitio/5717e0bc607d00b86df9 to your computer and use it in GitHub Desktop.
A script to convert an .iso file to a format suitable for creating a bootable USB (Mac OS X-specific)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
if [ "$1" = "" -o "$2" = "" ]; then | |
echo "Usage: $0 /path/to/source.iso /dev/usb_disk_device" >&2 | |
exit 1 | |
fi | |
iso_source="$1" | |
usb_disk="$2" | |
if [ ! -f "$iso_source" ]; then | |
echo "Source does not exist: $iso_source" >&2 | |
exit 2 | |
fi | |
if [ ! -b "$usb_disk" -a ! -c "$usb_disk" ]; then | |
echo "The selected USB disk device does not exist: $usb_disk (or is neither a block-special device, nor a character-special one)" >&2 | |
exit 3 | |
fi | |
echo "Converting $iso_source to .img..." | |
hdiutil convert -format UDRW -verbose -o "$iso_source.img" "$iso_source" | |
if [ -f "$iso_source.img.dmg" ]; then | |
mv -v "$iso_source.img.dmg" "$iso_source.img" | |
fi | |
echo "Unmounting the USB drive $usb_disk..." | |
diskutil unmountDisk "$usb_disk" | |
if [ -b "$usb_disk" ]; then | |
fast_usb_disk="/dev/r`basename $usb_disk`" | |
if [ -c "$fast_usb_disk" ]; then | |
echo "Using $fast_usb_disk as it should be faster than $usb_disk" | |
else | |
fast_usb_disk="$usb_disk" | |
fi | |
else | |
fast_usb_disk="$usb_disk" | |
fi | |
echo "Copying the image file to $fast_usb_disk..." | |
sudo dd if="$iso_source.img" of="$fast_usb_disk" bs=1m | |
echo "Copying done, ejecting $usb_disk..." | |
diskutil eject "$usb_disk" | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment