Writing a raw image file to a USB disk

The content of this section borrows heavily from very thorough documentation provided by the ArchLinux Wiki.

When you are ready to test your image on a real machine, you should write it to a flash drive and boot from that drive. There are machines in the Friend Center lab, rooms 011 and 012, which are reserved for this purpose and can only boot from USB. In order to write the image to your flash drive, follow instructions appropriate for your OS.

Make sure you have identified the correct device before writing the image, otherwise, damage may be done to other devices connected to the machine!

You must prepare your image for the flash drive by marking the image so that the BIOS recognizes it as bootable. In createimage.c, write a signature consisting of two bytes, 0x550xaa, to the end of the first sector: address 0x1fe of image.

Using dd in Linux

Tip: Find out the name of your USB drive with lsblk. Make sure that it is not mounted.

Run the following command, replacing /dev/sdx with your drive, e.g. /dev/sdb. (do not append a partition number, so do not use something like /dev/sdb1):

# dd if=image of=/dev/sdx bs=512 && sync

Using dd in MacOS

To use dd on your USB device on a Mac you have to do some minor maneuvers. First, insert your usb device and OS X will automount it. Then, in Terminal.app run:

$ diskutil list

Figure out then name of your USB device with mount or sudo dmesg | tail (e.g. /dev/disk2) and unmount the partitions on the device (i.e., /dev/disk2s1) while keeping the device itself (i.e., /dev/disk2):

$ diskutil unmountDisk /dev/disk2

Now we can continue similar to the Linux instructions above, but use /dev/rdisk instead of /dev/disk. rdisk means "raw disk".

# dd if=image of=/dev/rdisk2 bs=512 20480+0 records in 20480+0 records out 167772160 bytes transferred in 220.016918 secs (762542 bytes/sec)

Eject your drive before physically removing it:

$ diskutil eject /dev/disk2

Using USBwriter in Windows

This method does not require any workaround and is as straightforward as dd under Linux. Just download the USBwriter utility to write to your image directly to your USB disk.