Cloning a drive from one machine to another - eviltoast

You can clone a drive from one machine to another using “dd” and netcat (nc)

Caveats:

  • The commands should be run a root

  • Data on the destination device will be overwritten, so double-check that you get the right one (maybe check with “lsblk” etc)

  • The drive on the destination machine must be at least as big as the source

  • The data on the source device should not changed while it is being cloned. Make sure it has no mounted partitions (it’s a good idea to boot from USB). Ditto the destination drive

  • The source machine must be able to reach the destination on the port specific (not blocked by firewall etc)

  • Data is sent unencrypted over the network, so make sure you get the right destination and your network is trustworthy/secure (you could so this over the internet - firewall rules permitting - but I wouldn’t recommend doing so with a drive containing sensitive data and it is going to eat up bandwidth/data-cap)

The process…

On the machine with the destination drive, run the following (where 11111 is a TCP port the machine will listen on, and /dev/sdd is the device that will be cloned to. Data will be sent in 1M blocks).

nc -l 11111 | dd of=/dev/sdd status=progress

This will begin listening for data on port 11111

On the machine with the source drive, run the following (where 192.168.1.2 is the IP address if the destination machine, /dev/sdb is the drive being cloned from, and 11111 is the port you used above)

dd if=/dev/sda status=progress bs=1M | nc 192.168.1.2 11111

You should see progress on both hosts as the drive from machine to the other