In the past I’ve written about combining dd, Gzip and OpenSSH to image a drive over a network, while the above works just fine there are better tools available that can improve the results or at least make it easier to clone a drive. By better I mean:
Before we start the tutorial I recommend using a one of the many available Live-CD distributions like Parted Magic or Deft Linux because they include all the tools I’ll be using in this post. This tutorial assumes a working network share is already available. The process for imaging a drive over a network revolves around five commands ls, Dc3dd, Gzip, Gunzip and mount.cifs.
Locate the drive you need to image, we can use the ls command to list all available drives and their respective partitions, decide whether you need to copy the partitions or the entire drive.
# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1
* /dev/sda and /dev/sda represent the actual drive, /dev/sda1/2 and /dev/sdb1 represent a partition within the drive. Create a mount point for the network share.
# mkdir /media/netshare
Mount the network share.
# mount.cifs //192.168.1.8/072012/ /media/netshare/ -o user=tempuser,password=tempuser
Change the following:
Verify that the network share mounted successfully.
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 2.0G 8.0K 2.0G 1% /media/usb
//192.168.1.8/072012/
80G 23G 58G 29% /media/netshare
Star imaging or cloning the drive, compress and direct the output to the network share mount point.
# dc3dd if=/dev/sda progress=on | gzip -1 > /media/netshare/sda.img.gz
warning: sector size not probed, assuming 512
dc3dd 6.12.3 started at 2012-07-21 07:11:13 +0000
command line: dc3dd if=/dev/sda progress=on
compiled options: DEFAULT_BLOCKSIZE=32768
sector size: 512 (assumed)
9830400+0 sectors in
9830400+0 sectors out
5033164800 bytes (4.7 G) copied (??%), 444.728 s, 11 M/s
dc3dd completed at 2012-07-21 07:18:39 +0000
My network share is in a Windows Server 2003 and as you can see the image was successfully created and compressed.
To restore the image we use Gunzip to decompress and Dc3dd to write the decompressed data over to the target disk. I recommend using the progress=on option when working with large images, its nice to have an idea of the progress being made.
# gunzip -c /media/netshare/sda.img.gz | dc3dd of=/dev/sda progress=on
warning: sector size not probed, assuming 512
dc3dd 6.12.3 started at 2012-07-21 22:55:04 +0000
command line: dc3dd of=/dev/sda
compiled options: DEFAULT_BLOCKSIZE=32768
sector size: 512 (assumed)
9830400+0 sectors in
9830400+0 sectors out
5033164800 bytes (4.7 G) copied (??%), 192.915 s, 25 M/s
dc3dd completed at 2012-07-21 22:58:19 +0000
This is my preferred method for imaging drives over the network because the tools required to copy and restore are easily found in most distributions. If you have any questions feel free comment below.
dc3dd, gzip, smb — Jul 21, 2012