Shrink 2GB IMG to fit 2GB SD Card.

Leave a comment

July 1, 2015 by aubreykloppers

Here’s the thing:

You bought a Raspberry Pi, a 2GB SD card and downloaded a 2GB IMG to create your awesome project, just to find the card is too small to write the IMG file to!  The reason for this is that you bought a 2GB SD card, but technically it is only about 1.8G in size!  (1MB=1024768b, work it out from there!)

Software/Hardware used for this example:

  • Raspberry Pi
  • 2GB SD Card
  • RuneAudio (2GB image)
  • Win32DiskImager
  • I used a Generic Turnkey Linux OS to shrink the IMG.

Steps (as root):

  • Enable loopback:
    modprobe loop
  • Create a 1.8G image:
    dd bs=1M count=1700 if=/dev/zero of=NEW.img
  • Mount image as /dev/loop0:
    losetup -f --show NEW.img
  • Unzip 2GB image:
    gunzip RuneAudio_rpi_0.3-beta_20141029_2GB.img.gz
  • Mount image as /dev/loop1:
    losetup -f --show RuneAudio_rpi_0.3-beta_20141029_2GB.img
  • Write 2GB image onto 1.8GB image:
    dd if=/dev/loop1 of=/dev/loop0
  • Check the different sizes:
    fdisk -l /dev/loop1
    fdisk -l /dev/loop0
  • Unmount the images and zip your new image:
    losetup -d /dev/loop0 /dev/loop1
    mv NEW.img RuneAudio_rpi_0.3-beta_20141029_1.8GB.img
    gzip RuneAudio_rpi_0.3-beta_20141029_1.8GB.img

You now have a 1.8G image fitting on a 2GB SD Card.  Neat, hey?

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

counter for wordpress
%d bloggers like this: