Copyright 2009-2012 by djg. All Rights Reserved.

Wonky Gibbon Ramblings

Raspbery Pi: Copying SD card image to a smaller SD

Posted on January 19, 2014 by danny

Aaargh! So one of my Pi’s running AirPlay died. Or rather the SD card did. I bought a replacement and attempted to write the SD image to it in the usual way using Win32DiskImager. However it refused to write to it, saying that the image was bigger than the SD card.

Turns out that due to manufacturing errors, SD cards vary a little bit in capacity with dead bits hidden away. The new card had less capacity front than the old one.

So – I needed to find some way to burn the image to this card that was just a smidgen too small. This post was useful

In the post some people talk about having to shrink the linux filesystem a little before cloning the card however, it turned out I’d never resized my partion up from 2GB to 4GB so I didn’t have this problem. The easiest solution in the end, proved to be to fix the problem using an Ubuntu install rather than Windows. The nice thing about Ubuntu is that like many linux distro’s it can be run direct from the install media without actually having to install it, either DVD or memory stick.

The steps to resolve the problem were as follows:
1) In Windows, download Ubuntu from and burn to DVD (just to big to fit on a CD).

2) Then restart the laptop and let it boot the Ubuntu OS from the DVD.

3) 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.

4) Place the source SD card into the card reader slot and let Ubuntu mount it.

5) Type:

cd Desktop

6) 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 this output:

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 the laptop I was 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.

7) 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. Sorted!

Leave a Reply

↑ Top