I have two hard disks with the same sizes – represented as /dev/sda and /dev/sdb. I am trying to copy /dev/sda on /dev/sdb. /dev/sda has one ext3 partition. /dev/sda and /dev/sdb have the same partition layout.
What I do is use the following command:
dd if=/dev/sda of=/dev/sdb
When I mount the file system on /dev/sdb I see that not all of the changes are reflected on the device. In other words the disks are not the same. So it fails. And I don't seem to figure out why. Can this corrupt the partition table on /dev/sdb. Is this the proper way to clone a disk?
Well, I don't unmount the file system on /dev/sda before I start cloning it. But I am absolutely sure that nobody is writing on it while the cloning is executing.
Best Answer
In order to clone a disk, you absolutely should unmount all partitions. All modern desktop OS' have many services running in the background that write to the OS partition, and may also periodically write to other mounted partitions (even those on other disks) for whatever reason. The writes may be small and few, but any writes -- especially those involving filesystem metadata -- will wreck havoc with your cloning.
Typically one clones entire drives by booting a Linux Live CD/DVD/USB Key (pick any distribution you like, I prefer Mint for this kind of thing). This way your hard drives can remain unmounted.
The command you've got there will work fine, but as it stands, if a sector can't be read for any reason,
dd
will stop. You may want that behavior, or you may want it to continue... up to you. Arch has excellent documentation on disk cloning and they recommend something like this:But read the documentation, especially around adjusting
bs
to higher values, as that can have a significant impact on cloning speed. If you wantdd
to stop if it encounters an error, remove theconv=noerror,sync
part.