Last active
November 11, 2016 22:48
-
-
Save elifiner/3443e3f0d8f2ca3ca4abb535609942f8 to your computer and use it in GitHub Desktop.
Create a bootable USB stick from an ISO image on OSX, command line alternative to Unetbootin
This file contains 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
#!/usr/bin/env bash | |
if [ -z $2 ]; then | |
echo "Create a bootable USB stick from an ISO image." | |
echo | |
echo "Usage: $0 <iso> <disk>" | |
echo | |
echo "Target disks:" | |
diskutil list | grep '^/dev' | grep 'external' | sed -e 's/disk/rdisk/' -e 's/:$//' -e 's/^/ /' | |
exit 1 | |
fi | |
if [ ! `which pv` ]; then | |
echo "Error: pv not installed" | |
echo "Install using 'brew install pv'" | |
exit 1 | |
fi | |
sudo ls > /dev/null | |
ISO=$1 | |
DISK=$2 | |
IMAGE=${ISO%.*}.img.dmg | |
echo "Converting ISO to IMG..." | |
[ -f $IMAGE ] && mv $IMAGE $IMAGE.bk | |
hdiutil convert -format UDRW -o $IMAGE $ISO > /dev/null | |
echo "Erasing target disk..." | |
diskutil partitionDisk $DISK 1 "Free Space" "unused" "100%" > /dev/null | |
echo "Copying..." | |
SIZE=`stat -f%z $IMAGE` | |
sudo dd if=$IMAGE | pv -s $SIZE | sudo dd of=$DISK bs=1m | |
echo "Ejecting..." | |
diskutil eject $DISK > /dev/null | |
echo "Done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment