Creating USB Install Media For A Mac Under Linux/BSD

Isn’t as hard as one might expect. I expected that since I was working with a Mac, that the boot media required a special and complex partition setup. Only the former is true.

In order to create the USB install media, you’ll need five items:

  • An 8 GB or larger USB 2.0 or USB 3.0 flash drive
  • A DMG file (disc image) for the release of OS X that you want or need
  • A computer running a Linux or BSD operating system
  • dmg2img[1]
  • pv[2]
  • GPT fdisk[3]
  • dosfstools[4]

I will assume that you already have some knowledge of the commandline for the OS that you are using.

Creating the install media is a relatively simple and straight forward process. As the DMG is a disc image containing multiple partitions, we need to extract and convert the correct one as it holds the installer and associated software. Look for the number of the partition with the Mac_OS_X or OS_X label by running:
dmg2img -l (OS X filename).dmg
And extract the that partition with:
dmg2img (OS X filename).dmg -p (partition number) -o (OS X filename).img
Plug the USB flash drive into your computer and wipe the MBR:
sudo dd if=/dev/zero of=/dev/sdX bs=1024 count=1
And create the partition table using either cgdisk or gdisk (both from GPT fdisk). Two partitions are needed for this to work[5]. You will need the first partition to be the EFI System partition since the drive is larger than 2 GB. This partition is 200 MB in size and has type code EF00. The second partition is the main partition where the installer and associated software that was extracted earlier will be stored. This partition may take up the rest of the space and has type code AF00. Write the partition table to disc when you’re finished. Unplug the drive from the computer and plug it back in to have the new partition table that you wrote to disc be read. Now comes the last two steps.

The EFI System needs to be formatted with a FAT32 filesystem which can be accomplished using:
sudo mkdosfs -F 32 -n EFI /dev/sdX1
The IMG file containing the installer and associated software can now be written to the last partition using:
pv (OS X filename).img | sudo dd of=/dev/sdX2 bs=4096
This will ensure that you have an ETA when copying the data so that you can take a small break.

And that’s all there is to it! Once the copying to the second partition is complete (i.e.: no light flashing on the flash drive), unplug the drive from your computer and plug it into the Mac. Immediately after Powering on the Mac, hold down the Alt or Option key (depending on your keyboard) until a menu screen shows up where you can select ‘Mac OS X Install DVD’. If that menu doesn’t show, you’ll either boot from the flash drive (as the internal hardware has no bootable partitions) or something else is wrong (and you’ll have to troubleshoot it). Either way, congratulations on making it this far and I hope you’ll continue to enjoy your Mac.

1: http://www.vu1tur.eu.org/tools/
2: http://www.ivarch.com/programs/pv.shtml
3: http://www.rodsbooks.com/gdisk/
4: http://daniel-baumann.ch/software/dosfstools/
5: https://developer.apple.com/library/mac/technotes/tn2166/_index.html