Jump to content
Sign in to follow this  
Sergei

Clone/backup hard drive with 2 commands in OS X

Recommended Posts

Hey Mac Geeks!

 

How about cloning/ backing up your hard drive with just two commands in Mac OS X? Yes, I know, you can use CCCloner or SuperDuper, but would it be cool just to use Mac OS X and not to pay for extra piece of software?

 

For me it all started back in 2006 when I got my first intel based 20 inch iMac at home and first generation MacBook Pro at work. As frequently happens with ver.1 products and early adopters, I ran into some bad hardware quality issues which required sending my iMac and MacBook Pro multiple times back to Apple for either exchange or repair.

 

I never felt comfortable trusting my personal data to anyone. As Adam suggested in the last episode of Maccast, I wanted to do full backup, wipe the drive clean, do fresh install of Mac OS X and only then send it to Apple for repair.

 

I figured there had to be some sort of cloning software for Mac just like there was Norton Ghost for PC. Quick Google search revealed two options that everybody always talks about: CCCloner and SuperDuper. It appeared a lot of people prefer SuperDuper for better interface. I was also aware that Mac OS X is based on Unix and as many Unix sys admins would point out, there is a way to clone disks using Unix dd command. So before I pulled out my credit card to get a copy of SuperDuper I decided to try to clone my drive the Unix way.

 

Out of curiosity I did another Google search just to check if anybody already did it successfully, but surprisingly didn't get any hits on using dd with OS X.

 

However, I discovered that Mac OS X had another tool called asr which stands for Apple Software Restore. The man page pointed out that "...asr is the backend for the Mac OS X Software Restore application that shipped on Macintosh computers as well as the Scan and Restore functionality in Disk Utility".

 

One other interesting Google search result was a hint from macosxhints.com about how to boot OS X from an iPod.

 

So, after reading the iPod hint and the man page for asr I came up with this simple procedure. Chances are I am not the first, but so far I haven't ran across any other posts suggesting cloning hard disk this way. For me it works great every time as a full bootable backup solution. So, if you are not afraid of a little bit of command line kung fu, read on.

 

Before you start you will need the following:

 

1) Mac OS X DVD.

2) External USB or firewire hard drive of the same capacity as your internal drive formatted with Apple Partition Map scheme. Correct me if I am wrong, but booting from USB drives only works for intel Macs. You would need firewire drive for PowerPC Macs.

 

Cloning procedure

 

1) Format your external drive with Apple Partition Map scheme and name it, for example, backup.

2) Boot from Mac OS X DVD. First prompt will be to choose installation language. Choose English or whatever language you prefer.

3) Next Welcome screen will come up. DO NOT click Continue. Instead, go to Utilities menu and start Terminal application.

4) Once it's open, issue mount command to check that disks are recognized and mounted. Here is sample output from my iMac which was booted from Tiger DVD:

 

-bash-2.05b# mount

/dev/disk1s3 on / (local, read-only)

devfs on /dev (local)

fdesc on /dev (union)

<volfs> on /.vol

/dev/disk3 on /Volumes (asynchronous, local, union)

/dev/disk4 on /private/var/tmp (asynchronous, local, union)

/dev/disk5 on /private/var/run (asynchronous, local, union)

/dev/disk2s3 on /Volumes/backup (local, journaled)

/dev/disk0s2 on /Volumes/Macintosh HD (local, journaled)

-bash-2.05b#

 

Here you can see my internal hard drive listed as /dev/disk0s2 which is mounted under /Volumes/Macintosh HD and my external hard drive that I named backup listed as /dev/disk2s3 and mounted under /Volumes/backup.

 

5) Issue following command to start your backup. Note of caution!!! You don't want to make mistake with source and destination drive. You will lose all your data if you do. That's why I named my backup drive backup, so it's very clear which one is which.

 

asr -source /Volumes/Macintosh\ HD/ -target /Volumes/backup -erase -noprompt

 

-erase option tells asr to automatically erase destination volume and -noprompt option tells asr not to ask for confirmation. You are free not to use these options. Btw, asr has a lot of options. Man page goes into great detail about all of them.

 

6) Once backup is complete which in my case took a couple of hours for over 200 Gb of data on 320 Gb hard drive, issue bless command to make backup volume bootable. Note that since -erase option was specified asr renames backup volume into Macintosh\ HD\ 1 volume.

 

bless -folder /Volumes/Macintosh\ HD\ 1/System/Library/CoreServices

 

7) Once this was done, exit Terminal app and reboot you Mac from external drive to verify that backup worked. Hold Option key at startup and choose external drive as the one to boot from.

 

On a side note, it is also possible to clone the internal hard drive without Mac OS X DVD, but in this case, backup process will take much longer since asr won't be able to use block copy. Also you would need to add sudo in front of asr and bless commands. If want to do it this way, start Terminal app and issue:

sudo asr -source /Volumes/Macintosh\ HD/ -target /Volumes/backup -erase -noprompt

Mac OS will prompt for admin password

 

and once backup is complete

 

sudo bless -folder /Volumes/Macintosh\ HD\ 1/System/Library/CoreServices

 

I tried this method many times with OS X Tiger. Since I just upgraded to Leopard a couple of days ago, I haven't had a chance to try this with Leopard. It should work the same way.

 

One other thing I tried with this kind of cloned disk is using my iMac clone with MacBook Pro while my iMac was repaired. It worked just a bit slower because I was booting from external drive, but I could continue using my home iMac clone with MacBook Pro.

Share this post


Link to post
Share on other sites

Whilst cool, SuperDuper will do the basic clone for free. It's the scheduling and smart update features that you unlock when you pay.

Share this post


Link to post
Share on other sites
Whilst cool, SuperDuper will do the basic clone for free. It's the scheduling and smart update features that you unlock when you pay.

 

True. I just got a kick out of the fact that the cloning functionality was available within Mac OS and it wasn't hard to use either.

Share this post


Link to post
Share on other sites

It's there but why would you use it? Reading through that procedure it sounds much more difficult than just using with CCC, Superduper, or silverkeeper. All of which are free and have a nice front end.

 

For example you run through how to restore first. So you have your data on an external drive and you want to copy it back to the internal. So you find your DVD boot it up and choose utilities. Then go enter some text where you could possibly mess up and lose everything and eventually you get everything back. Or you could plug in the external drive boot from the drive run whatever software you are using and pick the internal drive with no chance of making a mistake. Seems easier to me. Plus you can pay $25 and get scheduled incremental backups with Superduper.

Share this post


Link to post
Share on other sites
It's there but why would you use it? Reading through that procedure it sounds much more difficult than just using with CCC, Superduper, or silverkeeper. All of which are free and have a nice front end.

 

For example you run through how to restore first. So you have your data on an external drive and you want to copy it back to the internal. So you find your DVD boot it up and choose utilities. Then go enter some text where you could possibly mess up and lose everything and eventually you get everything back. Or you could plug in the external drive boot from the drive run whatever software you are using and pick the internal drive with no chance of making a mistake. Seems easier to me. Plus you can pay $25 and get scheduled incremental backups with Superduper.

 

Well, it's certainly the matter of personal preference which tool to use. Some people like GUI, some people prefer command line. This is just another way to clone your disk for free without needing to download or buy any extra tools. Sometimes other tools may not be available or as it happened with Super Duper, not immediately compatible with the latest release of OS X. I remember Adam mentioned recently that his Super Duper backup didn't work when his Mac mini hard drive died. It may not be total point and click solution, but it works very well and I though it was just cool that Mac OS X has the capability to clone disks out of the box unlike some other OSes.

 

I made my very first backup attempt with CCC, it did the backup, but it wasn't bootable. I didn't feel like spending a lot of time trying and buying different software. I use dd frequently for disk/partition duplication in my day job with Solaris and Linux systems, so I thought of command line way. In the worst case scenario if your internal hard drive died and you want to restore from your backup made with asr, you don't need any extra software or even OS X DVD to get to your data. You simply boot from your cloned drive by holding Option key at startup and choosing external drive as boot drive. That's it. You are up and running.

 

I don't know about backups made with CCC and Super Duper, but I can use my asr cloned disk with another Mac while my primary Mac is being serviced. It took Apple several weeks to fix my iMac. I was lucky to have MacBook Pro as my work laptop. I simply connected my cloned iMac drive to it and booted from it on my MacBook Pro, continuing to download podcasts, photos from my digital camera and do whatever I usually need to do with my iMac. When my iMac finally came back, I cloned external drive contents back to iMac's internal drive without missing a bit.

 

Making typing mistake can be easily addressed by putting 2 commands that I mentioned into shell or Apple script and making it a point and click solution.

Share this post


Link to post
Share on other sites

Both carbon copy cloner and superduper backups can be used in that way. I was working off my SuperDuper backup when my poor laptop was stolen last year whilst I waited for the insurance to cough up the money for a replacement.

Share this post


Link to post
Share on other sites
Both carbon copy cloner and superduper backups can be used in that way. I was working off my SuperDuper backup when my poor laptop was stolen last year whilst I waited for the insurance to cough up the money for a replacement.

 

That's good to know. I will give SuperDuper a try.

Share this post


Link to post
Share on other sites
I don't know about backups made with CCC and Super Duper, but I can use my asr cloned disk with another Mac while my primary Mac is being serviced.

Carbon Copy Cloner tries very hard to use asr under the hood. If it can't use asr, it falls back to ditto. Either way, it's just a GUI interface to the underlying command line tools, so it produces the same backup.

 

In Disk Utility there is a "Restore" capability which is kind of a misnomer. It appears to be useful only for re-installing original software, but it is in fact nothing more than a GUI front end to asr. Again, it makes the exact same backup, with the exact same limitations.

 

That having been said, I think it's good to know the command line tools. I don't completely understand why people are so averse to the command line that they won't type in (or paste in) a one-line command until there is a downloadable application that puts a big button on the screen that just types the one-line command for them. To my mind, the hassle of downloading such a program far outweighs any potential convenience the GUI might provide.

 

When they say "Why use Terminal when there's this app you can download that does the exact same thing?" my gut reaction is "Why download another app when I already have Terminal which does the exact same thing?" The less non-standard software on my machine, the better. Especially since with Terminal I can see exactly what's going to happen. Who knows what clicking that button is going to do?

Share this post


Link to post
Share on other sites
Carbon Copy Cloner tries very hard to use asr under the hood. If it can't use asr, it falls back to ditto. Either way, it's just a GUI interface to the underlying command line tools, so it produces the same backup.

 

In Disk Utility there is a "Restore" capability which is kind of a misnomer. It appears to be useful only for re-installing original software, but it is in fact nothing more than a GUI front end to asr. Again, it makes the exact same backup, with the exact same limitations.

 

That having been said, I think it's good to know the command line tools. I don't completely understand why people are so averse to the command line that they won't type in (or paste in) a one-line command until there is a downloadable application that puts a big button on the screen that just types the one-line command for them. To my mind, the hassle of downloading such a program far outweighs any potential convenience the GUI might provide.

 

When they say "Why use Terminal when there's this app you can download that does the exact same thing?" my gut reaction is "Why download another app when I already have Terminal which does the exact same thing?" The less non-standard software on my machine, the better. Especially since with Terminal I can see exactly what's going to happen. Who knows what clicking that button is going to do?

 

Thank you ganbustein!!! That was exactly the point of my post. Yes, there are nice GUI tools, but built-in command line tools can be just as if not more powerful. When I first needed a backup in a rush, I was totally new to the OS X and CCC didn't work for me right away despite being GUI tool. Figuring it out was indeed a hassle. I wasn't sure why my backup wasn't bootable. May be I did something wrong or may be it didn't work because CCC was originally written for PowerPC and I had Intel Mac. At that point I didn't know. On the other hand using asr was totally transparent and worked right away. Btw, the very first time I didn't even use OS X DVD. I just connected my USB drive, opened Terminal app, typed one command and couple hours later it was done.

Share this post


Link to post
Share on other sites

Whilst I'm not personally adverse to using the terminal, I like to point out the GUI method since there are a lot of people who will read this who are for one reason or another.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing

    No registered users viewing this page.

  • Who's Online (See full list)

    There are no registered users currently online

×