Tag Archives: dd

How to make a bootable flash drive in OS X

This tutorial has to do with making a bootable flash drive, this would be useful when you do not want to burn a bootable image to a CD or DVD instead loading it to a flash drive. I am sure most of you know by now you just cannot copy the files over and reboot to the device. This will explain how to make such a device bootable using OS X, but can be easily translated to Linux or other versions of Unix. Now there¬†exist¬†other tutorials on the internet, and they are probably better – but this was a request from a friend so here it goes…

First of all you need to get a bootable image that you want to install to the flash drive, in this tutorial the type of file will have to be of type .img. However most files are not that you will more commonly find a .iso file on the net, in that case we can use a program called hdiutil to convert it to the file type we want, in general hdiutil is a program to manipulate disk images, it is a very hand program and I would suggest reading it’s man page.

To convert from .iso to .img you would use the following command:

hdiutil convert -format UDRW -o destination.img source.iso

Sometimes OS X appends a .dmg file extension, simple rename it. Next you have to know what device file your flash drive mounts as. This is easy enough to figure out, we simply run another program. This time we will use diskutil, another very hand program. Among other things diskutil can list all of the device files that are currently mounted, make sure your flash drive is not connected then issue the following command:

diskutil list

Please take a note of which disks are there, on my machine the output is listed below:

theObfuscated$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            121.0 GB   disk0s2

Please make note of your output, then insert the flash drive you would like to use, and again run diskutil. My output again is listed below:

theObfuscated$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            121.0 GB   disk0s2
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *4.0 GB     disk1
   1:                 DOS_FAT_32 MY STUFF                4.0 GB     disk1s1

Notice the new section listed after the old one, here it begins on line 7. On that line it indicates what device file your flash drive is mounted to, in this case the information we want is:

/dev/disk1

Next we need to unmount the disk, again we will use the diskutil command to accomplish this:

diskutil unmountDisk /dev/disk1

The only difference you might have for this command is to substitue /dev/disk1 with your device file. Now we will getto the meat of it, actually writing the image to the device. Again we will use another program, this time it is the old dd command. This command is to convert and copy files, it has been around as long as I can remember and if you want more info I suggest to check out it’s man page.

This command needs to be run as root so the command to copy the image to the device is:

sudo dd if=source.img of=/dev/rdisk1 bs=1m

Now there are a few things to state about this command.

  1. You should supply the complete path to your source.img file.
  2. I used /dev/rdisk1 instead of /dev/disk1 this is just to improve speed of the operation.
  3. This might take a while depending on the size of the image.
  4. It will completely erase all data currently on the flash drive.

Once this operation has finished we need to saftly eject the flash drive, and you might have guested it by now we will use our friend diskutil:

diskutil eject /dev/disk1

Remove your flash drive and you are finished. You should now be able to boot from it! Hope this little how to has helped!

 

Performance Optimization WordPress Plugins by W3 EDGE