Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create bootable clones via the command line System
There are many good disk cloners out there, but all of the ones I know of require a Quartz connection -- and so they can't be used remotely. I have written this wrapper around asr(8) that copies the Startup Volume to the Volume whose path is specified on the command line (if the path has spaces, you need to quote it). It then deletes those objects on the clone that will keep it from booting/working properly (much like Carbon Copy Cloner, but with a few additions such as my own user Cache).

Read the rest of the hint for the script...

#!/bin/sh

if [ `whoami` != "root" ]; then
  echo "You must be root to use this!"
  exit 1
fi

TGT="$1"
if [ "$TGT" = "" ]; then
  echo "Usage: $0 target_volume"
  exit 2
fi

logger -t backup "Backup started"
date

asr -source / -target "$TGT" -erase -verbose

vsdbutil -a "$TGT"

rm -rf "$TGT"/var/db/volinfo.database
rm -rf "$TGT"/var/db/BootCache.playlist
rm -rf "$TGT"/var/db/NetworkInterfaces.xml
rm -rf "$TGT"/var/db/PowerManagement.xml
rm -rf "$TGT"/var/db/SystemConfiguration/com.apple.PowerManagement.xml
rm -rf "$TGT"/var/vm/swapfile*
rm -rf "$TGT"/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist
rm -rf "$TGT"/Library/Caches/*
rm -rf "$TGT"/System/Library/Caches/*
rm -rf "$TGT"/System/Library/Extensions.kextcache
rm -rf "$TGT"/System/Library/Extensions.mkext
rm -rf "$TGT"/TheVolumeSettingsFolder
rm -rf "$TGT"/Users/ataraxia/Library/Caches/*

logger -t backup "Backup completed"
date
[robg adds: You'll need to make this executable with chmod 755 scriptname, and as noted, it must be run as root via sudo. I have not tested this script!]
    •    
  • Currently 2.83 / 5
  You rated: 4 / 5 (6 votes cast)
 
[22,781 views]  

Create bootable clones via the command line | 6 comments | Create New Account
Click here to return to the 'Create bootable clones via the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create bootable clones via the command line
Authored by: daveschroeder on Sep 21, '04 01:00:42PM
Actually, it is not required to remove ANY of those items for a successful clone with asr. A perfect, working clone with asr can be done using only:

sudo asr -source / -target /Volumes/[disk name] -erase

That's it. This assumes you're booted from the device you wish to clone, and that you would like to erase the target before cloning. Replace [disk name] with the name of your target volume; it will need to be in quotes if it contains a space.

See man asr for more information.

So, what if you want to do this frequently, but don't want to wait for asr to clone a 250GB hard disk? Another good companion to this is a technique that will give you a perfect, bootable clone via synchronization, using RsyncX. RsyncX contains a special version of rsync that is aware of Mac resource forks and HFS+. You can download RsyncX here. RsyncX installs its special rsync at /usr/local/bin/rsync.

To make a perfect clone of the boot drive to another drive, only copying things that have changed instead of the whole drive, the following command can be used:

sudo /usr/local/bin/rsync -a --delete --eahfs --exclude="/dev*" --exclude="/private/tmp*" --exclude="/Network*" --exclude="/Volumes*" --exclude="/private/var/run*" --exclude="/afs*" --exclude="/automount*" "/." "/Volumes/[disk name]/"

This can also be used in a cron tab, such as /etc/daily, for example. Add -v for verbose, --showtogo to show a percentage and number of files remaining, or --dry-run to see a "dry run" of what rsync would do, without actually changing anything.

[ Reply to This | # ]

Create bootable clones via the command line
Authored by: ClassicUser on Sep 21, '04 08:01:17PM
Actually, it is not required to remove ANY of those items for a successful clone with asr. A perfect, working clone with asr can be done using only: sudo asr -source / -target /Volumes/[disk name] -erase
That's it. This assumes you're booted from the device you wish to clone, and that you would like to erase the target before cloning. [...]
See man asr for more information.
Actually, since the asr man page itself specifically calls out that you should clean up the source volume before cloning (remove BootCache.playlist, volinfo.database, etc.), as well as booting from a different volume, I'd say those provisions are kinda necessary. By no means will you have a "perfect" clone, if you don't follow all the guidelines.

Trust me: If you're trying to create a reliable source image, you want to be as careful as possible. While some things "look like they work" if you take a lazy approach to mastering that original image, many many problems can creep in afterwards, if you aren't very careful.

Overall: Follow ALL the guidelines given in the man page for asr, and you'll have a much more reliable source image.

[ Reply to This | # ]

Create bootable clones via the command line
Authored by: daveschroeder on Sep 21, '04 10:13:32PM

No, that's only if you're using asr to build a distribution image; most of the removals are recommended but not necessary, by any means, and the desired removals only apply when the image is to be used on entirely different hardware than that on which the image was created, and to work around problems that occurred in earlier versions of Mac OS X.

Simply cloning a volume for use as a writable backup on the same machine does NOT require ANY cleanup, at all, since the OS is to be used on the exact same hardware. Since this article speaks to remote backup, it is inferred that it is to be used on the same machine. The only required cleanup in *any* scenario is BootCache.playlist and volinfo.database, and that's only if you're making an image. And even then, it's still not required, because since 10.2.1, BootCache.playlist and volinfo.database will get properly recreated on any hardware, and all swapfiles will ALWAYS be recreated.

My original post is completely accurate. Yes, definitely follow the documentation, but in this case, the cleanup you speak of does not apply to a volume-to-volume clone: it applies to "a disk image for restoration on another volume".

The example stated for volume cloning (NOT disk image creation) in the man page is:

Volume cloning:
sudo asr -source /Volumes/Classic -target /Volumes/install



[ Reply to This | # ]
Create bootable clones via the command line
Authored by: osxpounder on Sep 22, '04 12:37:13PM

So, if I backup my HD using dave's shorter plan, then change my hardware, I risk not being able to restore from my backup?

---
--
osxpounder



[ Reply to This | # ]
Create bootable clones via the command line
Authored by: daveschroeder on Sep 23, '04 09:47:08AM

No, I have used that exact method hundreds of times on everything from laptops to Xserves to Power Mac G3, G4, and G5 and everything in between, and have NEVER had any issue or anomaly. That's exactly how it's supposed to work, and is perfectly in accordance with the documentation (see my previous post).

The ONLY time ANY cleanup is recommended is if you are making a distribution IMAGE. Swap is deleted to save space, and the volume info stuff was deleted because it could cause kernel panics under certain conditions on different hardware on earlier versions of Mac OS X, but that has all been resolved, so even that doesn't matter any more.

The only command that is needed for any type of hardware (ASSUMING the hardware supports that particular version of Mac OS X[1]) is the single asr command I've described above. Same goes for rsyncx.

[1] Example: the iMac G5 comes with a NEWER version of Mac OS X 10.3.5 (7P35) than the "normal" 10.3.5 (7M34). You wouldn't be able to take a 7M34 clone and boot an iMac G5 with it. When the next point update, e.g., 10.3.6 (if there is a 10.3.6) comes out, it will consolidate all of the updates, making 10.3.6 universal again...until the next new hardware comes out. This is ONLY an issue for new hardware that has a special build of OS X for new hardware support. Other than this specific exception, an install of Mac OS X is always universal, and can be used on everything from an iBook G3 to a Power Mac G5. And even in the case of the "special" builds, if a universal image is desired, it's standard practice to simply use the newest build - even "updating" over an existing installation with the new build is acceptable.



[ Reply to This | # ]
Create bootable clones via the command line
Authored by: KSchlz on Feb 20, '06 10:06:14AM

Hi
I noticed strange things.
When asr is called, it seems to change my volume name.
It always changes the target volume to the name of the source volume
{blank}1
So my / is called nagasena, the target becomes
nagasena 1
This sucks because I have no clue why this is happening, and vsdbutil is called on the wrong volume name hence fails to execute.
Any idea?
Kay



[ Reply to This | # ]