Raspberry Pi

Summary

Copying RasPi images from one card to another can be an issue. While they are of the 'same size', it turns out that due to manufacturing errors etc. they are different in size. So sometimes you need to copy from a larger SD to a smaller one. Here is how.

This article was inspired by wonkygibbon and slightly updated

It might be of interest to note that this approach will also allow you to downsize an image. Just check the sizes to make sure your latest and greatest installation of system X fits.

Copying Images on Ubuntu

There are multiple ways to do this, it turns out that a Linux distro (Ubuntu or anything else) is the easiest tool for the job. It might be a good idea to use a virtual machine with an Ubuntu box on top.

  • Boot to Ubuntu
  • Click on the dash icon and start typing the word “Terminal” so that it finds the terminal program. Double click and you get a command line.
  • Place the source SD card into the card reader slot and let Ubuntu mount it.
  • Type:
cd Desktop
  • Then type this command to make an image file on the desktop:
sudo dd if=/dev/sdb of=sdimage.img bs=4M

‘sudo’ gives root priveleges. ‘dd’ is a copying program, ‘if’ is the input file which is the sd card reader device, ‘of’ is the output image on the desktop and ‘bs’ is the block size.

this gives the output below:

ubuntu@ubuntu:~/Desktop$ sudo dd if=/dev/sdb of=sdimage.img bs=4M
953+1 records in
953+1 records out
3998220288 bytes (4.0 GB) copied, 211.068 s, 18.9 MB/s

With 8GB of RAM on your system, you are able to use the desktop effectively as a RAM disk. If you have less than this – you could try saving to your windows hard drive which Ubuntu will have mounted.

  • Take out the source SD card and replace it with the target one (which is a bit smaller) and execute this command:
sudo dd if=sdimage.img of=/dev/sdb bs=4M conv=notrunc,noerror

The aditional parameters at the end tell it to write the full size and allow it to continue when it runs out of space.

This gives this output:

ubuntu@ubuntu:~/Desktop$ sudo dd if=sdimage.img of=/dev/sdb bs=4M conv=notrunc,noerror
dd: writing `/dev/sdb': No space left on device
932+0 records in
931+0 records out
3904897024 bytes (3.9 GB) copied, 482.878 s, 8.1 MB/s

The 3.9GB at the end tells you that a little bit of the image was lost. Happily it is of course blank.

All of which results in a working SD card that the Raspberry Pi can boot. Solved