Build an ISO to a Thumb Drive on the Mac

Reposted from Andrew King at work:

 

Insert your thumbdrive. You should see it pop up on your desktop, all nice and mounted, ready for you to use. Only it isn’t. If you can see it on your desktop, you can’t use it the way we need to.
$ diskutil list
 
You should see something like this:
/dev/disk0
   #:      TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme       *251.0 GB   disk0
   1:      EFI                          209.7 MB   disk0s1
   2:      Apple_CoreStorage            249.8 GB   disk0s2
   3:      Apple_Boot Recovery HD       814.4 MB   disk0s3
/dev/disk1
   #:      TYPE NAME                    SIZE       IDENTIFIER
   0:      Apple_HFS Macintosh HD      *249.5 GB   disk1
/dev/disk2
   #:      TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme       *1.0 TB     disk2
   1:      EFI                          209.7 MB   disk2s1
   2:      Apple_HFS My Passport        999.8 GB   disk2s2
/dev/disk3
   #:      TYPE NAME                    SIZE       IDENTIFIER
   0:      FDisk_partition_scheme      *1.0 GB     disk3
   1:      DOS_FAT_32 UNTITLED          1.0 GB     disk3s1
In the instance above, I’ve noted my thumbdrive – /dev/disk3. It happened to be “UNTITLED”, but it could be whatever name you may have given it. Anyhow, we essentially need to unmount everything on that disk, but not remove it completely from the system.
$ diskutil unmountDisk /dev/disk3
Unmount of all volumes on disk3 was successful
That solves that. Now, where is that ISO image you have? You need to know where it is so you can copy it to that thumbdrive. By the way – do this on a thumbdrive that is either backed up, or in other ways not useful (like old, and small, whatever). You’ll note the one I’m using is 1G. LOL! I got it with a Cisco router that I bought. It came with “management” software on it that sucks. But I digress. That thumbdrive, when it’s all over, will have NOTHING on it but the ISO you’re “burning” to it. On to the destructive part…
$ sudo dd if=~/Desktop/crunchbang-11-20130506-i486.iso of=/dev/rdisk3 bs=128k
6168+0 records in
6168+0 records out
808452096 bytes transferred in 186.954879 secs (4324317 bytes/sec)
I should note – you won’t see any activity (more on that in a second). You hit [Return] and the computer goes to work, not telling if it’s working or not. dd is one of those classic commands – it ain’t fancy, or pretty, or all high-falutin’. It does one thing, and it does exactly what you told it to do, or it errors. I should also note – if you screw up an point that to something important, like, in my disk list above, disk0? Well, you’ll have the joy of reinstalling the OS on your Mac, most likely.
Breakdown:
sudo - most of you know what this is. I hope. It allows you to do things as the “superuser” on your Mac (i.e., superuser do).
dd - command to convert and copy a file (I don’t know why it’s named that).
if=<filename> - input file
of=<filename> - output file
bs=n - block size… You can use 1m, 1k, 128k – you get the idea. I like 128k, there’s not much speed gained by anything bigger.
Some of you are looking at that output file location and thinking “Where in the heck did he get rdisk3 from??” Well… It’s the same location as disk3, only it’s a “raw” device connection. We’re stepping outside the rules a little bit – taking a little known shortcut that doesn’t have any stoplights, if you will. Or speed limits. You’ll essentially move the same data in about 1/6th of the time if you /dev/rdisk[n]
The last thing that you should do is eject it – but how do you do that, since you can’t drag it to the trash? diskutil still has you covered.
$ diskutil eject disk3
Disk disk3 ejected
If you really need to “see” something, you’ll need to have (or install) Pipe Viewer. Unless you already have some system like MacPorts orHomeBrew, have it working, and know how to use it, just suck it up and deal with not seeing something. Really. I mean it. Anyhow, maybe you’re a dork like me, and you have Pipe Viewer. Instead of the dd command we used initially, we’re going to modify it.
$ pv -petr ~/Desktop/crunchbang-11-20130506-i486.iso | sudo dd of=/dev/rdisk3 bs=128k
0:00:33 [4.11MiB/s] [===>                          ] 17% ETA 0:02:40
There you go. A nice little visual guide for elapsed time, how fast, and an estimate for how long it’s going to take. If you want to know more about Pipe Viewer, there’s a great article on it here.