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

  • errorgap@lemmy.caOP
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    You can also use a file instead of a device if you want to write your image to/from a file

    Writing a compressed image at the destination

    nc -l 11111 | gzip > /path/to/backup.img.gz

    Reading a compressed image at the source and sending uncompressed data over the network (can be cloned directly over drive at the destination, within the original constraints). Please note this will not show a progress status at the source:

    zcat /path/to/backup.img.gz | nc 192.168.1.2 11111

    Or you could just send the compressed-image data over the network and decompress at the destination (as per the second example}:

    dd if=/path/to/backup.img.gz status=progress bs=1M | nc 192.168.1.2 11111

      • errorgap@lemmy.caOP
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        I’ve never used that particular software so I couldn’t say. Unless you’re sending over the internet this method should be fairly safe though