23

I have a home machine running Windows 7, and I’m wondering if it would work to do a command like this:

dd if=/dev/${oldSataSpinningDisk} of=/dev/${newSSD}

To clone the contents of the current system running on a SATA HDD to a new SSD? mainly, would Windows 7 boot and actually work?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
dobbs
  • 353
  • 1
  • 2
  • 6
  • Two more resources to be considered: https://www.tecmint.com/clone-linux-partitions/ and https://cyberciti.biz/faq/unix-linux-dd-create-make-disk-image-commands – Cadoiz Jan 19 '21 at 05:34

3 Answers3

28

Yes, the idea is right, but the command is bad. If there is even one read error, the dd command will skip a byte which will cause the partitioning scheme to be faulty. You need to specify that every byte is copied to the same physical location (from the start).

dd if=/dev/oldsataspinningdisk of=/dev/newssd bs=64K conv=noerror,sync
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
cden
  • 380
  • 1
  • 3
  • 5
  • 1
    I've done this several times (never with an ssd, but I see no reason why that would be an issue) and it works great. Another issue is that your partition scheme stays the same, so if the hdd is larger, then you need to shrink down the partitions so that all of the partitions will fit on the ssd. To be clear, if your ssd is 1 terabyte and your hdd is 7 terabytes large but there is only 1 megabyte of information on it, then you'll still need to shrink the partitions on the hdd before doing this. When you're done, you're going to want to repartition the ssd so that there is no extra space. – cden Mar 10 '16 at 03:35
  • Thanks!! i'll give that a go soon. makes perfect sense. Any reason you recommend bs=64K and not something higher? seems like that would take like a week+ with a blocksize that big. – dobbs Mar 10 '16 at 03:55
  • How big is your harddrive? Last I did this was with about 500G using usb 2.0 and it took a couple of hours I think. I've always used 64K since that is what I was taught years ago (and what I wrote down in my notebook). I don't see why a larger blocksize would hurt and I also don't see why you would need to specify a blocksize at all for that matter. With that said, I think the worst case scenario is an ssd that won't boot up and a perfectly functional hdd, so you can decide if you want to experiment (barring anyone else chiming in). – cden Mar 10 '16 at 04:37
  • 12
    I would add "status=progress" to see what's going on while dd does its magic. – m4l490n Jul 28 '17 at 15:28
  • You should also add `iflag=fullblock` for error safety when you use these conventions. `iflag` is unfortunately not POSIX required, but it is [mentioned in the docs](https://www.gnu.org/software/coreutils/manual/html_node/dd-invocation.html) and [needed in case you should use the wrong bs/ibs](https://superuser.com/a/1075837/910769) – Cadoiz Jun 03 '21 at 09:28
16

Just to add up to the (perfectly fine) existing answers:

Why do you need a blocksize bs=64? While it is is probably not the fastest setting for all scenarios, it still runs way faster (around 4x) than the standard settings... this is true at least on my system - and seemingly many others out there. Tim Williscroft states that 100M could be faster, more research could be needed was done here, have a look.

Test data here: (I cancelled the first run because it took too long imho.)

$ sudo dd if=/dev/sdb4 of=/dev/sda2 status=progress
12962501120 bytes (13 GB, 12 GiB) copied, 394 s, 32,9 MB/s
$ sudo dd if=/dev/sdb4 of=/dev/sda2 status=progress bs=64K 
13143113728 bytes (13 GB, 12 GiB) copied, 98,0026 s, 134 MB/s 

More Hints and Ideas:

Nobody seems to know [...] dd is an asymmetrical copying program, meaning it will read first, then write, then back. You can pipe dd to itself and force it to perform the copy symmetrically, like this: dd if=/dev/sda | dd of=/dev/sdb. In my tests, running the command without the pipe gave me a throughput of ~112kb/s. With the pipe, I got ~235kb/s. I've never experienced any issues with this method. Good luck!

While he seems to misuse the the word symmetric in sense of meaning, this would probably also be worth a try. Additional information about this approach by groxxda: "If you do this and specify a blocksize, make sure you use the same blocksize on each invocation." (The respective post is also worth reading)

Cadoiz
  • 519
  • 3
  • 10
  • 3
    Full command with all the sparkles: `sudo dd if=/dev/sda3 of=/dev/nvme0n1p4 bs=64k conv=sync,noerror,notrunc iflag=fullblock status=progress ` – Cadoiz Sep 08 '22 at 12:12
2

I did it recently using plain vanilla:

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

Booted my laptop with ubuntu mate live usb.

For 1TB hdd it took ~6 hours @43mb/s, fired up my laptop with new SSD and everything (all windows and linux partitions) worked flawlessly.

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
Ajay Kumar
  • 131
  • 3
  • I don't get it because I did exactly as you did here, but when I try booting the resulting drive I get the error that my PC needs to be repaired with the specific `error code 0x000000f`. – Altimus Prime Jun 03 '22 at 03:37