the itjerk

my adventures with technology

Monthly Archives: January 2013

raspberry pi and sd cards

As much as I'm enjoying my Raspberry Pi, I've come across one big issue: the SD card has failed twice now. Even though I'm using a "verified" card from this list, it keeps getting corrupt to the point where my RPi won't boot. Why is this? Just a bad card? Voltage on the board checks out okay, I use "sudo halt" to shut down cleanly, I don't manhandle the cards… so maybe it's from overclocking? Fortunately cards are cheap, and I'm not adding a whole lot to the standard Wheezy distro.

Here's how to backup and clone a SD card with Ubuntu. First, mount the SD card, then find out its device name in /dev/ by using ls. (You can also use "sudo fdisk -l").

ls -al /dev/sd*
... 
brw-rw---- 1 root disk 8, 32 Jan 15 18:50 /dev/sdc
brw-rw---- 1 root disk 8, 33 Jan 15 18:50 /dev/sdc1
brw-rw---- 1 root disk 8, 34 Jan 15 18:50 /dev/sdc2

That known (and correct), unmount the disk and use the dd "convert and copy" command to clone an image of the card to a bin file. NB: This isn't the fastest operation (we're talking SD cards) and dd doesn't display a progress bar. It will however give you a summary of the transfer when completed.

sudo umount /dev/sdc*
sudo dd if=/dev/sdc of=~/sd-card.bin bs=1M

Finally, put in a new SD card, verify the device name (again), then issue the same dd command, but in reverse. Note your SD cards must be the or larger than your image. Be patient!

sudo dd if=~/sd-card.bin of=/dev/sdc

Another hint I found is to go into /etc/fstab and add "sync" to allow immediate writes.

/dev/mmcblk0p2  /               ext4    defaults,[B]sync[/B],noatime  0       1

Finally, I picked up a "class 10" SDHC card to give a try (much faster writes).

On the web:
Copying an image to the SD card in Linux (command line)

Other option:
dcfldd
dd if=/dev/sdx | gzip > /path/to/image.gz
gzip -dc /path/to/image.gz | dd of=/dev/sdx