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.

  • Actually, what you can be sure of is tht someone is wirting on /dev/sda, not viceversa. Linux has a zillion services logging all sorts of real-time info which are not under your control, and which you should leave well nigh alone. The proper way to clone the disk is the one you are using, but with both disks unmounted. Your current operation is also dangerous for /dev/sda. You ought to read this Arch Linux Wiki page, wiki.archlinux.org/index.php/Disk_cloning#Create_disk_image, where it says: Make sure no partitions are mounted from the source hard drive. – MariusMatutiae Nov 6 '15 at 7:21
  • @MariusMatutiae why it is dangerous to /dev/sda? – ilkhd Nov 6 '15 at 9:47
  • Because inode info may change after dd has copied the indoe, leaving the info in inode obsolete, parts of a file unaccounted for, and so on. – MariusMatutiae Nov 6 '15 at 10:10
  • @MariusMatutiae dd does not lock the file while reading, or I am wrong? – ilkhd Nov 6 '15 at 19:08

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:

# dd if=/dev/sdX of=/dev/sdY bs=512 conv=noerror,sync

But read the documentation, especially around adjusting bs to higher values, as that can have a significant impact on cloning speed. If you want dd to stop if it encounters an error, remove the conv=noerror,sync part.

  • misha256 thank you for your answer. By the way I have also used fsfreeze -f /directory_name to freeze the filesystem while the cloning is ongoing but it also fails. – nikozavar Nov 6 '15 at 8:05
  • @nikozavar No worries. Hmm, fsfreeze looks interesting, must look into that. Somehow I don't think fsfreeze can (or was designed to) work on the root partition of a running OS, but I could be wrong. – misha256 Nov 6 '15 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.