Use dd to clone a larger SD card to a smaller SD card if the actual partitions will fit

ddraspberry pisd card

I have a 16GB SD card that has a few partitions on it (it's actually the card for a Raspberry Pi). I have several other 4GB cards that I want to clone the primary card to. The 3 partitions on the primary card are:

  • Rasp boot partition, FAT, 60MB
  • Linux partition, ext2, 1GB
  • Additional "storage" partition, FAT, 1GB

If I use dd to create an image of the card via:

dd if=/dev/sdb of=~/sd-card.bin

then the resulting .bin is 16GB in size. Is there a way to use dd to copy just what's actually being used, i.e. < 4GB so that I can then dd this onto a new 4GB card? Or is there a better solution that I should be using?

Best Answer

I assume you are using a PC linux or mac computer to perform the copy, not the raspberry pi itself. You will probably need to add a block size.

I have seen one and four megs used for Raspberry pi disks by specifying bs=1M or bs=4M. I think block size is more important when writing the disk as large transfers are quicker than smaller ones. This does not set the block size for the disk, it just effects the size of transfers dd uses. One reason for setting a large block size is the need to erase the flash before writing it. This is done automatically but faster for transfers that are larger than the minimal erase size.

You can limit the total amount of data copied by dd using "count". "count" is in units of blocks. If the end of the last partition on the source disk is before the size of the destination you can do what you want.

Something like dd if=/dev/sdb of=~/sd-card.bin bs=1M count=4000 will create an image that is 4000MBs in size.

See and for more information. Not sure how to find the end of the last partition or the cards total size. However if you have formatted the disks you will probably know how to do this.