exwaver
Posts: 23
Joined: Thu Jul 05, 2012 10:34 am

Full proof backup of SD card

Tue Jul 17, 2012 12:06 pm

I have searched the web and this forum to find a way of completly backing up my SD card (simialr to an ISO image) so that it can be wiped clean and restored back to how it was before being wiped clean, but have never found a definitve answer. I have seen people using the dd commmand but I have never read of anyone using dd to backup their SD card and being able to fully restore it back to as was.

BTW, I am a newbie and need to have any Linux solution detailed in abc terms.
Thanks

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Full proof backup of SD card

Tue Jul 17, 2012 12:34 pm

In a thread entitled "How to backup operating system", I wrote:
by Joe Schmoe » 30 Jun 2012 10:46
rasbeer wrote:
Is there a way of backing up an OS that only uses the RasPi?

Plug in a USB card reader/writer, put a blank card into the external reader, then do:

dd bs=1M if=/dev/mmcblkWhatever of=/dev/sdWhatever
This is for making a copy of the SD card onto another SD card. Note that mmcblkWhatever is the "whole disk" name for your built-in SD card reader/writer (e.g., mmcblk0) and sdWhatever is the "whole disk" name for your external SD card reader/writer (e.g., sda). For what it is worth, it seems that the device names for card readers end in digits while those for "regular" disks end in letters.

Anyway, the underlying point is that if you replace /dev/sdWhatever with a filename, then the backup will be made in the file instead of onto another SD card.

For example:

dd bs=1M if=/dev/mmcblkWhatever of=/mnt/path/to/some/external/storage/PiBackup.img
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
RaTTuS
Posts: 10323
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Full proof backup of SD card

Tue Jul 17, 2012 12:35 pm

I always use
conv=noerror,sync on the command line also
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

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Full proof backup of SD card

Tue Jul 17, 2012 12:50 pm

dd is a very low-level command, so it reads/writes the SD card at a very low-level ("beneath" the level of filesystems, partitions, etc.), so any backup created using dd (as long as you backup the whole card e.g. /dev/sdb and not a single partition e.g. /dev/sdb1) will always be able to recreate a fully working SD card. Unless you have an example of where it hasn't worked?!
To swap between reading an image from an SD card, and writing an image to an SD card, simply swap the values of the if= (Input File) and of= (Output File) arguments.

I believe Win32DiskImager also works in a similar way to dd (it can both read and write).
http://elinux.org/RPi_Easy_SD_Card_Setup

exwaver
Posts: 23
Joined: Thu Jul 05, 2012 10:34 am

Re: Full proof backup of SD card

Wed Jul 18, 2012 7:03 pm

Joe Schmoe wrote:In a thread entitled "How to backup operating system", I wrote:
by Joe Schmoe » 30 Jun 2012 10:46
rasbeer wrote:
Is there a way of backing up an OS that only uses the RasPi?

Plug in a USB card reader/writer, put a blank card into the external reader, then do:

dd bs=1M if=/dev/mmcblkWhatever of=/dev/sdWhatever
This is for making a copy of the SD card onto another SD card. Note that mmcblkWhatever is the "whole disk" name for your built-in SD card reader/writer (e.g., mmcblk0) and sdWhatever is the "whole disk" name for your external SD card reader/writer (e.g., sda). For what it is worth, it seems that the device names for card readers end in digits while those for "regular" disks end in letters.

Anyway, the underlying point is that if you replace /dev/sdWhatever with a filename, then the backup will be made in the file instead of onto another SD card.

For example:

dd bs=1M if=/dev/mmcblkWhatever of=/mnt/path/to/some/external/storage/PiBackup.img
Thanks for your help Joe. I have a small problem that I need to resolve before I attempt to make a backup and erase my SD card:

My SD card is a 16gb and reading from file manager, I have 3 partitions:
mmcblkOp1
mmcblkOp2
mmcblkOp5

partition 1 is the /boot folder with the startup files and partiton 2 is for the files (opt, root, etc, bin and so on).
partition 5 is for file storage.

I want to back up my LINUX partitions as a single image (similar to the wheezy image) to a USB drive which appears as sda:sda1

Can you detail exactly how to backup the LINUX part of the SD card, or do I have to amke an image of the whole 16Gb card.

I guess it would be:
dd bs=1M if=/dev/mmcblkOp of=/dev/sda ??
and the target USB drive will have to have at least 16Gb to accept the whole image.

Many thanks from a complete Linux newbie

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Full proof backup of SD card

Wed Jul 18, 2012 7:14 pm

As with all things, what exactly you should do depends a lot on exactly what you want to do.

If you just want to make a backup of your Linux "system" partition (which is /dev/mmcblk0p2, if I am reading you correctly), you could do the dd command with if=/dev/mmcblk0p2 and of=/mnt/path/to/afile.img

The important thing to remember is this: Unless you are writing a whole disk to a whole disk (i.e., from /dev/mmcblk0 to /dev/sda, where the thing plugged in as /dev/sda is a USB SD card reader/writer), the target should *not* be a "whole disk" identifier. Doing so would be a good way to trash a live disk. Instead, you should use a full pathname/filename that specifies a file on a mounted media.

So, I'm going to assume that what you want is something like what I listed in the 2nd paragraph of this note - i.e., that you want to backup a partition of the SD card to a file on a USB thumb drive (or USB hard drive - same thing, really). Is that right?
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

edyb
Posts: 31
Joined: Thu May 24, 2012 3:11 am

Re: Full proof backup of SD card

Thu Jul 19, 2012 2:28 am

Maybe I don't understand the question correctly, but couldn't we just use the same Windows utility (Win32DiskImager.exe) to backup an SD card image that we have already played around with, the same way we use this utility to write the SD card image in the first place?

I usually download the OS image from the download area here on raspberrypi.org and use Win32DiskImager to write it to my SD card on my laptop. Once I've played around for a while, downloaded packages, installed stuff and have documents saved, my SD card would be full of all my customizations/documents. So if I want to make a "backup" there is an option in Win32DiskImager called "Read" and you can just read the same SD card and have it save a copy to your computer.

Meanwhile, you use Win32DiskImager to "Write" the new OS image so you can play with that. If you want to go back, you write your saved one. This method avoids you having to buy more SD cards, you just read and write that way to your laptop.

Is this what the OP was asking about originally?

Dilligaf
Posts: 283
Joined: Wed May 23, 2012 6:48 pm

Re: Full proof backup of SD card

Thu Jul 19, 2012 3:19 am

USB Image Tool also will backup cards or partitions. One thing to remember is that not all sd cards are created equally. For example if I backup a Sandisk 8gb sd card it won't necessarily fit on another brand 8gb sd or maybe even not on another Sandisk (bad blocks or whatever causing size differences). If you want a truly universal image I would recommend shrinking one of the partitions slightly for improved compatibility.

Mike

stevech
Posts: 144
Joined: Sun Jul 15, 2012 11:53 pm

Re: Full proof backup of SD card

Thu Jul 19, 2012 5:28 am

It wasn't obvious via the UI, but Win32DiskImager.exe will read the SD card image and write to a windows file.
Big result as empty sectors are copied too.

User avatar
RaTTuS
Posts: 10323
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Full proof backup of SD card

Thu Jul 19, 2012 8:14 am

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

User avatar
Jim Manley
Posts: 1600
Joined: Thu Feb 23, 2012 8:41 pm
Location: SillyCon Valley, California, and Powell, Wyoming, USA, plus The Universe
Contact: Website

Re: Full proof backup of SD card

Fri Jul 20, 2012 2:17 am

Joe Schmoe wrote:For what it is worth, it seems that the device names for card readers end in digits while those for "regular" disks end in letters.
It isn't clear to me that newbies reading this thread may pick up on this tidbit, as it was indirectly referenced in some of the comments, but, names ending in letters are device names, and names ending in digits are partitions within the named devices.

Each device type can have widely-varying attributes depending on its type, but, one of the more useful devices that actually does literally nothing is /dev/null - anything sent to /dev/null results in nothing happening. It's useful for testing things without actually changing anything. There are many inside Unix/Linux jokes that involve /dev/null ... Three devices walk into a bar ... :lol:
The best things in life aren't things ... but, a Pi comes pretty darned close! :D
"Education is not the filling of a pail, but the lighting of a fire." -- W.B. Yeats
In theory, theory & practice are the same - in practice, they aren't!!!

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: Full proof backup of SD card

Fri Jul 20, 2012 2:48 am

Jim Manley wrote:
Joe Schmoe wrote:For what it is worth, it seems that the device names for card readers end in digits while those for "regular" disks end in letters.
It isn't clear to me that newbies reading this thread may pick up on this tidbit, as it was indirectly referenced in some of the comments, but, names ending in letters are device names, and names ending in digits are partitions within the named devices.
But the point was that some whole disk device names (sdX, xvdX) end in a letter, whereas others (mmcblkN, cciss/cNdN) end in a digit. Where the whole disk name ends in a digit, an extra "p" is inserted/removed before any partition number.

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Full proof backup of SD card

Fri Jul 20, 2012 10:42 am

By way of a quick example - if accessing your SD card via the RaspberryPi's SD slot, the whole device will be /dev/mmcblk0 and it will contain two (or more) partitions /dev/mmcblk0p1 /dev/mmcblk0p2 etc.
If accessing the same SD card via a USB card reader (on a Linux PC), the whole device might be /dev/sdb and then the partitions would be /dev/sdb1 /dev/sdb2 etc. :geek:

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Full proof backup of SD card

Fri Jul 20, 2012 11:48 am

jojopi wrote:But the point was that some whole disk device names (sdX, xvdX) end in a letter, whereas others (mmcblkN, cciss/cNdN) end in a digit. Where the whole disk name ends in a digit, an extra "p" is inserted/removed before any partition number.
Quite so.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

TxBobS
Posts: 18
Joined: Thu Mar 14, 2013 11:46 pm

Re: Full proof backup of SD card

Thu Mar 14, 2013 11:59 pm

I know I am necro-posting but I've tried this and it isn't working for me.

I made a backup of an 8GB SD card with the device name of /dev/sdf and 2 partitions. First part is 59MB FAT and the rest is EXT4. To do this I used this command:

Code: Select all

sudo dd if=/dev/sdf of=gate.img
That seemed to work and I ended up with a 8.1GB file.

I then tried to restore it to another 8GB SD card with just a single EXT4 partition using this command:

Code: Select all

sudo dd if=/dev/sdf of=gate.img
It complains that there isn't enough room when it finishes. Also when looking at the target card, there is still only one partition and it isn't bootable.

Code: Select all

dd: writing to `/dev/sdf': No space left on device
15661057+0 records in
15661056+0 records out
8018460672 bytes (8.0 GB) copied, 4122.95 s, 1.9 MB/s
Any thoughts on how I can make a backup of this card?

Thanks.
Bob

unclejed613
Posts: 55
Joined: Sun Jan 15, 2012 10:49 pm

Re: Full proof backup of SD card

Fri Mar 15, 2013 4:06 am

not sure. it would be better if you copy-pasted the whole "dialogue" from the terminal window, so we could see the whole process. then we might have an idea what's causing it.

it could be a typo, or it could be a difference in disk size. i know i had an SD card just begin to get corrupted, and when i reformatted the card, it had lost 100Meg in bad sectors. if these are marked by the cards memory management, they can't be written to, and so the card is now slightly smaller. if i go to write a copy of the last backup i did, i would get an "out of disk space" error

TxBobS
Posts: 18
Joined: Thu Mar 14, 2013 11:46 pm

Re: Full proof backup of SD card

Fri Mar 15, 2013 4:45 am

Both are fairly new cards (less than 6 months old) and have only had fledgling rPi OSes on them. I just got one I want to not lose the work on and would like to be able to image a whole card.

Here's the complete dialog from my terminal. Thanks! I broke out of the first first attempt to do the restore because I thought it was stuck.

Code: Select all

[email protected]:~/Pi-Images/Gate_2013-03-13$ sudo dd if=/dev/sdf of=gate.img
15759360+0 records in
15759360+0 records out
8068792320 bytes (8.1 GB) copied, 352.517 s, 22.9 MB/s
[email protected]:~/Pi-Images/Gate_2013-03-13$ sudo dd of=/dev/sdf if=gate.img

^[email protected]:~/Pi-Images/Gate_2013-03-13$ sudo dd of=/dev/sdf if=gate.img
[sudo] password for bob: 
dd: writing to `/dev/sdf': No space left on device
15661057+0 records in
15661056+0 records out
8018460672 bytes (8.0 GB) copied, 4122.95 s, 1.9 MB/s

Return to “General discussion”