How to clone a bootable SD card to a little smaller card?

0

I have an 8G bootable SD card used for Raspberry Pi. Currently I bought an exactly same card, in order to clone the card. I have tried the following steps:

  1. Create an image from the old card:

    sudo dd if=/dev/rdisk3 of=SD.img bs=1m

It succeeded and the output shows:

7681+0 records in
7681+0 records out
8054112256 bytes transferred in 386.217068 secs (20853849 bytes/sec)```
  1. Write the image into the new card:

    sudo dd if=SD.img of=/dev/rdisk3 bs=1m

Here It failed and the output shows:

dd: /dev/rdisk3: Input/output error
7581+0 records in
7580+0 records out
7948206080 bytes transferred in 568.141243 secs (13989842 bytes/sec)```

I think the problem may be the difference between the number of blocks. Does it imply that these two cards don't have exactly the same size? (The new one looks smaller.) I would have to clone the card many times, so I wonder how can I make the image smaller (There's available space in it) so that I can write them to other cards, even with a little smaller size?

Skyler

Posted 2014-12-30T00:27:30.023

Reputation: 185

One seems to be 100mb smaller. Use gparted to make the larger one 110mb smaller. Then gparted can copy the contents of one to the other. – cybernard – 2014-12-30T02:06:35.103

Can you post the output of fdisk -l /dev/rdisk3 of the original card ? If the SD Card has ~10 MB of free space at the end of the card - i.e. the / partition ends before the end of the SD Card, then it shouldn't matter if the SD card is 10 meg smaller as nothing would get written at the end. – Lawrence – 2014-12-30T02:43:18.560

That "m" needs to be upper case I believe, i.e. "...bs=1M" – None – 2015-05-12T04:05:55.773

Answers

0

Does it have to be a dd clone? That won't be easy (maybe not possible as-is) with a smaller target drive.

How about formattng the new card & just copying the files onto it? Might result in less writes (and be faster) if the original isn't full. dd will copy unused space happily.

parted should be capable of running in a script, and can set bootable partitions & format, etc. Could see man parted or take a look at what commands gparted runs to do what you want... then automate a partition, format, copy script?

Or, if you used gparted or similar to shrink your current original card's partitions to a smaller size, then a dd image might fit on slightly smaller cards? May have to tell dd to stop reading after the last used partition, or it might keep reading to the "end." And it could leave some unused space on the new card. - I haven't had good luck with dd'ing images (especially live iso's) onto flash devices though.

Xen2050

Posted 2014-12-30T00:27:30.023

Reputation: 12 097

This might be a good idea - the raspi dosen't need anything other than a standard FAT32 FS IIRC – Journeyman Geek – 2014-12-30T00:37:09.730

It doesn't have to be a dd clone. But it's a bootable card with hidden partitions. How can I just copy the files and keep it bootable? – Skyler – 2014-12-30T00:37:16.983