BoyLens
Posts: 7
Joined: Thu May 26, 2016 6:41 am

cloning sdcard using dd

Thu May 26, 2016 6:53 am

Hi

I've tried multiple times to clone my Pi's SD card.

I did dd if=/dev/rdisk2 of=pi.img bs=1m using OSX. I get an image. But after writing it to another 16gb card, it gives a kernel panic: VFS: Unable to mount root fs on unknown-block(179,2)

I read about slightly smaller SD cards giving this kind of issues. I also trying writing the image using Ubuntu, but that failed too.

Now I thought I'm going to make the img file smaller, so I mounted it (is that the correct term?) as a loop device:

sudo losetup -f
sudo losetup /dev/loop0 pi.img
sudo partprobe /dev/loop0
sudo gparted /dev/loop0

see the attached screenshot: it only shows the boot partition, the rest is unallocated space! I would at least expect that dd would correctly build the .img file.

Anyone an idea what is going wrong here? What am I doing wrong? Is there a different way to clone the sd card?
Attachments
Screenshot from 2016-05-26 08_48_59.png
Screenshot from 2016-05-26 08_48_59.png (46.41 KiB) Viewed 1881 times

epoch1970
Posts: 5132
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: cloning sdcard using dd

Sun May 29, 2016 8:36 pm

The foundation has recently issued a GUI tool to do this AFAIK. Did you try it?

To respond to your question, I think gparted is wrong, it has a bug.
I had to do the same as you some time ago, but the sad thing is I don't remember exactly the toolchain I used... It probably went with the command-line for the whole thing: kpartx -a to create the loop0 device and partitions, resize2fs to shrink the partition, and fdisk or parted to destroy/recreate the partition to the new size. And although it makes no difference once you compress the disk image, I think I also made the image file size shrink using qemu-image (I was in a creative mood, truncate is the tool for this. It's dangerous and useless anyway, just gzip the image.)

So I am not sure at all I've used the gparted gui, or even parted.
(Trying to write this post, I've seen a "guide" on the net that proposes to 1) resize the partition, and 2) resize the FS. Positively DO NOT do that. Resize the FS first, and create a partition to size.)
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

User avatar
flatmax
Posts: 343
Joined: Thu May 26, 2016 10:36 pm

Re: cloning sdcard using dd

Mon May 30, 2016 5:16 am

A straight clone using dd should work.

Lets work through this a little ...

Assume the new disk is the same size or bigger then the original disk. You plug the sdcard into a computer and you find the root partition. So for example on my computer I will plug it in and use dmesg to see which device it hangs off :
$ dmesg
[.... SNIP ...]
[269932.192121] sdf: sdf1 sdf2
[.... SNIP ...]

OK - so on my computer sdf is the root partition of the disk. All other partitions hang off that one.

I do the same when I plug in my new sdcard (make sure you get this right or you will wipe your original card !), and find out it is /dev/sdg.

so now I do : dd if=/dev/sdf of=/dev/sdg
wait a while. when it is finished, to be sure I can do 'sync' to ensure all data is done.

This new disk should work.
Finally you should be able to run gparted on the new disk and see exactly the same partition table. In my case :
$ sudo fdisk /dev/sdf
p [enter]
Device Boot Start End Sectors Size Id Type
/dev/sdf1 8192 131071 122880 60M c W95 FAT32 (LBA)
/dev/sdf2 131072 15523839 15392768 7.3G 83 Linux


If your new disk is smaller then the original, use gparted to resize the original to the same size or smaller then the new disk.

Hope that helps.
Matt
Discuss hearing, acoustics, audio injector products, - https://lists.audioinjector.net/mailman/listinfo/people
Sound card for the Raspberry Pi with inbuilt microphone : www.audioinjector.net
Audio Inector Octo multitrack GPIO sound card

BoyLens
Posts: 7
Joined: Thu May 26, 2016 6:41 am

Re: cloning sdcard using dd

Wed Jun 01, 2016 11:25 am

Thanks guys for your replies!

I checked the image file with kpartx, but still only one partition. I think the image really failed. I'm going to use my Ubuntu laptop now to make a copy and a 32gb SD card instead of a 16gb. Let's hope that helps. The sd card is used in a working environment, so I cannot just take it home and start testing. Have to do it there.

I don't know about any GUI tool and can't find anything like it, as @epoch1970 mentioned.

Going to do the DD with to sd card readers/writers.

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: cloning sdcard using dd

Wed Jun 01, 2016 11:44 am

make sure you have the correct raw device on the mac for reading from
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

Return to “Troubleshooting”