ericdaigh
Posts: 9
Joined: Sat Jan 12, 2013 2:07 pm

SD Card Backup

Tue Feb 05, 2013 12:51 pm

Hi All,
Apologies if this could be in a more appropriate area. I'm on a mac, trying to make a clone of my RaspPi card. It's been flashed using http://elinux.org/RPi_Easy_SD_Card_Setup

But in OSX, the card is regarded as only being 58Mb in size (It's actually a 16GB card with approximately 6GB of video inside)

Can anyone posit why it won't recognize (and thus allow me to backup) the full size of the disk?

Many thanks,
e.

pjc123
Posts: 911
Joined: Thu Mar 29, 2012 3:37 pm

Re: SD Card Backup

Tue Feb 05, 2013 12:57 pm

I suspect on a Mac, just like Windows, it can not see the Linux partition which contains most of the files on the pi. I don't know anything about Macs, but you need to find software that does an image backup (sector by sector), not a file backup.
My Raspberry Pi Project Page:
http://www.flaminghellmet.com/launch/

User avatar
socialdefect
Posts: 108
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: SD Card Backup

Tue Feb 05, 2013 1:36 pm

If you open Disk Utility you can see the device but the EXT partition cannot be mounted on OSX by default. It is possible to create a clone image of the disk but that will also copy the entire partition table including free space. These images can be compressed though but remember to have about 3x more free space as the full disk size.

A nice tool to help you create .dmg clones is Disk Drill and FreeDMG and DMGconverter are quite handy to compress images.

Also there is the old fashion way using dd on the command-line which is as simple as reversing the dd method for installing to SD:
Replace rdisk2 in the example for your SDcard. To find it's device name use Disk Utility, select the main disk (not a partition like: /dev/disk1s1 but /dev/disk1. Using /dev/rdisk.. copying might go a little faster. Make sure you unmount all partitions

Code: Select all

sudo dd if=/dev/rdisk2 of=/User/yourname/Desktop/RPI-backup.img
This will take a while but it's a great way of doing back-ups.

Another way is to add support for Linux filesystems to OSX. There is Mac Fuse but I guess it will only work for Intel Mac's. EXTFSmanager only supports EXT2 but it does work on PowerPC too. When your system supports EXT filesystems you can also create an image by mounting the disk and drag it on FreeDMG, this won't copy any empty space etc..
== If it's not broke... I'm not done fixing it! ==

ericdaigh
Posts: 9
Joined: Sat Jan 12, 2013 2:07 pm

Re: SD Card Backup

Tue Feb 05, 2013 5:02 pm

What if I had two SD cards (one to be copied, one to copy to) attached via card readers to the pi (running a third card)? Would/could that work? Can anyone give a detailed instruction, if so, including the mounting, unmounting, etc?
thank in advance,
e.

User avatar
socialdefect
Posts: 108
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: SD Card Backup

Tue Feb 05, 2013 5:34 pm

From disk to disk you would do like this:

Using your mouse:
1) Open Disk Utility.app using Finder.
2) Connect SD cards one by one so you'll see which one it is as it get's mounted by the system.
3) Select the device's partitions on the left and press Apple key + i to view it's info and remember the device name. e.g. /dev/disk2, not /dev/disk2s1
4) Right click the disk's partition and select Unmount, Not eject!
5) Do the same for the other SD card.

Using the terminal: (locate it using Finder)
6) Enter the following command And replace $DISK1 and 2 for the devices you detected in Disk Utility. (if stands for: Input File and of for Output File)

Code: Select all

sudo dd if=/dev/$DISK1 of=/dev/$DISK2 bs=1m
This will take quite long (20 min / 2 hours) and if nothing goes wrong it won't show any indication that it's working exept for a blinking cursor. Changing /dev/disk? to /dev/rdisk? can speed-up the process.
If you get an error concerning the 1m option than change it to 1M as used in GNU versions of dd.
7) If nothing went wrong you'll end-up with 2 identical SD cards. You can test that to be sure by running a checksum program like this: (You might have to re-connect the disks first)

Code: Select all

md5sum /dev/$disk1
md5sum /dev/$disk2
The above should output 2 identical strings.

Using Disk Drill the above is this simple: (but takes a little longer and needs HD space for the image)
1) Open Disk Drill.
2) go to recovery
3) click create image
4) Select source disk and storage for image
5) Restore the image to the second disk.
== If it's not broke... I'm not done fixing it! ==

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

Re: SD Card Backup

Tue Feb 05, 2013 6:28 pm

If you have a SD card plugged into your Pi via a USB card reader, you can use my rpi-clone script to copy the booted Pi SD card to the target SD card. If nothing else is plugged in, the target SD card should show up as /dev/sda and you would be ready to run rpi-clone. So do this:

1) You need to have rsync installed, if it's not already installed:

Code: Select all

sudo apt-get update
sudo apt-get install rsync
2) Download the zip file for rpi-clone from https://github.com/billw2/rpi-clone and
run the rpi-clone script to clone to the sda SD card:

Code: Select all

unzip rpi-clone-master.zip
cd rpi-clone-master
sudo ./rpi-clone -f sda
Just answer a question or two with "yes" or "y" when rpi-clone runs and in 8 to 12 minutes it should get your running system cloned to a target SD card. If it works OK for you, copy the rpi-clone script to a bin directory (probably /usr/local/bin or /usr/local/sbin).

ericdaigh
Posts: 9
Joined: Sat Jan 12, 2013 2:07 pm

Re: SD Card Backup

Tue Feb 05, 2013 6:30 pm

Thanks, I'll try this out. And you would expect this to overcome the initial problem (top of the thread) wherein OSX doesn't seem to recognize the true Linux size of the disk?

User avatar
socialdefect
Posts: 108
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: SD Card Backup

Tue Feb 05, 2013 11:03 pm

It will not be able to use the second partition but It is possible to clone the entire disk, including the partitions and all empty space to either an image file another disk. To use a different approach you must install the Linux filesystem driver in OSX, SSHFS or MacFuse can install it for you but I can't tell you if it will work for it doesn't on my G5.

The only way to do backups on OSX without the filesystem driver is by using imaging tools like Disk Drill or dd that perform a byte copy on an unmounted filesystem. This way there is no need to mount the partition in OSX.
All other options include Linux live cd's, imaging from the system itself while in use or excessive use of the command-line.

If I were you I'd just plug those SD cards, open Disk Utility and clone your disk to the other one. This will erase all data on the device you are copying to...
== If it's not broke... I'm not done fixing it! ==

TravelinMax
Posts: 25
Joined: Mon Nov 26, 2012 3:46 am
Location: Michigan, USA

Re: SD Card Backup

Thu Feb 07, 2013 2:44 am

Can I use rsync (or any other utility) to backup my Pi's SD card to an attached external hard drive?

It would have to save it as a .img file, I don't want it to clone to my hard drive and erase hundreds of gigs of files (and then have to figure out how to format the drive so it's usable again)

I'm running my Pi headless and I SSH and SFTP into it to use it and get my files, so sometimes it would be nice to be able to run a backup remotely, seeing as I am most likely to ruin it while I am not physically near the Pi.

ericdaigh
Posts: 9
Joined: Sat Jan 12, 2013 2:07 pm

Re: SD Card Backup

Thu Feb 07, 2013 3:14 pm

This worked like a charm. Thanks so much.

User avatar
socialdefect
Posts: 108
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: SD Card Backup

Mon Feb 11, 2013 7:02 pm

TravelinMax wrote:Can I use rsync (or any other utility) to backup my Pi's SD card to an attached external hard drive?

It would have to save it as a .img file, I don't want it to clone to my hard drive and erase hundreds of gigs of files (and then have to figure out how to format the drive so it's usable again)

I'm running my Pi headless and I SSH and SFTP into it to use it and get my files, so sometimes it would be nice to be able to run a backup remotely, seeing as I am most likely to ruin it while I am not physically near the Pi.
Using Rsync or SCP you cannot create a .img file (Unless your mac supports Linux filesystems but then you need to create an empty img, partition & format it, mount the partitions and copy all files over)
It is possible though to copy the files to a directory on your disk. The fastest and most reliable way to do that is to connect your backup disk to the Pi and use SSH to copy the files over using rsync. Do NOT copy the files inside /tmp /opt /proc /dev /sys for these are created by the OS while booting. You do need these (empty) directories though.

For those that don't like using the command-line or any of the tools mentioned above I've created a simple tool that helps you create an image on Mac OSX. This tool also helps you detect your SDcard so you won't have to guess it's disk number. The images it outputs can also compressed with gzip to save storage space.
Download from Sourceforge.net
== If it's not broke... I'm not done fixing it! ==

Colton3310
Posts: 1
Joined: Tue Dec 03, 2013 6:54 am

Re: SD Card Backup

Tue Dec 03, 2013 7:02 am

Hi, you can try Kvisoft Data Recovery Mac to recover files from SD card.

Return to “Beginners”

Who is online

Users browsing this forum: rpiMike and 42 guests