8

I need to clone one laptop's drive to another one which is basically the same built.

They are M.2 PCIe drives so even if I wanted to open the laptops I can't currently find USB connectors for them.

So I would need then to image the source to an external drive and then play that image back on the new computer.

Doing that for almost a Terabyte of data does take quite some time - and I have to find room for the image as well.

How can I clone the source laptop to the target laptop over the network without creating an intermediate copy of the image? I can boot to USB on both laptops.

I say Reinstate Monica
  • 25,487
  • 19
  • 95
  • 131
Mark Canada
  • 81
  • 1
  • 1
  • 2

2 Answers2

9

No need to find storage for the image - just load up a Linux Live CD (or USB stick), and use netcat.

On the computer that is setup and ready to go, run:

sudo dd if=${SOURCE_DISK} bs=4M | gzip | nc -l 27015

Then, on the computer that will recieve the image and become a clone, run the following... (I feel I should note the obligatory this will destroy all data)

nc ${IP_OF_SERVER} 27015 | gzip -d | sudo dd of=${DEST_DISK} bs=4M

Here, ${SOURCE_DISK} and ${DEST_DISK} need to be swapped for the relevant disks - e.g: /dev/sda or /dev/nvme0n1.

Additionally, ${IP_OF_SERVER} needs to be replaced with the IP of the first computer.

This will transfer the data directly between the two M.2 drives.


For bonus points, you could replace the source dd with pv to keep an eye on progress... or send a SIGUSR1 to the dd instance for an update.


Notes:

  • This doesn't cover any modifications that you may need to make to the (unspecified) OS... Windows might get picky about activation, and Linux might get nostalgic about things like network interfaces...
  • This basic approach isn't suitable if your target SSD is smaller than the source.
  • If you're only interested in particular partitions, then check the sizes, and use a suffix of p1 / p2 / etc... on the device names.
Attie
  • 19,231
  • 5
  • 58
  • 73
  • Thanks. Really...dd can copy a whole partition, not just files? That's quite interesting. Copying Windows 10 but other than the hard drive (new one is bigger) they are the same config - so Windows activation hopefully shouldn't be an issue if it doesn't read too many part IDs...wonder if UEFI will create issues now that you mention issues... – Mark Canada Dec 25 '17 at 00:28
  • Absolutely - in this scenario `dd` will copy the whole file table, inculding file contents and metadata (e.g: permissions). You will end up with "*identical*" disks. – Attie Dec 25 '17 at 19:23
  • There is an even easier version of this solution which would be to use ssh to pipe the output - ie from the client : ssh root@server "gzip < /dev/sdX " | gunzip | pv > /dev/sdX – davidgo Dec 26 '17 at 01:18
  • Indeed, though: A) this requires root over SSH (not typically enabled by default), B) specifying both block devices on one line opens up for mistakes and confusion, and C) `pv` no longer gives you progress - just rate and total transferred – Attie Dec 27 '17 at 18:11
  • Also, you might not need to encrypt and then decrypt the data when on a secure network, or when the disk is already encrypted. – Cigarette Smoking Man May 06 '23 at 21:15
1

For gnu netcat there is a "-p" missing in the "server" line

sudo dd if=${SOURCE_DISK} bs=4M | gzip | nc -l -p 27015

For GNU netcat you will have to use the -p option to determine the local listening port. This might be important, when you use the SysRescue CD.

gorgooger
  • 11
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 29 '22 at 10:45
  • You should explain what -p is for. – Rohit Gupta Aug 29 '22 at 11:07