clone sd card?


25 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: 37
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: 609
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: 37
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: 609
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: 115
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: 609
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: 1009
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: 37
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: 63
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: 474
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: 19
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: 24
Joined: Sun Dec 29, 2013 12:24 pm
by donrecardo » Sat Mar 26, 2016 1:26 pm
Please excuse the noob question but
I am using a 32Gb sd card in my Pi 3
I tried cloning my SD card using using win32 disk imager
I saved the image file ok to my windows PC
I then took a second 32gb sd card and formatted it with SD formatter
and tried to write the saved image back with win32 disk imager

It says size is 62333952
sectors available 61415424
why would it do this when they are both 32Gb cards
I have put very little extra on the R Pi so wont have used much space on the disk
is there any way to make it smaller so it fits on the second disk ?

Don
Posts: 21
Joined: Tue Mar 06, 2012 12:21 pm
by GTR2Fan » Sat Mar 26, 2016 2:03 pm
donrecardo wrote:It says size is 62333952
sectors available 61415424
why would it do this when they are both 32Gb cards

Because neither of them are 32GB cards, and the second is slightly smaller than the first. 32GB cards don't exist. Neither do 4GB, 8GB, 64GB, etc. They're all slightly undersized, often by differing amounts. It's quite normal.
I have put very little extra on the R Pi so wont have used much space on the disk

An image is a copy of every single byte of a card, not just the occupied space. That's the way imaging works.

If it's a plain non-NOOBS Raspbian you're attempting to copy, try this...

https://www.raspberrypi.org/forums/view ... 09#p914109
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.
User avatar
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK
by liudr » Sat Mar 26, 2016 7:36 pm
Please note, for those trying to make backup clone or restore copy to a new card, don't rely on win32disk imager. The main issue is the program doesn't know what it is copying. If your identical card (for a clone) has one bad sector, it will be one sector (512 bytes) less than the image you made, not to mention "same size" cards from different brands. Win32disk imager will NOT work. You have to bump up to a larger size card and the problem comes back when you want to make copies again. Both one-sector-less and bumping-to-next-size happened to me and I've been looking for a while for a solution that works for beginners.

For those beginners and intermediate users that want to do it properly (and easily) and want to squeeze into a smaller card (given original card has space to spare), please use Paragon backup and restore 14 free edition. I have a blog post explaining how to back up and restore:

https://liudr.wordpress.com/2016/03/25/ ... pberry-pi/

Enable compression and you get a very compact image that you can restore entirely or pick out any files to restore if you want.
If you are a linux guru, good for you. For the rest of us, with windows machines, Paragon does a great job!
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
Posts: 591
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
by donrecardo » Sat Mar 26, 2016 7:45 pm
Because neither of them are 32GB cards, and the second is slightly smaller than the first. 32GB cards don't exist. Neither do 4GB, 8GB, 64GB, etc. They're all slightly undersized, often by differing amounts. It's quite normal.

If it's a plain non-NOOBS Raspbian you're attempting to copy, try this...

https://www.raspberrypi.org/forums/view ... 09#p914109


I understand now what you mean regarding they are all different sizes

Thank you very much for the link. It worked a treat and I was then able to copy my card

Cheers
Don
Posts: 21
Joined: Tue Mar 06, 2012 12:21 pm
by Raspiv » Tue Apr 12, 2016 6:20 am
Hello Raspberry Pi fans,

I tried to make an image file of my Raspberry SD card (8Gb) using an Win32DiskImager. Did all instructions step-by-step: Read file from SD card (with installed and working version of Raspberry) and save to a local HDD. The image size is correct (a liitle bit less of 8GB). Then Write the .img file to the formatted SD card (use the same one for the experiment). Then put it to the Raspberry Pi, switch power on and load only the startup screen with message telling, that the partition is corrupted. The loading process fails.
What I noticed is when I open the SD card in Disk Management, the partitions are different before and after restoring the image. I tried to repeat these procedure on two different computers, under Windows 7 and Windows 10 (both are 64 bit versions), but the results are the same.
I also noticed that Disk Management shows only first partition on SD card if I use laptop bult-in card reader, butwhen I use an external USB card reader, all partitions are showed. I tried backup and restore image both with built-in and external card reader, but without any success.

Can anyone help me where I'm wrong?
Thank you in advance.
Posts: 1
Joined: Tue Apr 12, 2016 5:35 am
by liudr » Wed Apr 13, 2016 8:21 pm
Maybe your original sd card is corrupted. Try back up again with paragon software.
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
Posts: 591
Joined: Sat Jun 01, 2013 12:11 am
Location: Central MN, USA
by kemnet » Tue May 10, 2016 6:05 am
I don't see a clear cut answer...will this work on a seperate PI?
Posts: 26
Joined: Sat Aug 10, 2013 12:11 am
by calito » Thu Jul 07, 2016 6:24 pm
Posts: 1
Joined: Fri May 01, 2015 6:01 pm