Suppose you want to make a hard drive image of some particular
computer and send that image over the network to another computer.
How do you do this in GNU/Linux? Surely, the easiest way to make disk
images is through the dd
command, but the destination of a dd
command must be a file, correct? Incorrect. Actually, the dd
command in its default mode reads from standard input and writes to
standard output. If you don’t specify an input or output file, the
defaults will be used. So, you can rest assured that it is easy to
route the output or input from dd
to network streaming commands.
Matter of fact, perhaps the easiest way to use dd
to send and
receive disk images over the network is with this nifty trick
involving netcat
(a.k.a. nc
). Insert some bzip2
commands into
the chain to compress before sending across the network and you’ve got
yourself a pretty good system.
First, on the receiver, type the following commands. You can set the output to either a file, a physical partition, or a physical drive. If you are storing the image to a file, you may want to skip decompression and start by just storing the compressed disk image.
# Before `netcat' version 1.84-10
nc -p 2222 -l | bzip2 -cd | dd bs=16M of=/dev/sdb
# `netcat' version 1.84-10 and later
nc -l 2222 | bzip2 -cd | dd bs=16M of=/dev/sdb