pwalden
Posts: 51
Joined: Wed Jan 09, 2013 3:23 am

backup of SD card to img file not working

Thu Dec 05, 2013 12:16 am

I have only linux systems and I wanted to clone a 16GB SD image from one SD card to another. So I cannot use the w32 disk imager.

First, I used dd to make an img file from the original 16GB SD card:

Code: Select all

dd if=/dev/sdb of=sdcard.img bs=1024
The img file has a size of 16,009,658,368 bytes. I then inserted a new 16GB SD card (out of the wrapper) and tried to write the image to it.

Code: Select all

dd if=sdcard.img of=/dev/sdb bs=1024
The process completed with no warnings or errors. However, when I tried to mount the partition on the new SD card, the second partition (sdb2) had this error:

Code: Select all

# mount /dev/sdb2 sdb2
mount: wrong fs type, bad option, bad superblock on /dev/sdb2,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
from dmesg:

Code: Select all

[20131.645808]  sdb: sdb1 sdb2
[20131.646118] sdb: p2 size 31145984 extends beyond EOD, truncated
Did I miss a step? Should I have reformatted the new SD card first? If so, how do I do that?

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: backup of SD card to img file not working

Thu Dec 05, 2013 12:19 am

You need to fsck /dev/sdb1 and /dev/sdb2 on your Linux system. You may need to checkdisk f: (or whatever /dev/sdb1 shows up as on Windows).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pwalden
Posts: 51
Joined: Wed Jan 09, 2013 3:23 am

Re: backup of SD card to img file not working

Thu Dec 05, 2013 12:25 am

DougieLawson wrote:You need to fsck /dev/sdb1 and /dev/sdb2 on your Linux system.
Do you mean I need to mount the original SD card partitions and fsck them before I make the img file? Or do I try to fsck the copied SD card?

pwalden
Posts: 51
Joined: Wed Jan 09, 2013 3:23 am

Re: backup of SD card to img file not working

Thu Dec 05, 2013 12:28 am

Trying to fsck the copied SD partition yields:

Code: Select all

# fsck /dev/sdb2
fsck from util-linux 2.23.2
e2fsck 1.42.7 (21-Jan-2013)
The filesystem size (according to the superblock) is 3893248 blocks
The physical size of the device is 3846912 blocks
Either the superblock or the partition table is likely to be corrupt!

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: backup of SD card to img file not working

Thu Dec 05, 2013 12:33 am

I meant a fsck of the newly written card. You need to get a new copy of the original. That one is incomplete.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
rpdom
Posts: 17174
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: backup of SD card to img file not working

Thu Dec 05, 2013 6:56 am

I'm surprised that the second dd command didn't give any warnings or errors. It sounds like the second card is slightly lower capacity than the first and the root file system didn't fit.

I use a slightly more complicated method to backup on Linux, but it is a bit faster and works on different sized cards. (Just a simple Raspbian install, not NOOBS)

First I use fdisk -l to get the partition details from the original card

I take a copy of the first partition using dd "dd if=/dev/sdb1 of=/tmp/boot.img"

I take a backup of the second partition using the Linux "dump" program (ok, it's old. Some people may not like it, but it works for me). "dump -0 -f /tmp/root.dump /dev/sdb2". At least it only backs up the data, not the empty space like dd does.

I switch to the new card and partition it so the first partition is exactly the same size as the old one and the second partition fills the rest of the card. I also set the partition types correctly. 1=VFAT, 2=Linux

I also create an empty ext4 filesystem in partition 2.

I then restore the first partition with dd "dd if=/tmp/boot.img of=/dev/sdb1"

I mount the second partition somewhere "mount -t ext4 /dev/sdb2 /media/sdb2", cd into it "cd /media/sdb2", then restore it "restore -r -f /tmp/root.dump". This will give a warning about "lost+found" and create a file called "restoresymtable" which can be deleted.

That's it. Pretty much all of this can be scripted, with a little work for the fdisk options.
(You may need to install the "dump" package for dump and restore to work)

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: backup of SD card to img file not working

Thu Dec 05, 2013 7:00 am

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

pwalden
Posts: 51
Joined: Wed Jan 09, 2013 3:23 am

Re: backup of SD card to img file not working

Fri Dec 06, 2013 1:12 am

Thank you both DougieLawson and rpdom.

Yes the problem was that the new SD card was about 200MB smaller. Lesson 1 is that not all 16GB SD card are the same.

The thread posted by DougieLawson referenced an autosize.sh script that worked perfectly. http://sirlagz.net/2013/03/10/script-au ... downsizer/ It shrunk the img file to 2.5GB, allowing me to flash the newer smaller SD card.

Return to “Beginners”