The Raspberry Pi uses (micro)SD cards for its operating system and basic storage. Since I have more projects in mind than physical Raspberries I need to swap SD cards to accomplish this. And for backup it's nice to be able to clone the SD card to an image file for future use.
The official method into creating an SD card from an image file (e.g. to install the basic OS) is the following (on Apple OSX):
1. Locate the SD card (in Terminal):
$ diskutil list
In this case, the SD card is /dev/disk5 (this might change upon a reboot, so always check before wrtiting an image to disk!!!)
2. unmount the disk (but do not eject it!!!)
$ diskutil unmountDisk /dev/disk5
3. format the disk
$ sudo newfs_msdos -F 16 /dev/disk5
4. install image on SD card
This is where the magic happens. By default, the following line writes an image to the SD card, but this is rather slow.
$ sudo dd if=~/Desktop/raspberrypi.img of=/dev/disk5
By changing the command to the following, the writing speeds increases considerable.
$ sudo dd if=~/Desktop/raspberrypi.img of=/dev/rdisk5 bs=1m
By using the rdisk option and the bs=1m (blocksize) argument the writing of a 16GB image takes ~10 minutes instead of more than an hour.
5. Write SD card to image file
This works the same when you want to backup an SD card to an image file. Just use the same command to locate the SD card, and write the SD card to an image file with the following command:
$ sudo dd if=/dev/rdisk5 of=~/Desktop/raspberrypi.img bs=1m
To see the difference with rdisk and bs=1m, and the 'classic' way:
$ sudo dd if=/dev/rdisk5 of=~/Desktop/raspberrypi.img bs=1m 139460608 bytes transferred in 6.434188 secs (21674936 bytes/sec)
The classic way:
$ sudo dd if=/dev/disk5 of=~/Desktop/raspberrypi.img 21090304 bytes transferred in 6.920170 secs (3047657 bytes/sec)
This shows that the rdisk / bs=1m is about 7 times faster.
NOTE: the reading/writing performance can be viewed by pressing control-T in the terminal app where the dd command is running.