Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Mar 19 '13 at 10:14

This question came from our site for professional and enthusiast programmers.

    
I ended up creating the exact contents on a new 4GB card and cloning that with dd to a quantity of other cards. Still, would like to know if it's possible to solve the initial problem. –  Charlie S Mar 18 '13 at 20:07

2 Answers 2

up vote 7 down vote accepted

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 tthe 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 http://en.wikipedia.org/wiki/Dd_(Unix) and http://elinux.org/RPi_Easy_SD_Card_Setup 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.

share|improve this answer
    
Thanks for the info. I was not aware of the count option. I'll give that a try. –  Charlie S Mar 19 '13 at 1:32
    
@charlie it'd be fascinating if you can try it with and without the count option and report back. be sure though to check how the size of the disk is being reported, and if you can add files to it and the size changes. 'cos when dd fails related to different sized disks, you get those kind of problems. Here is an example where I messed up with dd with two different sized drives. superuser.com/questions/538583/difficulty-resizing-a-partition In the end I didn't use dd to do the clone. –  barlop Mar 19 '13 at 12:23

Have a look at this article, it helped me with a similar problem:

http://www.howtoforge.com/linux_resizing_ext3_partitions

share|improve this answer
2  
Welcome to superuser. You've posted a link only answer, which while possibly useful now, may be of less use should the linked site go down. You may want to reference the site, and post a more complete, awesome answer for the benefit of everyone (and more upvotes!). –  Journeyman Geek Apr 3 '13 at 7:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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