How to clone a Raspberry Pi's MicroSD card?

Hi all,
I have a problem that I can't solve. I have FreeBSD installed and running on my Raspberry Pi 2, but I want to backup my MicroSD.

How can I do it?
I did dd if=/dev/da0 of=/home/joan/backup.img but the new MicroSD can't boot the Raspberry Pi.

By the way, when I insert the MicroSD on my PC, I see four devices (which means, these are partitions of the MicroSD, isn't it?):

Code:
[root@benicass ~]# ls /dev/da*
/dev/da0        /dev/da0s1      /dev/da0s2      /dev/da0s2a

Can somebody help me, please?
 
If you dd(1) the whole disk (/dev/da0) all partitions will be included too. So it should simply work provided the new SD card is of the same size or bigger.

How are you restoring the image?
 
dd if=/dev/da0 of=/home/joan/backup.img
This command copy the first MicroSD to a image file. How do you copy the image file back to the new card?
Should look like dd if=/home/joan/backup.img of=/dev/da0 bs=1M
(the bs=1M is not really required, but speed up the process)
If you plugged in both cards at the same time you can also make a direct copy:
dd if=/dev/da0 of=/dev/da1 bs=1M
Attention: be sure which one is the card to read (if=...) and which one is the card to write (of=...)

Yes, /dev/da0s* are MBR-partitions.
 
hi all, thanks very much for your information.
I was cloning my second MicroSD well (dd if=/home/joan/COPIAUSB.img of=/dev/da0) but witouth "bs=1M" but I'll try again.

I didn't know that /dev/da0 contains all partitions.
Thanks.
 
hi all, thanks very much for your information.
I was cloning my second MicroSD well (dd if=/home/joan/COPIAUSB.img of=/dev/da0) but witouth "bs=1M" but I'll try again.

I didn't know that /dev/da0 contains all partitions.
Thanks.

If you make a card-to-card copy, make sure the source card is unmounted, or mounted read-only, first... Cloning something that's being written to isn't a super good idea...

I don't think the blocksize really matters, but it's definitely faster... it just tells dd to make send out chunks instead of writing bit by bit... I usually specify 16M, but I never did any tests to find out if 16M was faster than 1M or even 4K... Also if you're writing to a magnetic disk, don't specify a blocksize... You can use large sizes with flash and optical media only, magnetic media has specific sector sizes, 4K or 512B, and that should be your bs in those cases...

Also /dev/da0 is the device itself... on the device you can have partitions, /dev/da0p1, /dev/da0p2, etc. for GPT and slices for MBR /dev/da0s1, /dev/da0s2, etc.
 
I don't think the blocksize really matters, but it's definitely faster... Also if you're writing to a magnetic disk, don't specify a blocksize... You can use large sizes with flash and optical media only, magnetic media has specific sector sizes, 4K or 512B, and that should be your bs in those cases...

Flash memory internally has much larger blocks; a few years ago 64K was common. For that reason, when bulk writing flash (USB stick, SD cards, ...), one should use seriously large block sizes, megabytes or so. Then the little flash translation layer (the software inside the USB stick or SD card that maps 512- or 4K sectors to the large internal blocks) doesn't have to work so hard, and in particular it doesn't have to do inefficient read-modify-write or log append cleaning operations.

Also /dev/da0 is the device itself... on the device you can have partitions, /dev/da0p1, /dev/da0p2, etc. for GPT and slices for MBR /dev/da0s1, /dev/da0s2, etc.
Actually, if you want the clone of the card to have exactly the same partitions, the easiest thing to do is to copy from source to target like this: /dev/da0 to /dev/da1 (whatever the real device numbers are). That will also copy the GPT tables or MBR header, and then the target disk gets a valid partition table.

Personally, I always name my partitions in GPT with human-readable names, so I would then go in and rename the partitions on the target disk, because having two disks that have two partitions with the same name is too confusing. But then, I don't suffer from being OCD, I enjoy it.
 
Back
Top