How to clone entire hard-disk into new one?

18,822

Solution 1

This problem was created by an incorrect dd command. Accurate dd command for disk cloning is:

dd if=/dev/sda of=/dev/sdb

sda and sdb point to the hard-disks themselves, which includes the partition table as well. if= points to the input file (in this case, /dev/sda), and of= points to the output file (/dev/sdb).

dd command is time consuming but it is more trusted and also default system tool so I gave priority to dd.

enter image description here

After successful operation, the next step is to restart the system, then your new hard-disk will look like this:

enter image description here

Here is the second last step, that is also required after dd: Use Gparted utility to resize the extended partition. The old hard-disk partition table was Legacy boot type and did not support more than 4 primary partitions. Therefore, resizing is the only safe option to use 500GB free-space.

After resizing the extended partition:

enter image description here

Solution 2

Recently I've had to use dd for recovery and image work. I used it intensively some 10 years back for cloning drives and backing up partitions. I must say that it's use is light-years away from direct and simple. With respect to HDDs, you need to know exactly how the drive is structured at the lowest level. For this you need other programs that you can trust (fdisk, sfdisk, cfdisk, etc.) Trust only comes from experimentation with known objects and examining the results -- not from word of mouth. I'm in agreement with muru's initial comment about wrong dd command, but more should be said. if=/dev/sda starts reading at the very beginning of the device (byte address 0) while of=/dev/sdb1 writes to the first partition of device b. The result is that your sda-MBR resides at sdb-part1, along with your OS, etc., and I don't know what will happen when it gets to the end of sdb1, if it's larger than sdb1.

I'm guessing that sda is the boot device and you want sdb to also be your boot device, but maybe you just want sdb1 to be a backup clone. Your question is vague about this. You might be able to copy partition to partition if they are exactly the same size but maybe the OS has meta-data about the partition filesystem that doesn't match, so it can't 'view' it. If you just want a clone for backup then maybe your command is ok, but there are issues about reaching the end of the partition and over-writing the next partition, and whether your OS will object to the filesystem destruction on sdb1 (booting still from sda1(?)). In principal, such might work, but it's probably better to write sda to sdb only and forget about booting from sdb, it's just a clone for reading. You could probably write to file if you had extFAT or some system that accepted 500GB file sizes, but I doubt that you do.

There are dozens of other questions as well. If you wanted to transfer to sdb and later boot from it, you must know the bytes and sectors to copy and include that in your command -- making sure your output drive has the size necessary, again /dev/sda to /dev/sdb should work except for some problems that I've encountered. Namely, what should dd do if it encounters a read error that is common on older used drives? You can set dd to ignore them but what then does it write? In my experience, it writes nothing, thus that 512 bytes (normal traditional block, but your disk might be different; newer drives may use 4096 byte blocks) is taken out of the write and all further bytes are shifted 'to the left' of where they should be. This happens for each read error that maybe you've optioned to ignore because a read error stops dd cold and a restart is painfully hard. In short, dd for cloning can be done, but it should be done in a bash script with an error recovery loop that fills unread blocks with nulls, the command should specify exact block counts, and you should know exactly the low-level format of the drives involved. In the end, it's probably best for serious cloning to use a dedicated open source c executable that does what dd and sfdisk do but more professionally. But, I'll admit that dd is useful. It's like a Bowie knife on your belt -- impressive and powerful, but with limited usefulness.

Also, OSs can check for UUIDs stored in free space and other places on HDD and can object to booting if they don't match. This is one of the black art areas of OS competitiveness. Official software knows these things.)

GPT tables are also important, even essential these days, unlike 10 years ago. And EFI boot partitions complicate things too. With the little I know about low-level disk formatting, I won't even waste my time trying to clone a whole disk. Parts of the disk might be useful for very special problems. Ignoring LVM and its significance, a partition might usefully be cloned but only for reading back to the original drive (no OS mixing, boot changes, etc.) To transfer a bootable 500GB drive to make a 1TB bootable system, assuming the OS doesn't object to a different drive (hardware signatures?), then my suggestion for a successful experiment would be to make the low-level formatting on the 1TB drive exactly like the 500GB drive -- I mean exactly! You must examine the MBR and GPT tables with a hex editor. Then dd the partitions byte-for-byte to the new drive. Then, boot-up the 1TB drive (assuming success) and make another partition in the new 500GB of additional space, or expand the partition and live filesystem, if you have and trust such software. Trust in this realm is hard to find because this stuff is difficult and disastrous if gotten wrong. Better to buy a new system or software with a great reputation and SHA256SUMed so you can check its integrity. Digital systems are by nature volatile and impermanent, so best to get used to change, if you need more than what you have.

Share:
18,822

Related videos on Youtube

Madhav Nikam
Author by

Madhav Nikam

I like to improve new thoughts, Technics, and philosophy. Love to computer, mathematics and nature. Agriculture is my soul, math is my mind, computer is my heart and knowledge is my breath. I think breathing of knowledge is very importance to make us alive.

Updated on September 18, 2022

Comments

  • Madhav Nikam
    Madhav Nikam over 1 year

    I was use dd command to copy my 500GB hard-disk into my new 1TB hard disk. After 9 hours system display message everything was successfully copied but I can't display any data into my new hard disk.
    I go through following steps.
    step1:-

    enter image description here

    After that system disply message :- step2:-enter image description here
    but now 1 TB HDD can't display anything. enter image description here
    How to solve that issue?

    • muru
      muru about 8 years
      Try restarting. Sometimes the kernel's partition information isn't correctly updated.
    • Madhav Nikam
      Madhav Nikam about 8 years
      @muru how to do this?
    • muru
      muru about 8 years
      You don't know how to restart your system? O.o
    • Severus Tux
      Severus Tux about 8 years
      If you want to copy the files, you can use rsync or cp instead od dd
    • Madhav Nikam
      Madhav Nikam about 8 years
      @muru I restart my system but harddisk display freespace
    • Madhav Nikam
      Madhav Nikam about 8 years
      @SeverusTux I want exact clone.
    • muru
      muru about 8 years
      OH, now I see. You wrote to /dev/sdb1. You should have dd'd to /dev/sdb.
    • MKay
      MKay about 8 years
      Let's try Clonezilla! I usually copy my entire ssd with it on an external hdd for backup purpose, it works pretty good and it's quite fast.
    • Madhav Nikam
      Madhav Nikam about 8 years
      @MKay thanks! Is it any idea to avoid re-copy process? And clonezilla have any repair tool for it?
    • MKay
      MKay about 8 years
      No idea, I'm sorry, and I don't think that Clonezilla have any repair tool inside, it's crafted to litterally clone partitions. Just yesterday I have cloned 250GB ssd in no more than half an hour. Considering that you're trying to copy an hdd of 500GB that is a little bit slower, you may need more time, but I don'think you'll need more than 2/3 hours.
    • Madhav Nikam
      Madhav Nikam about 8 years
      @MKay ok. now I can try clonezilla.
    • muru
      muru about 8 years
      @MadhavNikam Use bs parameter with dd. Something like bs=10M may considerably speed up the process.
    • Madhav Nikam
      Madhav Nikam about 8 years
      @muru dd if=/dev/sda of=/dev/sdc bs=10M its ok?
    • muru
      muru about 8 years
      @MadhavNikam that should be fine. I suggest you run a few trials with varying bs values for about a minute each, and pick the fastest value. It really shouldn't be taking 9 hours.
    • Madhav Nikam
      Madhav Nikam about 8 years
      @muru if its take more time, I don't have problem; but i want exact clone and after that free space for remaining 500GB. I still doubt about free space after dd success.
  • vanadium
    vanadium over 5 years
    Please clarify the procedure, i.e., explaining what and why you do things as you propose.
  • aldo
    aldo over 4 years
    used this procedure to enlarge a virtual drive of a linux virtual machine. the same procedure can be applied to a real disk, so it fit the original question