There may be some scenarios when installing an additional hard drive to clone an existing one is not possible: lack of data or power ports, no physical space, etc. Using several command line (CLI) tools in Linux it is still possible to efficiently create a full low level clone of a hard drive on another machine over a wired network connection.

Requirements

The following are required to successfully complete the task

  • two separate machines
  • destination hard drive must be equal or larger in size than source hard drive
  • two machines must be physically connected via a LAN connection, other methods may theoretically work but do not guarantee data integrity and speed
  • basic knowledge of Linux command line
  • root or sudo

Command line tools used:

  • fdisk - disk partitioning and info tool
  • dd - convert and copy tool
  • pv - see the progress of data through a pipeline
  • gzip - compression tool
  • nc - netcat,arbitrary TCP and UDP connections and listens

Source Machine Setup

On the CLI find out the device path of the source disk:

fdisk -l

Correlate the source disk parameters in the output to its device path and take a note of it. It's needed later.

In this example, we're using /dev/sda

dd bs=1000M conv=notrunc if=/dev/sda | gzip -3 | pv | nc 192.168.10.190 19000

Command details:

dd:

  • bs=1000M - input block size copied to the output as a single block without any aggregation of short blocks
  • conv=notrunc - this will preserve any blocks in the output file not explicitly written by dd
  • if=/dev/sda - input source, in this case a drive with device path of /dev/sda

gzip:

  • -3 - 1 is fast, 9 is best, 3 is ok enough to impact the amount of data transfered without performance penalty

nc:

  • 192.168.0.101 - IP address of the destination machine
  • 19000 - destination machine port

Destination Machine Setup

On the CLI find out the device path of the destination disk:

fdisk -l

Correlate the destination disk parameters in the output to its device path and take a note of it. It's needed later.

In this example, we're using /dev/sda

DESTINATION:

nc -l -p 19000 | pv | gzip -d | dd bs=1000M conv=notrunc of=/dev/sdb

Command details:

nc:

  • -l -p 19000 - listen for an incoming connection on port 19000

gzip:

  • -d - decompress

dd:

  • bs=1000M - input block size copied to the output as a single block without any aggregation of short blocks
  • conv=notrunc - this will preserve any blocks in the output file not explicitly written by dd
  • of=/dev/sdb - output device, in this case a drive with device path of /dev/sdb

Bonus:

Find out dd operation progress.

Linux:

kill -USR1 $(pgrep ^dd)

OS X:

kill -INFO $(pgrep ^dd)

Published

Category

Linux

Tags

Contact