I am trying to clone an SD card which may contain a number of partitions, some of which Ubuntu cannot recognize. Generally, I want to clone the whole volume, not only some partition. So, I mount the SD card and see something like this in the Log viewer:
kernel: [ 262.025221] sdc: sdc1 sdc2
alex@u120432:~$ ls /dev/sdc*
/dev/sdc /dev/sdc1 /dev/sdc2
Since I want to copy the whole disk, I execute:
dd if=/dev/sdc of=sdimage.img bs=4M
File sdimage.img, 7.9 GB (7,944,011,776 bytes) is created (SD card is 8 GB). Now I mount another SD card and execute:
dd if=sdimage.img of=/dev/sdc bs=4M
The problem is that the second dd command hangs on some stage, and never succeeds. After this, I cannot reboot or shut down computer, and I need just to switch power off.
Is this the correct approach? Maybe there is another way to clone an SD card?
OS: Ubuntu 12.04 (Precise Pangolin), 32 bit.
Insert the original SD card and check the name of the device (usually
mmcblkX
orsdcX
):You might see:
In my case the SD card is
/dev/mmcblk0
(the*p1
and*p2
are the partitions).Now you have to unmount the device:
Now to create an image of the device:
This will take a while.
Once it's finished, insert the empty SD card. If the device is different (USB or other type of SD card reader) verify its name and be sure to unmount it:
Write the image to the device:
The write operation is much slower than before.
You should not be using dd on mounted devices. unmount all the partitions first, then your command should work.
I am using dd tool to clone usb sticks with multiple partitions, here is my command:
notrunc - do not truncate the output file
noerror - continue after read errors
dd is fine, but I prefer
cat /dev/sdc/ > ~/backup.iso
If you want to put it on an SD card again, just runcat ~/backup.iso > /dev/sdc
Here are the steps which worked for me on Ubuntu to restore the image file (
~/raspberrypi2.img
in my case) back to a new SD card (inspired heavily by Alon's reply above):Open terminal and execute:
Relevant output (which showed there were no partitions due to the quick format of the whole card):
This step takes a few good minutes (even on USB3). Make sure to not interrupt it by any operation which will invoke mounting (opening the Files or Disks apps).
Thanks for everyone's answers.