Skip to content

Instantly share code, notes, and snippets.

@verhovsky
Last active July 3, 2017 06:41
Show Gist options
  • Save verhovsky/a3c754023aa0215f039597735451497a to your computer and use it in GitHub Desktop.
Save verhovsky/a3c754023aa0215f039597735451497a to your computer and use it in GitHub Desktop.
create bootable usb from .iso file on macOS
# if you want to boot a laptop from a USB drive and you have a file like archlinux-2017.07.01-x86_64.iso
# (and a USB drive plugged in), this is a script to copy the .iso onto the USB drive.
# like UNetbootin but debuggable.
# https://apple.stackexchange.com/questions/179781/how-to-create-a-bootable-ubuntu-usb-stick-using-os-x-10-10-2
ls
echo "path to .iso?"
read iso_filepath
echo "rm /tmp/linux.dmg"
rm /tmp/linux.dmg 2>/dev/null
echo
echo "converting .iso to .dmg"
echo "hdiutil convert $iso_filepath -format UDRW -o /tmp/linux # adds a .dmg to output"
hdiutil convert $iso_filepath -format UDRW -o /tmp/linux # adds a .dmg to output
echo
if ! [[ $(diskutil list external) ]]; then
echo "your USB drive isn't plugged in. quitting"
exit
fi
diskutil list external
echo "which /dev/diskX is the flash drive that should be overwritten (just the number)?"
read disk_number
disk=/dev/disk$disk_number
rdisk=/dev/rdisk$disk_number # supposedly faster
echo "diskutil unmountDisk $disk"
diskutil unmountDisk $disk
echo
echo "copying .dmg file to the USB drive, this might take a while"
echo "if this errors, try to lowercase 1M to 1m in bs=1M"
echo "sudo dd if=/tmp/linux.dmg of=$rdisk bs=1M"
sudo /bin/dd if=/tmp/linux.dmg of=$rdisk bs=1M
diskutil eject $disk
echo
echo "done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment