clone sd card?


17 posts
by rinky451 » Thu Nov 08, 2012 7:24 pm
Is it possible to copy this sd card like a clone to another sd card for if the first one fails. I finally got things set up the way i want to and would like to have a copy of this program as is on hand.
tks
rinky
Posts: 25
Joined: Sun Nov 04, 2012 5:08 pm
Location: USA
by milhouse » Thu Nov 08, 2012 7:55 pm
Use dd on Unix/Linux, or Win32 Disk Imager on Windows (or USBIT - USB Image Tool). Create a backup of your working card using the aforementioned tools, then restore the image as often as you like (using the same tools).
Posts: 568
Joined: Mon Jan 16, 2012 12:59 pm
by rinky451 » Thu Nov 08, 2012 9:16 pm
tk for the response. I would be doing it on windows with the win32 imager since i am familer with. But don't I have to create a image first out of the card? I tried in windows where i created a folder on the desktop, copied files from the sd card into the file but it did not work out for me.
Posts: 25
Joined: Sun Nov 04, 2012 5:08 pm
Location: USA
by milhouse » Thu Nov 08, 2012 9:21 pm
Just connect your SD card to your Windows PC, fire up Win32 Disk Imager, select your SD card device, specify a file name (eg. "MyImage.img") and click on Read - the file you create will be your "image".

The image will be an exact copy of whatever is on your SD card, so assuming you already have a working Pi setup exactly as you want it, this method will allow you to create a clone of your working system by reading "MyImage.img" and writing it to a new SD card.
Last edited by milhouse on Thu Nov 08, 2012 9:23 pm, edited 1 time in total.
Posts: 568
Joined: Mon Jan 16, 2012 12:59 pm
by flyinghappy » Thu Nov 08, 2012 9:22 pm
If you have a USB sdcard adapter you could do it right on the pi using the dd command I would think, somebody correct me if I'm wrong, but wouldn't something like
Code: Select all
dd bs=4M if=/dev/mmcblk0 of=/dev/sdX
where the sdX would be changed to the correct drive work?

I do know if you do this, the card has to be the same size or bigger for it to work.
Pi with ArchLinux running a minidlna/samba home server
Posts: 112
Joined: Mon Nov 05, 2012 5:31 pm
by milhouse » Thu Nov 08, 2012 9:24 pm
flyinghappy wrote:If you have a USB sdcard adapter you could do it right on the pi using the dd command I would think, somebody correct me if I'm wrong, but wouldn't something like
Code: Select all
dd bs=4M if=/dev/mmcblk0 of=/dev/sdX
where the sdX would be changed to the correct drive work?


It's possible, but the image being created is from a running system which isn't really ideal.
Posts: 568
Joined: Mon Jan 16, 2012 12:59 pm
by SN » Thu Nov 08, 2012 9:35 pm
Stick with win32diskimager and as said just take an image copy off your original sd card onto your hard drive
And then use win32diskimager again to restore your .img file onto a new card - the two cards do need to the same size OR the new one be bigger than the old one

But do beware the .img file will be the same size as your SD card - so if its a 16Gb card, you'll end up with a 16Gb .img file - takes a long time and takes up a lot of space. This is a good reason for NOT using oversized SD cards to be honest.

At the moment I am using a pair of Aldi 8Gb cards for experimenting with and having got a good base setup using the first card in my third Pi I created an 8Gb ,img file. Now the thing is I did not extend the volume beyond the initial 2Gb so I know the last 6Gb of that img file is white space, so when I burnt the image back out onto the second 8Gb card for use in my fourth Pi :roll: I actually killed win32diskimager after just 26/27% of the write phase and the card worked first time into a headless Pi with a nano wireless usb adaptor.

I'd like to see an option to control how much of an image is read/written by win32diskimager
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?
User avatar
Posts: 1008
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
by dextrus » Thu Nov 08, 2012 10:05 pm
I did make a video about this. It assumes you are using Windows to do the "cloning" however.

http://youtu.be/tRRrxt-eJ_M

Action-packed it's not, but I hope it helps. You are very wise to want to clone your card.. I regularly trash the contents on mine.

/Dextrus
Have more FUN with your Pi. Visit www.pi-fun.com
Posts: 119
Joined: Tue Jan 24, 2012 10:10 pm
Location: Eastleigh, Hampshire
by rinky451 » Fri Nov 09, 2012 5:41 pm
Dextrus, I viewed you video on youtube. Great. as soon as I saw the win32 i realized how you was going to extract the image from the sd card so I can make backups. I feel really foolish now. I do have Weezy on a 16 gig card. I thought I could use a bigger card and it would be better for extra storage. But per what I am reading I must be wrong on that idea. Can you confirm that for me?
also do i have to put this image back on a 16gig card or can i use a 8gig. I think i will probably have to use the 16 wont i. Appricate the help man. I been using linux for just a little over a year and it does amaze me on the things i have learned thru forums. I ususally run pc linux lxde on my tower, but for viewing streaming videos off of the net like thru streamtuner the pi does the job. Wher we live we do a lot of tv from the net for we live out in the middle of now where so recetpion is out of the question and I refuse to pay a bill to a satallite carrier for they are not worth the 60 to 80 per month for what you get. Tks and give me a heads up on the info i requested wil you.
rinky
Posts: 25
Joined: Sun Nov 04, 2012 5:08 pm
Location: USA
by dextrus » Mon Nov 12, 2012 12:24 am
You can only take your image and put it on the same sized OR BIGGER card. I haven't come across a solution to the opposite yet (I can think how it would work).

Now, to get the extra space you can do a number of things. If it's Raspbian, you can run sudo raspi-config and there is a menu option that will do just that for you. Otherwise you will need to do this manually or use disk partitioning software. That's what I do.. I use gparted, but do be careful if you go down this route because you can easily kill your PC disk system.

/Dextrus
Have more FUN with your Pi. Visit www.pi-fun.com
Posts: 119
Joined: Tue Jan 24, 2012 10:10 pm
Location: Eastleigh, Hampshire
by Digital Larry » Wed Dec 26, 2012 3:00 pm
milhouse wrote:
flyinghappy wrote:If you have a USB sdcard adapter you could do it right on the pi using the dd command I would think, somebody correct me if I'm wrong, but wouldn't something like
Code: Select all
dd bs=4M if=/dev/mmcblk0 of=/dev/sdX
where the sdX would be changed to the correct drive work?


It's possible, but the image being created is from a running system which isn't really ideal.


I did this yesterday prior to giving my brother a RPi for Christmas. I had a 4GB SD card which was pretty heavily modified from its Raspbian "Pisces" origin. Didn't want to repeat all the steps, if I could even remember them! So I grabbed another 4 GB SD card and got to it.

The second card had slightly fewer total data blocks as shown by the "df" command. But I tried it anyway. It did go ahead and copy a bunch of blocks and finally stopped when it ran out of destination space. I popped that card into a fresh Pi ;) and it booted. About 2/3 way through the process it flashed a message about a file system error and rebooted. After that it came right up and worked fine.

This doesn't prove there isn't SOME problem somewhere. In any case I gave my bro the original OS card and kept the clone for myself.
Posts: 62
Joined: Tue Jul 24, 2012 9:10 pm
Location: Silicon Valley, CA
by jfornango » Mon Dec 31, 2012 9:14 pm
imaging/cloning SD cards is a good skill to lear in this world.

As soon as I get my RPi i nhand, I'm going to work on a multi-boot system. I figure a 16 GB card with 4 GB allocated to each of the four distros the Foundation has links to. Once they're all set up, image, image, image.

Hmmm..... Think there might be a market for Selectable OS cards? $$ :lol:
I'm only wearing black until they find something darker.
Posts: 113
Joined: Fri Sep 14, 2012 7:46 pm
Location: St. Louis, MO USA
by Marck » Mon Feb 18, 2013 3:05 pm
Hello Andy/Dextrus

I saw your video and it seems very easy. When I tried it with to exactly the same sd cards, I got a remark on the screen that the amount of 'heads' were not the same.....

Do you know what to do in this case ?


with kind regards,

Marck
Posts: 1
Joined: Mon Feb 18, 2013 2:56 pm
by 1HzCoder » Mon Feb 18, 2013 7:48 pm
This thread gives a nice script for cloning your SD right on your pi
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=29&t=21342
Einstein once said you don't really understand anything until you can explain it to your Grandmother
Posts: 31
Joined: Thu Jul 12, 2012 1:15 am
Location: Lower Alabama
by SiriusHardware » Tue Feb 19, 2013 9:16 pm
1HzCoder wrote:This thread gives a nice script for cloning your SD right on your pi
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=29&t=21342


I'll second this recommendation, which 1HzCoder originally pointed me to when I asked the same question.

Ingredients:
-Pi with working (possibly customised) Raspian running on it
-Card reader plugged into Pi, containing the destination card to which the current Raspbian will be cloned.
-The script referenced in the thread 1HzCoder mentioned.

No external computer or software required.

The great thing about this is that the destination card can be SMALLER than the original card, if the original card does not contain more actual data than can be fitted on the smaller card.

Example: You downloaded a 2GB Raspbian Image, wrote it to a 32GB card and expanded the OS to fill the whole of that card using Raspi-Config. You haven't used it for very long, and the programmes / data that you have accumulated on it so far do not amount to more than about 6GB. The script will not only clone the data on the large card but resize it, if possible, to fit onto whatever card you have chosen to use as the destination. In this case, it would be sensible /economical to choose an 8GB card as the destination for the backup.

Oh, and the nice thing is that by cloning your working Raspbian card the script naturally also includes a copy of itself on the clone, so that the clone can clone itself just as easily...

Only one thing - it needs a utility called 'rsync' installed first in order to work. On my Raspbian, it wasn't installed by default.
Posts: 439
Joined: Thu Aug 02, 2012 9:09 pm
Location: UK
by Eradicatore » Fri Jan 03, 2014 9:55 pm
Thank you for pointing to this other thread!! I've been looking for a clone solution and for some reason never found that. This is EXACTLY what I wanted. No more dd or windows imager stuff. :D :D :D
Posts: 18
Joined: Sun Jul 29, 2012 1:21 am
by RSvedman » Sat Jan 04, 2014 10:39 pm
That script did not produce a bootable copy for me, the newly made card can't find & mount its root partition, because the script failed to set up the partitions on the new card exactly like the old one, it made two primary partitions instead of one primary and one extended, resulting in the root filesystem to be in partition number 2 on the copy instead of number 5 on the original.
Posts: 20
Joined: Sun Dec 29, 2013 12:24 pm