I have expand the images to use 8gb, but my problem now is i want to create a images so orther people can use my software, how can i make it smaller?

Right now i use a 8gb sd card and when i use a dd backup, its fill 8gb i want to make a dd only on the used space and now for the free space.

can somebardy help me whit this problem?

i try to create my own project but its not so nice to upload 8gb every time i update my project images, :)


3 Answers 3


If you've expanded the root partition to 8 gigs, then plug the SD card into a PC, and use gparted to resize the partition back down again.

Once it's been downsized, make a dd image of the file with this command
dd if=/dev/sdcard of=imgfile bs=1M count=SizeOfYourImage
for example
dd if=/dev/sdc of=Pi.img bs=1M count=2000

That will make a 2gig image of the SD Card

  • Orh, nice! :) so i just need to look how much of my space there are not are empty? :) Jul 15, 2013 at 8:00
  • gparted will not allow you to shrink the partition smaller than the allocated space anyway, so verifying the used/free space should not be necessary.
    – Tevo D
    Jul 15, 2013 at 15:58

If I were making images often, I would not want to be shrinking and regrowing my SD card partition repeatedly.

I'd want to leave the partition big, because this is better for the card and more efficient for the system, but create minimal size images. To do this, figure out what size you'll need (see man df) and, on a (linux) computer separate from the pi, create an empty file of that size:

dd if=/dev/zero of=filesystem.img bs=512 count=4194304

That's a 2GB image (512 bytes * 4194304 = 2147483648 bytes = 1024 * 1024 * 1024 * 2). Here's an interesting thing: you can make a filesystem in the (empty) file.

mkfs.ext4 filesystem.img

Don't worry about the "this is not a block device" warning. Now create a mount point and mount it:

mkdir fsmnt
mount filesystem.img fsmnt

Now there's an empty ext4 filesystem mounted on fsmnt (there will be one "lost+found" directory, which is basic to ext filesystems; notice there is one on the pi).

You can now copy everything from the SD card partition in. This means there is zero wear on and zero risk for the card. Then just umount the image:

umount fsmnt

Guess what? Everything you copied into the mount point is now in filesystem.img, which can be used exactly the same way you used the original raspbian (or whatever) image (and this is almost certainly how they make those).


While trying to re-distribute a customized Raspbian OS, I had the same question with respect to making the image as small as possible. To make this process easy I wrote mkimg.sh and outline what it does at: https://raspberrypi.stackexchange.com/a/37899/32585

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.