ben5243
Posts: 4
Joined: Wed Apr 17, 2013 11:48 pm

Restoring SD card from backup made using dd

Sat Apr 27, 2013 6:52 pm

So I following instructions to backup the SD card on another linux computer using dd. The output file was a .img and I used dd to put that image back onto a second card.

When I try to boot that SD card on a raspberry pi I get:

Code: Select all

EXT4-fs (mmcblk0p2):  bad geometry:  block count 2003712 exceeds size of device (1925120 blocks)
List of all partitions:
b300        7761920 mmcblk0 driver: mmcblk
  b301          57344 mmcblk0p1 00000000-0000-0000-0000-000000000000
  b302        7700480 mmcblk0p2 00000000-0000-0000-0000-000000000000
No filesystem could mount root, tried: ext4
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,2)
So I assume that this is because I have used a different SD card and they are both labeled 8GB but are not identical in size...

I have looked and looked but cannot find a way to RESTORE a .img file to an SD card and have it work. All of the instructions I have found tell you how to use dd to create a .img file but then they end. Any help would be appreciated!!

remsnet
Posts: 151
Joined: Wed Dec 19, 2012 7:32 pm
Location: Planet Gaia
Contact: Website Yahoo Messenger

Re: Restoring SD card from backup made using dd

Sat Apr 27, 2013 8:31 pm

try use gparted from an running debian 7 live cd or knoppix on that and resize it so that may fit.

if that failed, your dd image seems incompletly written .

Other way been to create manulay the partions with fdisk and have 2 dd files , one for the p1 ( bootfs, vfat) one for the p2 (rootfs, ext4 )

the 3rd way may just create the partions , format them , flag the boot as bootable
and blast the filesystems with tarballs ;-)

hope this helps.

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

Re: Restoring SD card from backup made using dd

Sat Apr 27, 2013 8:42 pm

There are no simple as in one-command-fits-all ways of restoring an image to a smaller SD card.

The way I'd do it (with access to a linux PC), is:

Use dd to copy the first 100MB or so, just to get a partition table and the /boot partition onto the card.

Use fdisk to delete the (incorrectly sized) second partition and create a new one that fits the card.

Use mkfs.ext4 to format that partition.

Mount the part of the image file that contains the Linux partition on a temporary mount point.

Mount the second partition of the SD card on another temporary mount point.

Use tar or cp or something to copy the contents over.

Unmount both partitions.

Something like: (this is not a script, just hints for you)

Code: Select all

# Assuming /tmp/myimage.img is the image file
# and /dev/sdb is the SD card
dd if=/tmp/myimage.img of=/dev/sdb bs=1M count=100
# remove the card reader and plug it back in to make sure the system reads the new partition table!
fdisk -u /dev/sdb
# p to print partition table. Note start of partition 2.
# d delete partition 2
# n new partition 2, use start noted above, defaults for the rest
# w to write and exit.
mkfs.ext4 /dev/sdb2
# mount the part of the image file that we want. Value for OFFSET is start noted above * 512 (bytes)
mkdir /media/image
mount -t ext4 -o loop,offset=OFFSET /tmp/myimage.img /media/image
mkdir /media/sdb2
mount -t ext4 /dev/sdb2 /media/sdb2
cd /media/image
tar cf - * | tar -xvCF /media/sdb2 -
umount /media/sdb2
umount /media/image
Disclaimer: I typed all that off the top of my head. Please check each command as you use it. I believe I got it right, and it should work.

I'm working on another method of backing up one SD card to another on the Pi, which will work for differing sized cards, but needs a bit of minor fiddling to work.

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Restoring SD card from backup made using dd

Tue Apr 30, 2013 4:41 am

Again with a Linux PC. Run parted/gparted to reduce the size of the main partition , re image the SD card, use truncate to shorten the .img file slightly (reduce it by less than you took off using gparted, so the entire partition is within the file) and re-burn the SD card from that image. The truncate bit is optional, you'll still get the error using dd but since the new partition is entirely on the SD card it will work when you put it in the Pi. You could use the raspi-config menu to stretch it to fully fit the new SD card afterwards.

As you may have gathered by now, there's more than one way to skin a cat, but a seperate linux box is a must. No doubt it could be done in windoze, but its like trying to work with one hand tied behind your back.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

SirLagz
Posts: 1705
Joined: Mon Feb 20, 2012 8:53 am
Location: Perth, Australia
Contact: Website

Re: Restoring SD card from backup made using dd

Tue Apr 30, 2013 5:11 am

Or linux livecd.
My Blog - http://www.sirlagz.net
Visit my blog for Tips, Tricks, Guides and More !
WiFi Issues ? Have a look at this post ! http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=44044

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

Re: Restoring SD card from backup made using dd

Tue Apr 30, 2013 5:11 am

remsnet wrote:...flag the boot as bootable
Why?

billw
Posts: 415
Joined: Tue Sep 18, 2012 8:23 pm

Re: Restoring SD card from backup made using dd

Tue Apr 30, 2013 11:02 pm

rpdom wrote:There are no simple as in one-command-fits-all ways of restoring an image to a smaller SD card.

The way I'd do it (with access to a linux PC), is:

Use dd to copy the first 100MB or so, just to get a partition table and the /boot partition onto the card.

Use fdisk to delete the (incorrectly sized) second partition and create a new one that fits the card.

Use mkfs.ext4 to format that partition.

Mount the part of the image file that contains the Linux partition on a temporary mount point.

Mount the second partition of the SD card on another temporary mount point.

Use tar or cp or something to copy the contents over.

Unmount both partitions.
See http://www.raspberrypi.org/phpBB3/viewt ... 29&t=21342

Ignore the initial rpi-clone download link given for pastebin at the beginning of the thread and read on to get the link for the more up to date rpi-clone script download link on github.

dxradio33
Posts: 3
Joined: Fri May 31, 2013 3:08 pm

Re: Restoring SD card from backup made using dd

Fri May 31, 2013 3:40 pm

After a lot of research I wanted to pass along some information on saving your SD Pi image and restoring it. I have tried Roadkill's Disk Image tool and it horribly fails as it does not read a true block for block image. Win32DiscImager worked at one time but no longer has the ability to write a saved image to an identical SD card. It reports an error "Not enough disc space on target" or something similar and exits the process. I have also tried DD and it is very cumbersome and dangerous to use if you are tire. I have located a free tool that so far has been absolutely dependable . http://hddguru.com/software/HDD-Raw-Copy-Tool/ I hope this saves some time for you folks.

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Restoring SD card from backup made using dd

Sun Jun 09, 2013 3:56 pm

Hi dxradio33,

I am trying to make backup of my pi as well. The program that you are recommending, HDD GURU, can it image original image to a larger SD card? I have a 4GB sd card on my pi (initially thought that's enough for a try). Now I am thinking about expanding to 8-16GB card. But I will make a 4GB backup card anyway. I have a few identical cards at hand.

Thanks.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

sdjf
Posts: 1395
Joined: Fri Mar 16, 2012 5:20 am
Location: California
Contact: Website

Re: Restoring SD card from backup made using dd

Sun Jun 09, 2013 6:52 pm

dd'ing a smaller image to a larger card is not that hard to do directly, then all you have to do is expand the file system with the regular Raspbian tools or with fdisk or parted with other systems. But I am talking Linux, do not know what a DOS box would do.
FORUM TIP: To view someone's posting history, sign in, click on their user name, then on "Search User's Posts." || Running ArchLinuxArm on Model 2B and 512MB Model B

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Restoring SD card from backup made using dd

Sun Jun 09, 2013 7:40 pm

sdjf wrote:dd'ing a smaller image to a larger card is not that hard to do directly, then all you have to do is expand the file system with the regular Raspbian tools or with fdisk or parted with other systems. But I am talking Linux, do not know what a DOS box would do.
I installed Debian on an older laptop with no sd card slot. Not willing to shell out $7 for an adapter made me want to try windows option first. I'll try that and see how the copy works :)
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Restoring SD card from backup made using dd

Sun Jun 09, 2013 11:03 pm

I was able to use the win32 disk imager in winodws 8 to backup the original rasbian SD card that is 4GB. I then made a copy of it on a different brand 4GB SD card. I booted the pi and was able to log on and do stuff like running Arduino IDE. Tied to run eclipse but it just couldn't start on pi.

[EDIT] Wow that took long. I left my main Debian box to do some dinner prep and half hour later I came back and eclipse has started on the pi. Setting up a c++ project took some waiting. It eventually started and compiling a hello world program took a few minutes. I am definitely going to develop projects on my main Debian box. Meanwhile probably getting a class 10 SD card to speed up the pi.
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

dxradio33
Posts: 3
Joined: Fri May 31, 2013 3:08 pm

Re: Restoring SD card from backup made using dd

Mon Jun 10, 2013 12:22 am

liudr wrote:Hi dxradio33,

I am trying to make backup of my pi as well. The program that you are recommending, HDD GURU, can it image original image to a larger SD card? I have a 4GB sd card on my pi (initially thought that's enough for a try). Now I am thinking about expanding to 8-16GB card. But I will make a 4GB backup card anyway. I have a few identical cards at hand.

Thanks.
Yes it can. I just upgraded my 8gb to 16gb and the image was copied to the larger card with no issues. To expand the file system after you boot the new card you will have to run "raspi-config" to utilize the new space available to you. Good luck !

User avatar
liudr
Posts: 687
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
Contact: Website

Re: Restoring SD card from backup made using dd

Mon Jun 10, 2013 1:27 am

Thanks! I will try that after I get a 16GB SD card. I was just not committed to pi when I prepared the SD card :)
Arduino data loggers, user interface, printed circuit board designer since 2009, RPI 3B 2B 2B Zero Jessie, assembly/C/C++/java/python programmer since the 80's

Return to “Beginners”