On my raspberry pi I want to back up my current sd card using dd. I have a 64 gigabyte card for raspbian wheezy but I made sure not to Expand the Filesystem (under raspi-config) so the used data in the card remains at 4 gigabytes, plus the boot partition. When I try to use the command:
sudo dd bs=1m if=/dev/sdb of=~/Downloads/pineapple.img dd makes pineapple.img 64 gigabytes rather than 4 gigs because dd is backing up the unallocated data. I was wondering if there is a way to copy multiple partitions into one .img file. For example: sudo dd bs=1m if=/dev/sdb1 /dev/sdb2 of=~/Downloads/pineapple.img gparted

To sum it up, I want to copy over the two used partitions (/dev/sdv1 and /dev/sdb2) to one .img file.

2 Answers 2


There is no magic in the image file. It's simply a bit-for-bit copy of a chunk of the sd card. What you want to do is figure out exactly where the second partition ends, and copy from the device file representing the whole card (in this case: /dev/sdb.

Now, look at how your partitions are laid out: in your case, it's partition 1 followed by partition 2. Right click on sdb2, and select information. Note the last sector. It will be some number around 8 million (a "sector" is 512 bytes, you have four gigs, that makes eight million sectors). Let's say the number is 7666777. That's the last useful sector you care about. Since the first sector is sector 0, there will be a total of 7666778 sectors that you want to copy. So do something like:

dd if=/dev/sdb of=foo.img bs=512 count=7666778

and wait for a while; sdcards are not very fast.

Usually the number of sectors will be a multiple of some power of 2, and you can increase the copying speed a little bit by increasing the block size and decreasing the count, keeping the product constant.

To feel a bit more comfortable with how partitions are laid out, use the non-graphical version, parted, and specify units as B (bytes).


  • Awesome thank you so much for such a quick answer!
    – splch
    May 14, 2016 at 6:16

if you have multiple partitions on your sd card, use win32diskimager. it treats all your partitions as separate disks so you can make separate images.


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.