🌑

Linhost.info

Copy and Restore a Drive with Dc3dd, Gzip and a Network Share

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:

  1. Unlike dd, Dc3dd comes with a progress indicator
  2. With Gigabit links OpenSSH appears to become the bottleneck, even when resources are available network throughput is low

Keep in mind

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.

Prepare

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:

  1. mount.cifs //192.168.1.8/072012/ - This is the network share IP address and share name
  2. /media/netshare/ - This is the mount point we created with mkdir.
  3. -o user=tempuser,password=tempuser - This is the username and password for the network share

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

Copy

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

  1. dc3dd if=/dev/sda - Dc3dd will work with drive /dev/sda
  2. progress=on - Dc3dd will display the progress
  3. gzip -1 > - Gzip will be used for compression, -1 means fast compression
  4. /media/netshare/sda.img.gz - This is the network share path

My network share is in a Windows Server 2003 and as you can see the image was successfully created and compressed.

Restore

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

Conclusion

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.

, , — Jul 21, 2012