Page 1 of 4 123 ... LastLast
Results 1 to 10 of 33

Thread: Cloning an old drive to a new drive

  1. #1
    Join Date
    Mar 2008
    Location
    Phuket, Thailand
    Posts
    26,569
    Blog Entries
    38

    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.

    Edit: The reviewed how-to has been copied to here:
    Cloning an old drive to a new drive - openSUSE Forums
    any/all future edits will be made on the Linked how-to, and not on this post. This thread is being maintained for comments, suggestions, and discussion of corrections for the "reviewed" how-to.

    OVERVIEW:

    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).

    RESEARCH:

    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.

    BACKUP FIRST

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

    CONNECT BOTH OLD AND NEW DRIVE

    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.

    CLONE

    Then, in the same terminal / konsole (with root permissions) type:
    dd if=/dev/hda of=/dev/hdb bs=32256
    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. Dependant 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
    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 dependant on the PC age). There will be no messages during the cloning.

    PREPARE FOR FIRST BOOT

    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.

    FIRST BOOT

    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.

    RECLAIM FULL SPACE OF NEW DRIVE

    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).

    EXAMPLE OF ADDITIONAL THINGS

    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
    Last edited by oldcpu; 06-Feb-2009 at 01:39. Reason: Added reference to reviewed how to

  2. #2
    Join Date
    Oct 2008
    Location
    Birmingham. AL
    Posts
    858

    Default Re: Cloning an old drive to a new drive

    Good stuff.

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Cloning an old drive to a new drive

    Well done oldcpu. I see the OpenSUSE world is benefiting from your filial IT support.

  4. #4
    Join Date
    Aug 2008
    Location
    Brazil
    Posts
    2,937

    Default Re: Cloning an old drive to a new drive

    I understand that for drives of different geometry it is possible to clone by partition, for example,dd if=/dev/hda1 of=/dev/hdb3. This will copy partition hda1 to partition hdb3.

    Pros: After copy you can resize the new partition before copying the next one, if any. This may be very desirable, as after a full drive dump (copy) you're only be able to resize the last partition.

    Cons: The boot sector(s) is(are) not copied, it has to be done manually. dd can be used for this, or another partitioner. Also grub or lilo may have to be edited if partitions are copied out of order, as in the example above.

  5. #5
    Join Date
    Mar 2008
    Location
    Phuket, Thailand
    Posts
    26,569
    Blog Entries
    38

    Default Re: Cloning an old drive to a new drive

    Further to my above post, ... to say that I did a large amount of research into dd before applying it for a specific purpose of cloning a "healthy" 40 GByte drive image on to a new "healthy" 160 GB drive, would be an understatement. I did a LOT of research.

    For those users who wish to follow any debate that may follow on this thread, and I think such a debate would be VERY HEALTHY, then I recommend users first bring themselves up to speed technically. By being up to speed technically, it will make any technical debate much more useful in coming to the truth as to the utility of the how-to.

    I recommend a good place to start is to read this very large thread quoted here, from start to finish:
    How to migrate XP, Vista, Linux, BSD and Solaris to a bigger hard disk - JustLinux Forums

    And finally a plea to all. No insults. Just the specific technical facts, without generalisations. I am "guilty" of complaining about FUD, although if one reads the thread I quote, and then read also this initial thread Looking for new hard drive advice - openSUSE Forums about the warnings I got saying it would never work (until I examined each one in detail, and figured out why the warnings were not applicable if things were done properly) then one might understand why I say there is a lot of FUD.

  6. #6

    Default Re: Cloning an old drive to a new drive

    As I have been quoted. In the thread, the guy with the flakey disk wants to go from XFS to ext3, and dd does not provide a convenient interface to copy files. Cloning also will not result in the cleanest disk layout, whereas filling a newly built filesystem would.


    That said, there's nothing wrong with cloning a drive. It's a perfectly reasonable and efficient technique, if you understand the PC Partitioning concepts.

    The point I would make about the HOWTO is that disk geometry & track sizes are not very relevant and that personally, I'd use some small multiple of 4KiB block sizes eg) 32768 last time I did some tests, large blocks didn't improve performance.

  7. #7

    Default Re: Cloning an old drive to a new drive

    That makes me wonder about the whole importance of the original point.

  8. #8

    Default Re: Cloning an old drive to a new drive

    An LBA disk is just effectively a big array of blocks, with no guarantee about geometry.

    A Linux block device, gets cached by the OS, unless you take special steps to use a raw device.


    So, when you copy... I think we are just doing a serial read on a very big file. readadhead should kick in and read the old drive as fast as poss. The output drive is larger, and very likely faster, so most likely we are limitted by read speed, with Linux doing a whole load of buffering in the block cache.

    Doesn't this defeat any attempt to do a track by track copy? The OS and drive electronics, should effectively do the same (even drives have large buffers these days).

    If this is right, do we gain anything by talking about geometry? Isn't the main thing that after cloning, you need to find & use the unused space?

  9. #9
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Cloning an old drive to a new drive

    In fact in modern drives, the track, head, and sector numbers used to interface to the OS in CHS addressing are just fictions that are materialised by the onboard controller. Internally CHS will map to however the controller wants it. There are in fact spare sectors that are automatically mapped in when the controller detects a bad block (with attendent cost in seeking to it). That's why CHS has no correspondence to geometric reality these days and LBA is the easier way to address a block.

    I can only think of floppies and DVD-RAMs where there tracks and sectors have geometric reality. DVDs and CDs just have one long spiral track.

  10. #10

    Default Re: Cloning an old drive to a new drive

    On the new drive possibly having bad sectors it would be possible to suggest using badblocks(8) as an optional procedure to aid reliability.

    That's not going to be enough for a critical system though. Suitable 'burn in' tests belong to a different HOWTO though.

    We could suggest mounting the clone partitions under /mnt, and using rsync -nca to verify the copy.

Page 1 of 4 123 ... LastLast

Posting Permissions

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