Saturday, July 19, 2014

Clone, Save, Backup, Restore Hard Disk Partitions – Part I

Read Part II here.

In this series, we would like to explain on how to clone your hard disk partitions along with data, then backup it in a separate disk. Later we will show on how to restore the cloned partitions back, either to the existing disk or to a brand new disk.

We’re always searching for a tool, that can clone and backup our hard disk, along with all installed operating systems and configurations. Later we should be able to restore it back, if the inevitable happens like a new upgrade broke the existing system. You would also prefer to clone your physical system, and restore it to a virtual environment like virtualbox to try some new updates, softwares etc before you actually apply them to your physical machine. So that, you’re at most sure that, it wont broke your existing system.

Our major expectation from the tool are below.

a. Backup should be small as possible and it should have a good compression level

b. Should support both Linux and Windows based partitions

c. Only “used hard disk space” should be backed up. Free space should not included with the backup

d. Ease of use, backup and restore operations

e. Backup should work like normal files, that can be X-Copied and moved to other machines for restoration

This is the Part-I of the series, where we explain on how to clone and save your hard drives. Part II will explain on how to restore the same.

As we’ve both Windows and Linux based partitions, the tool we’ve considered is “CloneZilla”. This seems to be one of the best tool for this purpose and ease of use. CloneZilla is included within “Parted Magic” live CD, which is no longer free now. But you can download it from here (Alternate download here).

Note: If you opt, you can also download the free “CloneZilla” live cd from here and “Gparted” from here. But you may need to boot into them individually. Or you can try Ultimate Boot CD. You can download it from here. We haven’t used it, but it is said to include both clonezilla and gparted.

Using CloneZilla, you can clone and backup an entire hard drive in one go!. Also you can selectively clone and backup individual hard drive partitions as well. We are only considering the latter, as former option (Cloning entire hard disk) is pretty simple to achieve and the steps are intuitive with the CloneZilla wizard. Also cloning the entire hard disk is a waste of your backup space, as most of the time you only want to backup your operating system partitions and not your data in other partitions. The data can be simply X-Copied to wherever you like and copy back.

Ok enough theory. Now we will move to our live example.

1. Check and Fix errors in the Source Hard Drive Partitions

This is the very important step. You should do a through disk check before cloning. For NTFS format partitions, you can use ‘chkdisk’ command within windows. To check linux partitions you can use either ‘fsck’ or ‘e2fsck’. Use options to fix the disk errors.

2. Boot into PartedMagic Live CD

Boot to the live CD.

Note: If you opt, you can also download the free “CloneZilla” live cd from here and “Gparted” from here. But you may need to boot into them individually. Or you can try Ultimate Boot CD. You can download it from here. We haven’t used it, but it is said to include both clonezilla and gparted.

3. Attach your Backup Disk [*Optional: Skip this step, if you choose the backup to be saved in the source drive itself, that’s being cloned]

If you would like to backup the cloned image to a secondary hard disk, that should be attached prior to Step#1 (i.e Switch off, Plug in your secondary hard drive, Power up and boot to Parted Magic Live CD)

If we would like to backup the cloned image in a USB drive [With enough capacity], plug it in now.

Or better, you can save your backup to your source hard drive itself, that’s being cloned! But of course the partition that’s being cloned cannot be used to store your backup, you should choose a different partition. That’s why we’ve given this step as optional.

See below fig now. In our case, we are using a secondary hard drive (Sdb) to store the backup. In your case you should identify it’s name and replace our ‘Sdb’ place holder, references with  your own. if you’ve already two drives,  your inserted USB may be detected as ‘Sdc’.

image

It has only a single partition formatted as NTFS. It is mounted as “/media/Archive” (See the mount point in the above fig). Open it and create a new folder named ‘CurrentClone’. We plan to backup our cloned image inside the newly created ‘CurrentClone’. You can provide any name you want.

image

4. Unmount Source and Backup drives

Unmount the source disk drive and back-up disk (if they already mounted), so that “CloneZilla” can detect those. Simply right click on the drive (Open the file manager, than in the left pane, you can view the drives) and choose unmount.

5. Clone Hard Drive Partition Table Structure [*One Time Activity: You can skip this step, if you intend the backup only for restoring it back to the original source drive being cloned]

This step is required, if you want to restore your cloned image to a separate hard disk, rather than to the same hard drive again at a later time (e.g. to setup a virtual environment, you may want to restore the image to a new virtual hard disk).

Note (NB): Please note one important thing. If you clone your existing hard disk to a newer hard disk, your newer hard disk should have a total partition size equal or greater than to your source drive partition size. This does not means you can clone your source hard disk to a smaller disk. It’s still possible, but you’ve to first shrink your partitions to a smaller size, that can fit it to the target disk. Then create that partition layout in the target disk. You can use GParted application to resize your partition.

Ok. Let’s see an example from our environment. Below is our current partition layout.

image

As we can see, there is Windows XP in Sda1 (with bootable flag set), Lubuntu in Sda5, FatDog64 in Sda6 and others are normal partitions for storing data. Please also note that partitions are perfectly ordered based on their position (i.e Sda1->Sda5->Sda6->Sda7->Sda8). If your partitions are unevenly ordered and if you’re ambitious enough to make it ordered as per their position, you can follow this guide. But this is optional and can leave as it is if you choose.

Note: You may wonder, where Sda3 and Sda4 have gone, and may argue that the above layout is not ordered because of this. But believe me it is okay. We had this confusion before, but later realized that the numberings “Sda1 to Sda4”  are dedicated for physical partitions  (Primary and Extended, At most 4 in a hard drive). In the above setup ‘Sda1’ is primary partition and ‘Sda2’ is the extended partition. ‘Sda5’ to ‘Sda9’ are logical partition comes under the extended partition ‘Sda2’. So ‘Sda3’ and ‘Sda4’ are reserved for any primary partitions that we will create in future if we choose.

Now take a command prompt and type in ‘sudo fdisk –l /dev/sda’. This will print the partition layout of your hard drive.

image

Now we will save this partition layout also to our backup location (i.e ‘/media/archive/CurrentClone’) with the name ‘partitiontable.txt’. To do that type in the command below.

“sudo sfdisk -d  /dev/sda > /media/Archive/CurrentClone/partitiontable.txt ”

image

 

6. Clone Selected Hard Drive Partition [Note: Repeat this step, for each partition to be cloned]

Now here comes the actual cloning of individual partitions!

For this example, we will show cloning of one partition that contains the Windows XP. That is ‘Sda1’. If we want to clone another partition say cloning ‘Sda5’ that contains ‘Lubuntu14.04’, we should follow this step again.

Now run the “CloneZilla” application. (Icon named ‘Disk Cloning’ in the desktop)

Select default. ‘device-image’.

image

Select ‘local_dev’

image

Now select your ‘Backup Disk Partition’ to which you want to save the cloned image. In our case it is ‘Sdb1’, the secondary hard disk. If you’ve opted USB backup disk, select it here.

image

Now within your backup disk, select the top level folder to which you want to save the cloned image. In our case, we’ve already created a folder named ‘CurrentClone’ and we’ve selected it in this step.

image

Select expert mode

image

Select ‘SaveParts’ to save individual partitions.

image

Now provide a name for your partition backup. CloneZilla will create a folder with this name under the top level folder, you’ve selected earlier.

image

Now choose your source partition that is to be cloned. In our case, we are cloning partition that contains ‘Windows XP’ (‘Sda1 26.8GB_ntfs_WinXp…”). Select it and move to next step.

image

Select default selected option

image

Select only ‘-c’. Nothing else.

image

Select default selected option

image

Provide a higher value, so that your backup will not be split into multiple files.

image

Select default selected option

image

Select default selected option

image

Select default selected option

image

Confirm the operation by typing ‘Y’ two times.

image

Now relax and have a cup of coffee. The operation may take some time to finish, so let it finish the job.

image

Now you’ve successfully cloned your hard drive partition. You can verify it under your backup disk. See the below, we’ve a new folder under ‘/media/Archive/CurrentClone’, that contains the entire Windows XP partition clone!

image

Now you can keep it, move it to a different machine, and then later use it to restore the state of the original source machine or can restore it to a new machine that will exactly replicate your source machine.

All those are described in Part-II of the discussion. Restoring the cloned image are detailed here!

1 comment:

  1. Hey, Your post is very informative and helpful for us. In fact i am looking this type
    of article from some days. Thanks a lot to share this informative article.

    level 3 cdn

    ReplyDelete