Progress while copying an img file to/from an SD card with OSX/Linux

I’m setting up some SD cards for my Raspberry Pi computers. Since it takes forever to backup and/or restore even a 4GB card, I wanted to see the progress of the copy. The dd command is not very informative in this regard, so I looked around for a solution. These instructions are for a raw .img file and not for fancier formats such as .dmg or .iso.

To copy to/from an SD card from OSX/Linux, make sure the SD card is not mounted. There is some infomation at elinux.org. The following commands assume you know the correct device files to unmount and copy to/from. The references to /dev/diskN will need to be updated to point to appropriate files on your computer.

Normal Unix method (usually works on Mac OSX):

sudo umount /dev/diskN

The Mac OSX way:

diskutil unmount /dev/diskN

In order to see the progress while copying to/from the SD card, you can use pv to send the source file to dd. pv will then show the progress as dd writes to the target location. I used homebrew to install pv on my mac.

To copy an image to the SD card:
WARNING: Using dd to copy to a disk is dangerous! Be extremely careful that the device you are writing to is in fact your SD card and not, for example, your boot drive (or any other drive you don’t want to completely erase and replace with the contents of your image file.)

pv -tpreb /path/to/image.img | sudo dd of=/dev/diskN bs=1m

To copy an SD card to an image:

sudo pv -tpreb /dev/diskN | sudo dd of=/path/to/image.img bs=1m
Advertisements

2 thoughts on “Progress while copying an img file to/from an SD card with OSX/Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s