Results 1 to 2 of 2

Thread: Cloning an old drive to a new drive

  1. #1
    Join Date
    Mar 2008
    Phuket, Thailand
    Blog Entries

    Default Cloning an old drive to a new drive

    This is a basic guide/example for cloning an old small hard EIDE (PATA) internal drive to a new larger EIDE (PATA) internal hard drive, using the Linux "dd" command where both hard drives are 255 heads, 63 sectors/track.

    Please paste any suggested corrections/comments to this post on the following "unreviewed" corresponding thread: Cloning an old drive to a new drive - openSUSE Forums


    In the example that I did in January 2009, the old drive was 40GB and the new drive was 160GB. This was done on an old Dell Dimension 2100 PC (1.1 GHz CPU with 512MB of RAM and the latest A4 BIOS) that was purchased in 2001. After a successful cloning, the new drive will have only 40 GB of formatted bits and bytes, but it can be easily expanded to use the fully 160 GB with the appropriate utility.

    In the case where I did this operation, I used an
    (a) openSUSE-11.1 live CD
    (b) parted Magic Live CD
    (c) external 60 GB USB hard drive (for data backup).

    A note/caution from the comment thread, when cloning, drive bit pattern imperfections are cloned. For example, fragmentation which existed before the cloning, will be duplicated and will exist after the cloning. And just like before the cloning, fragmentation after the cloning can be addressed with utilities that address fragmentation. One issue one may encounter is if the new drive has bad sectors, dd will fail. Note this guide refers to cloning on to a "destination" NEW drive. On the MS-Windows partitions (win98/ME/XP) one can also run chkdsk before (and after) cloning on the windows partitions. Note if the cloning fails, one still has their original partition untouched, still bootable and one has their backup. One has lost a small amount of time (time spent connecting the new drive and time lost in the cloning attempt to the point where the bad sector was encountered).

    Another caution, if one is cloning a Linux partition, prior to cloning it is likely a good idea to check the /etc/fstab file and the /boot/grub/menu.lst of the old hard drive, to see if it uses disk-by-id identification in the /etc/fstab, the /boot/grub/menu.lst, and the /boot/grub/ files. If it does, IMHO it is best to change the fstab, menu.lst, and files to mount/label more generically (ie not by disk-id) and confirm that works prior to cloning. For new users (to Linux) , one can obtain guidance on how to do this by posting a query on this forum. In essence one simply needs to type su -c 'fdisk -l' (enter root password) to determine how one's disks are labeled, and also cat /etc/fstab to see what one's fstab has for mounting on boot.

    For example, prior to cloning assuming fdisk -l gives this:
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1        3187    25599546    7  HPFS/NTFS
    /dev/sda2            3188        5099    15358140    b  W95 FAT32
    /dev/sda3   *        5100       19929   119121975    5  Extended
    /dev/sda5            5100        8364    26218080   83  Linux
    /dev/sda6            8364       19721    91233072   83  Linux
    /dev/sda7           19722       19929     1670728+  82  Linux swap / Solaris
    and prior to cloning cat /etc/fstab gives this:
    /dev/disk/by-id/ata-Maxtor_6Y160P0_Y4319JDE-part7 swap                 swap       defaults              0 0
    /dev/disk/by-id/ata-Maxtor_6Y160P0_Y4319JDE-part5 /                    ext3       acl,user_xattr        1 1
    /dev/disk/by-id/ata-Maxtor_6Y160P0_Y4319JDE-part6 /home                ext3       acl,user_xattr        1 2
    /dev/disk/by-id/ata-Maxtor_6Y160P0_Y4319JDE-part1 /windows/C           ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0
    /dev/disk/by-id/ata-Maxtor_6Y160P0_Y4319JDE-part2 /windows/D           vfat       users,gid=users,umask=0002,utf8=true 0 0
    then prior to clonging one could change the fstab to this:
    /dev/sda7 swap                 swap       defaults              0 0
    /dev/sda5 /                    ext3       acl,user_xattr        1 1
    /dev/sda6 /home                ext3       acl,user_xattr        1 2
    /dev/sda1 /windows/C           ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0
    /dev/sda2 /windows/D           vfat       users,gid=users,umask=0002,utf8=true 0 0
    By changing this prior to cloning (and testing it prior to cloning), one can then not worry about a boot failure after cloning, because of disk specific ids in one's /etc/fstab file.

    A similar edit should be done to the /boot/grub/menu.lst and /boot/grub/ Be very careful here as a bad edit will prevent one's PC from booting the boot manager.


    Before purchasing the external hard drive, try to ensure that it is compatible with your PC (via research on the Internet). This is especially true if one intends to use the hard drive on an older PC. This guide assumes both old and new drives are 255 heads, 63 sectors/track, so attempt to confirm that prior to purchasing the new drive.

    Also before starting, check the web site of your motherboard manufacturer to see if there is a BIOS update. Sometimes there are BIOS fixes associated with new drives (and newer drive technology).

    If possible, it is useful to ensure the new hard hard drive can be returned to the computer store, if the cloning does not work. However finding a computer store that will allow that return policy is not so easy nor common.


    Before cloning, it is best to backup all data. External USB drives are inexpensive, and they make great platforms for external backed up data.


    After backing up the data, switch OFF the PC, and leave the old (smaller) hard drive connected. Connect the new hard drive to the same cable as the old hard drive, but have the jumpers on the new hard drive set as "slave". Now switch ON the PC and boot to the BIOS, and confirm that that BIOS recognizes both the old hard drive, and the new hard drive.

    In the example I did (with the old Dell Dimension 2100) the BIOS recognized both old and new drives, although the Dell recognized the new 160GB drive (a Seagate Barracuda) as a 137,447 MB drive. The fact the drive is recognized was positive, although it worried me that the 160 GB drive was recognized as a 137 GB, as opposed to 160 GB. I read on our forum that this was due to a 142 GB BIOS limit. Purportedly (from what I was told) that only means that any GRUB files should be in partitions under this limit. Linux has no problems reading the whole disk, since it doesn't rely on the BIOS to access the disk.

    Put the openSUSE Live CD in the CD drive, and with the BIOS set to boot to CD ROM first, continue booting to the openSUSE live CD. Once boot is complete, open a gnome terminal (for Gnome live CD) or KDE konsole (for KDE live CD) and type "su" (no quotes, enter root password when prompted) followed by
    fdisk -l
    to check openSUSE can see both old hard drive and new hard drive. Once may see something like this for the old hard drive:

    # fdisk -l
    Disk /dev/hda: 40.0 GB, 40000000000 bytes
    255 heads, 63 sectors/track, 4863 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/hda1 * 1 959 7703136 b W95 FAT32
    /dev/hda2 960 2043 8707230 7 HPFS/NTFS
    /dev/hda3 2943 4863 15430432+ f W95 Ext'd (LBA)
    /dev/hda4 2044 2942 7221217+ 83 Linux
    /dev/hda5 2943 4033 8763426 b W95 FAT32
    /dev/hda6 4034 4103 562243+ 82 Linux swap / Solaris
    /dev/hda7 4104 4863 6104668+ 83 Linux
    and something like this for the new hard drive:
    Disk /dev/hdb: 160.0 GB, 160041885696 bytes
    255 heads, 63 sectors/track, 19457 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Disk /dev/hdb doesn't contain a valid partition table
    So clearly here in the above example, hda was the old drive and hdb is the new drive. In this example, hda1 was a winME partition, hda2 is a winXP partition, hda5 is a fat32 data partition, and hda4, 6, 7 were all old openSUSE-10.2 Linux partitions (for /, swap, /home respectively). Note that hdb "doesn't contain a valid partition table" because it is brand new, and never was partitioned before. Note also that both drives were 255 heads and 63 sectors/track. That is important, and provides confidence that the cloning will work.


    Then, in the same terminal / konsole (with root permissions) type:
    dd if=/dev/hda of=/dev/hdb bs=32256 conv=sync,noerror
    BE VERY CAREFUL when typing that. If you get that wrong, you could erase your existing hard drive !! THAT LINE IS KEY TO THE CLONING. Note in this example, hda is the original hard drive, and hdb is the new hard drive. Dependent on how the live CD recognizes your drives, this may instead be different. For example if the old drive was sda and the new sdb, this could instead be:
    dd if=/dev/sda of=/dev/sdb bs=32256 conv=sync,noerror
    I have read that bs=32256 represents one complete track of 63 sectors, each with 512 bytes (I also read that omitting bs=32256 purportedly still works, but that would significantly slow down dd cloning).

    In the case of cloning a 40 GB drive, that could take about 2 hours for an old PC (time dependent on the PC age). There will be no messages during the cloning.


    Once the cloning is complete, switch OFF the PC, remove the old drive (40 GB drive in this example) and move the new drive (160GB in this example) to the same place on the cable as the old drive, and ensure that you change the jumpers on the new drive to make it the primary drive. This is important. Do NOT power on with new drive still setup as a slave.


    Then switch ON the PC. It should boot properly to Grub, which was cloned as part of the cloning process. In my example case, I selected to boot to openSUSE-10.2, and the PC booted properly to 10.2 (hda4). I then rebooted to winME (hda1) properly as a test. I then rebooted to winXP (hda2) as a test. WinXP gave an error the first time, and refused to boot properly. I'm told this is typical winXP behaviour when it notes a new drive ID in the place of the old drive. I then rebooted winXP (hda2) and on the second boot winXP booted properly and functioned properly.


    I then inserted the Parted Magic live CD (this would work just as well with the gparted live CD) and repartitioned the new hard drive. There are many ways to go from this point, but the purpose here by booting to Parted Magic is to expand the 160 GB drive (which is currently only using 40 GB) to use its full capacity.

    At this point, one is complete. (In my case, I "shelved" the old 40GB drive, and did not use it any more).


    If at this point you have problems, note your original old drive is still intact. Do NOT connect BOTH the old and the new drive at the same time. While that will be ok for Linux, it may cause MS-Windows partitions no end of problems if one boots to MS-Windows with both drives connected. Hence if the new drive fails to boot properly, one can simply stop the process at this point, remove the new hard drive, and put the old hard drive back in where it was, and one has not lost anything, except some time in the failed cloning effort.


    Also in my case I decided to go a step further to completely remove openSUSE-10.2 and replace it with openSUSE-11.1, so I removed all partitions except for the hda1 (winME) and hda2 (winXP). By doing that the drive would no longer boot, as the MBR had the old openSUSE-10.2 grub pointing to /hda4 (where the boot files on /hda4 had been removed by me). With parted Magic I expanded the /hda2 NTFS partition to be larger (for winXP), I created a new /hda3 (fat32 data partition) and created a new /hda4 extended partition where upon I created an hda5 swap partition, a hda6 / (root) partition area and a hda7 /home partition area for an openSUSE-11.1 install. I then rebooted from the Parted Magic live CD to the openSUSE-11.1 live CD, and during the openSUSE-11.1 live CD install I was careful to ensure openSUSE-11.1 installed on the /hda5 (swap), /hda6 (root) and /hda7 /home, and careful to ensure openSUSE-11.1 placed grub on the MBR (it was not going to do this by default, and I had to edit the install configuration).

    The openSUSE-11.1 was successful, and after a successful openSUSE-11.1 install, the new grub then gave me the choice upon booting to go to winME, winXP, openSUSE-11.1 or openSUSE-11.1 safe.

    Overall, the operation ran quite smooth.

    For the example I gave above, the following is the thread where I sought help from our forum experts for conducing the cloning operation: Looking for new hard drive advice - openSUSE Forums


    Again, please post any corrections and/or corrections on the corresponding "un-reviewed" how-to thread: Cloning an old drive to a new drive - openSUSE Forums I ask users with comments stick to the technical on that thread. One valid observation (but not a concern) in that thread is when cloning, drive bit pattern imperfections (such as fragmentation) are cloned. However after cloning, imperfections such as fragmentation, can be addressed after the cloning, as they can before the cloning.
    Last edited by oldcpu; 31-Oct-2010 at 15:47. Reason: Added note to possibly edit /boot/grub/

  2. #2
    Join Date
    Mar 2008
    Phuket, Thailand
    Blog Entries

    Default Re: Cloning an old drive to a new drive

    Change History:

    This change history is on a separate post, because the maximum number of characters have been reached in the initial post.

    Edit-1: 5-Feb-09 - added additional comments based on 5-Feb-09 discussions in comment thread
    Edit-2: 6-Feb-09 - added additional comment about possibility of bad sector on new drive causing a fail
    Edit-3: 13-Feb-09 - added caution about cloning Linux PC that has disk-by-id mounting in /etc/fstab and added caution about stopping if cloning fails.
    Edit-4: 14-Feb-09 - added simplistic description on how to modify fstab prior to cloning
    Edit-5: 15-Feb-09 - replaced "dd if=/dev/sda of=/dev/sdb bs=32256" with "dd if=/dev/sda of=/dev/sdb bs=32256 conv=sync,noerror" per Cloning an old drive to a new drive - Page 2 - openSUSE Forums - post #58 . Also moved change history to a separate reply post.
    Edit-6: 19-Oct-09 - added comment to also edit /boot/grub/menu.lst to remove specific device-by-id entries (and make more generic) in that file.
    Edit-7: 20-Oct-10 - cleaned up reference to backup/comment thread.
    Edit-8: 1-Nov-10 - fixed some spelling errors and added a comment to possibly also edit /boot/grub/ file to remove specific device-by-id-entries (and make more generic) in that file.
    Last edited by oldcpu; 31-Oct-2010 at 15:48.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts