Friday, November 13, 2009

How to clone hard drives with Clonezilla

Clonezilla is a Ncurses-based front-end to a set of scripts that use several open source disk utilities such as Partimage, ntfsclone, Partclone and dd.

It'll jump at your command and duplicate particular partitions, or better still complete disks. It'll also restore the partitions, and help you mirror an old disk onto a bigger new disk.

Clonezilla supports a whole battalion of filesystems and then some. It can work its magic on partitions formatted as ext2, ext3, ReiserFS, XFS, JFS, FAT, NTFS, and HFS+, so you can let it rip on Linux, Windows, and Intel-based Macs.

If Clonezilla encounters a partition type it doesn't understand, say Solaris's ZFS, it'll fire up the venerable dd and still get the job done.

It'll constantly amaze you, so if you're looking for a bullet-proof way to backup your disks, read on...

Big on saving
Clonezilla not only saves your data, but also saves you a lot of time when doing so, by concentrating its efforts on stuff that matters - or segments of the disk that contain the data, and ignoring the blank space.

But, unlike a simple data backup app, Clonezilla remembers the size of the partitions that you're asking it to clone.

So, if you have a partially used 10GB NTFS partition, you can squeeze it in a 4GB pen drive, and yet when restoring it on another disk, ask Clonezilla to create the original 10GB partition.

Oh, and it can compress this data using gzip, bzip2, or lzo compression algorithms. In theory it should take a lot of time to compress the data, but on the chic dual-cores juiced with a couple of GB of RAM, you'd hardly have time to make coffee.

I cloned an 80GB disk with one NTFS, one FAT, three ext3, and a Solaris ZFS partition on to a 40GB USB disk in under 20 mins. And it took less than half that time to restore.

Checklist for cloning
It's not difficult to get started with Clonezilla, but there are a few things you need before you can clone a disk or a partition, and you need to understand the process as well.

Local or Universal repository?
Clonezilla compresses the data on the partition/disk that you're cloning into an image. The most important decision in the cloning process is to select a repository where it keeps these image.

You can keep them in a locally attached device, such as a USB disk attached to the computer, or on another disk on the same computer.

You can also keep the images on a computer halfway across the galaxy as long as you have network connectivity to the remote box.

Clonezilla lets you communicate with an SSH server, a Samba server or an NFS file share, after prompting you for the necessary login info.

When using a locally attached device, Clonezilla scans it and displays the list of disk and partitions on the device.

When you're selecting a repository, make sure the disk or partition where you'll store the images is not the same one that's being cloned (the repository partition is mounted under /home/partimag).

Clone or copy?
Clonezilla can clone partitions and clone disks on the fly, but it can't do both at the same time, so you'll get the opportunity to select whether you want to create a clone image or directly clone a disk or a partition on to another disk attached to your box.

Even if you wish to clone one disk on to another, you can go via the image route. When you have a working image of your disk, you can experiment with the direct disk-to-disk/partition-to-partition cloning.

Clone this, restore that
Despite all its clever options and smart behaviour, Clonezilla relies on you to select a partition for it to clone or restore.

When cloning, you'll be shown a list of disks or partitions, depending on whether you selected to clone complete disks or individual partitions, at the start of the cloning process.

When restoring a partition, Clonezilla lists all the partition images it has on the repository you've pointed it at.

All you have to do is find and select the partition you wish to restore. If you get this wrong, you'll have restored the wrong partition.

Don't worry, there's no harm done - just restart the process and select the right image.

To compress or not to compress?
There is no straight answer to this question. If you're on a slow computer, but your repository is on a large disk, you can get through the process faster without compressing the data.

If you want to back up an enormous disk/partition on to something smaller, you can select one of the three compression algorithms.

All produce different size images, with bzip2 producing the smallest. By default Clonezilla uses gzip, which balances speed and compression ratio and produces small images without much overhead.

Split images
Depending on the size of the disk/partition you're cloning, the images can be huge, despite the compression.

Clonezilla offers to split them into smaller, more manageable chunks that you can burn onto optical media such as CDs and DVD.

By default Clonezilla splits images into 2GB chunks, and you are free to shrink or increase this number. If you prefer one big huge chunk, select 0.

Which program to use?
Clonezilla packs a variety of programs to handle different partitions. When it sees a partition, it goes through the tools at its disposal in a particular order, and selects the most appropriate one.

By default, it first lets ntfsclone have a look at the partition. If it runs into an ext3 partition, Clonezilla then calls in Partimage. If it sees a partition that Partimage can't handle, it calls in dd.

Generally you wouldn't want to mess around with the priority, but if you know you have a disk full of partitions that none of these apps can handle, you can save a bit of time and direct Clonezilla to use only dd.

Or if you are feeling lucky, you can choose a priority order which calls the experimental Partclone utility before dd to back up your Mac OS X partitions.

Understand your partitions
If you don't know your hda from your sda, you'll not be able to do much with Clonezilla. If you're copying entire disks, it's also a good idea to make sure that clones of IDE disks are restored to IDE disks.

It's possible to clone an IDE disk on to a SCSI disk, but it involves some command-line fun, and depending on the complexity of the disk, you might not always come out on top.

Step by step: Cloning a disk


Where to save?


Where to save? After booting the Clonezilla live CD and opting to create a clone, select where the images are saved. The 'local_dev' option saves the image on a locally attached device.

To use any of the three over-the-network options, you must have the relevant connection and login details.

Disk or partitions?


Disk or partitions? Now select whether you want to clone a complete disk or just individual partitions. The 'savedisk' option clones whole disks and will later prompt you to select a disk on the computer.

If you select 'saveparts' you will be asked to select the partitions you wish to clone later on.

Select the disk to clone


Select the disk to clone This is the most important step of the whole process. You'll be shown a list of disks or partitions, depending on whether you selected to clone complete disks or individual partitions. You can select multiple partitions by using the space bar.

Moving to a bigger disk
It's easy to ensure that a clone of a SCSI disk is restored to a SCSI disk, but you'll have a tough time finding an exact replica size-wise.

The good news is you don't have to restore a disk on another disk of the same size. The even better news is that you can in fact restore the image to a much larger disk.

When restoring a disk, Clonezilla enables you to resize the filesystem and create partitions on the new disk proportionally.

But even if you are moving to a bigger disk, you might prefer to keep the partitions as they are. In that case you can ask Clonezilla to create the partition table as its listed in the image.

Know your parameters
The programs included in Clonezilla that do the actual cloning and restoring have a few configurable parameters.

Clonezilla will bring up the relevant options, after you've selected the disks/partitions to clone/restore. Don't get hassled when you see them, because Clonezilla would have marked the best (and safest) options for you.

The parameters that you should pay close attention to, are the partition and restore parameters. If you are clumsy with these parameters you'll end up wiping the MBR, or worse still nuke data on the target disk, which wouldn't probably always be new and empty. All options are clearly explained, and it'll help if you pause and think before selecting them.

Always pay close attention to the Grub and bootloader options. If you're restoring a disk on to a bigger disk, it's always a good idea to use the partition table from the disk being cloned, and you should use the option to create the new partition table proportionally.

But then again, you might not always want Clonezilla to modify the MBR when restoring a disk.

Maybe you want to restore the data on to a secondary disk and prefer to modify the Grub on the primary disk to point to the distro on the restored disk.

Or maybe you are restoring a partition on a disk that already has a bootloader. In this case, it's not a good idea to reinstall Grub from the image and you also shouldn't create a partition table on the disk.

Restore DVD
Once you've cloned a disk, you can copy its image to an optical media like a CD or DVD. Better still, you can ask Clonezilla to do it for you - not that Linux users have a shortage of media burning apps.

But when Clonezilla creates an ISO or an image for your USB disk, it'll also pack itself on to the media.

Now you'll have your disk/partition images as well as the means to restore them in one very convenient and portable location.

Step by step: Restore from a cloned image

Choose to restore


Choose to restore After you boot the live CD and select the repository containing the cloned images, you need to opt to restore an image to disk or restore an image to a partition.

The recover-iso-zip option reads the image and churns out a bootable ISO image.

Select where to restore


Select where to restore Now Clonezilla displays a list of all the unmounted partitions that you can restore the image on to.

Clonezilla wipes the partition and creates a new partition table on the disk, so be careful, or you'll be in trouble.

Partition parameters


Partition parameters Partitioning is the most critical step whether installing a Linux distro or restoring one from an image. Again, be very careful here, or you'll end up with a useless target disk.

Advanced CLIoning
If you think you can be efficient at low-level system administration tasks by sticking to the graphical interface, you've got another thing coming.

Like most power tools, to squeeze the most of out Clonezilla you need to cut down on the GUI and move closer to the keyboard.

When you get down to cloning and restoring a disk you'll realise that you were never that far from the command line anyway.

After it's done pestering you for info through an endless series of Ncurses screens, just before it begins cloning/restoring, Clonezilla spits out a rather long command that tells you that you can use next time around.

It looks something like this:
# /opt/drbl/sbin/ocs-sr -q -c -gm -z1 -i 2000 -p true savedisk "2009-01-25-02-img" "hda"

Assuming you would like to repeat the operation you just did, you can issue this command at the Clonezilla prompt to avoid having to labour through all the steps.

All the switches in this command reflect the options you've opted for in the GUI. For example, the -q is for the default priority, and -z1 in there points to the gzip compression algorithm.

Once you get the feel for it you can also modify the command to alter minor settings like the compression algorithm to use, or more serious settings like choosing a different partition/disk.

It's a good idea to clone disks regularly, since it doesn't take much time. So the next time your hard disk decides to pack in, use your time finding the best bargain for a replacement instead of worrying about data loss.

Step by step: Cloning on the fly

Local or remote?


Local or remote? As with the normal cloning process, the first step in direct cloning is to select what you want to clone and where you want to clone it.

Clonezilla can copy a local disk or partition to another locally attached disk or partition or to one accessed remotely.

Source disk/partition


Source disk/partition Next select the disk/partition you wish to clone. Unlike the normal cloning route, which creates an image, when cloning on the fly, you can only select a single disk or a single partition to clone.

Target disk/partition


Target disk/partition The next obvious step in the process is to select a disk/partition where the source disk/partition will be cloned.

Stay alert when making a selection here. If you choose the wrong disk/partition, it'll be wiped clean.

No comments:

Post a Comment