Partition Cloning

Cloning a partition is not a difficult task. However there are a lot of steps that have to take place. We will use a variety of open-source software to help get the task accomplished. In this tutorial it is assumed that a Windows NTFS partition is being cloned and that there is an available FAT32 partitioned drive with sufficient space to save the image file to. Please read through the whole tutorial before beginning the task!!!

Overview:

An NTFS partition is cloned by using the ntfsprogs group of tools. The image file will be saved to a FAT32 formatted partition and imaged to the destination drive. A linux live-cd will be used as the workbench.

Tools Needed:

Knoppix Live-CD or DVD
GParted Live-CD

Note: At the time of writing this tutorial, GParted is not a binary that is included with Knoppix. Also, newer versions of Knoppix (>= 4.0.2) include a version of QTParted that uses ntfsresize version 1.11.2 or later. ntfsresize is the backend command-line program that GParted and QTParted use to resize our NTFS partitions.

Drives Needed:

Drive with NTFS partiton to be cloned (A)
Drive that will be formatted FAT32 to be used as a container for the image file (B)
Drive to be imaged with the NTFS clone image (C)

Note: If there is enough free space on the (A) drive, you may copy the image file back to that drive under Windows and use it as the source drive (C) when restoring the image to the (B) drive.

Mounting the drives and creating the image:

  1. Insert the Knoppix Live-CD and boot.
  2. When the OS finishes booting and the GUI loads, open up a terminal window.
  3. Since Knoppix mounts drives read-only by default, we will need to manually mount our FAT32 drive to be writable.
  4. First determine which drive is the FAT32 drive. There are several ways to do this. QTParted (Start -> System -> QTParted) is one way. Look at the size of the drives to determine which device is the FAT32 drive.
  5. Format the drive by right clicking and click create. Select the file system type to be FAT32. Commit the changes.
  6. Note the path of the drive — e.g. hdb1
  7. Also note the path of the drive/partition to be cloned — e.g. /dev/hda1

Now we will mount the drive:

  1. Open up a terminal window (should have an icon of it on the taskbar)
  2. Type the following in (substitute hdb1 with the correct drive name):

    sudo mount /dev/hdb1 /mnt/hdb1 -t vfat -o users,exec,umask=000,uid=knoppix,gid=knoppix,rw

  3. Test by cd’ing into the directory:

    cd /mnt/hdb1

Then the actual cloning:

  1. Make sure you are in the root directory of the FAT32 drive:

    pwd

    You should get something back like /mnt/hdb1

  2. Enter the following in the terminal (substituting /dev/hda1 with the partition to be cloned):

    ntfsclone --save-image --output ntfs-backup.img /dev/hda1

  3. Next back up the MBR:

    dd if=/dev/hda of=mbr.bak bs=512 count=1

Procedure with 3 drives:

  1. You’ll may need to shutdown the computer and attach the new drive if is not connected already.
  2. Use QTparted or open the desktop icons after restarting to determine the paths of drives.
  3. Using QTParted, create an NTFS partition on the (C) drive that is as large as the imaged partition from (A). (Note, the size of the file ntfs-backup.img will be significantly smaller than the size of the actual (A) partition.)
  4. You may image the new drive with the following command (substituting /dev/hda1 with the appropiate drive path):

    ntfsclone --restore-image --overwrite /dev/hda1 ntfs-backup.img

  5. Write to the MBR:

    dd if=mbr.bak of=/dev/hdb bs=512 count=1

Test the drive in the original computer and you should be done.

Procedure with 2 drives:

  1. Replace the drive (A) in the original system and also connect the (B) drive.
  2. Start up the system and copy the two files (ntfs-backup.img and mbr.bak) to the root directory of drive (A).
  3. Restart the system with the Knoppix Live-CD loaded.
  4. Using QTParted, create an NTFS partiton on the (B) drive at least as large as the imaged partition from drive (A).
  5. Image the new drive (substituting /dev/hda1 with the appropiate drive path):

    ntfsclone --restore-image --overwrite /dev/hda1 ntfs-backup.img

  6. Write to the MBR:

    dd if=mbr.bak of=/dev/hdb bs=512 count=1

Test the drive in the original system and you should be done.

Possible Problems:

You may need to resize the partition to be imaged. If your source drive and destination drive are both roughly the same size, it would be a good idea to resize as disk drive mfg’s do not adhere to the same size standards. If your destination drive is small by a fraction, the image will not be able to be written.

This is where we will use GParted.

  1. Start up the computer with the GParted Live-CD.
  2. Go through the dialog boxes.
  3. GParted should load automatically. Then select the partition you wish to resize. Click and drag to resize.

  4. Commit the changes.
  5. Shutdown the system. Boot up the drive in it’s original computer to allow checkdisk to run. This is important. You cannot create an image of the drive if chkdsk is not run.
  6. Follow the previous steps to image the drive.

sources:
http://www.mckeay.net/secure/2004/10/using_dd_to_clone_a_hd.html
http://www.justlinux.com/forum/printthread.php?t=134457