Aerospace



Home

Company Information

Information Request

Linux How-to Guides

ADSP 21xx
Digital Signal Processing
Tutorials

SW Utilities

On-line Order Form

Aerospace Projects

Commercial Projects

Circuit Boards

Server Support


Bonk

Have you found this site useful? Did we save you time? Did we cure your head-ache? Is your hair growing back now?

Please make a donation to help with maintenance.


Netcat Disk Duplicate How-to Guide

For Mandriva Linux 2006


Scope

This guide shows how to save an image of a disk drive on a server.

The ultimate snapshot, is a binary disk image, which you can make using dd (disk duplicate) and nc (netcat). This is good for saving a backup of a Windoze PC, before the user has a chance to infest it with junkware, after which you can easily fix it again.

You can also use dd and netcat to copy all data from a smaller to a larger disk drive, then use diskdrake to add the additional space to the existing partition - or make a new partition of the extra space. This way you can upgrade a notebook from a 30GB disk to a 60GB disk for example, without having to re-install everything. You can let it rip and go watch a ball game, instead of having to spend the afternoon re-installing all your schtuff.


Network Test

Here is a neat network test method using netcat:

On the server:
$ echo Hello | nc -l -p 5000

On the client:
$ echo Aloha | nc server.ip.add.ress 5000

Whatever you type on the keyboard of one terminal will be echoed on the other terminal.


Save Image

To save a backup image on a server:

On the server:

# nc -l -p 50000 | dd of=pc.img

On the PC:

# dd if=/dev/hda | nc servername 50000

Restore Image

To retrieve a backup image from a server:

On the PC:

# nc -l -p 50000 | dd of=/dev/hda

On the server:

# dd if=pc.img | nc pc.ip.addr.ess 50000

Speedups

If you are impatient (and who isn't?), then make the dd block size bigger, with the 'bs=1M' parameter. It will speed things up a bit - or at least, it will make you believe that it speeded it up a bit...

Sending 30GB of zeroes accross a 100MBps network can take a long, long time. Therefore, it is a good idea to compress the data before sending it with netcat, since most of the hard disk is usually empty. Remember to unzip it before writing it back. This will make a huge improvement in the backup time.

Save image

On the server:

# nc -l -p 50000 | dd bs=1M of=pc.img

On the PC:

# dd bs=1M if=/dev/hda | gzip -9 | nc servername 50000

Restore Image

On the PC:

# nc -l -p 50000 | gunzip |  dd bs=1M of=/dev/hda

On the server:

# dd bs=1M if=pc.img | nc pc.ip.addr.ess 50000

Because of the bs parameter, dd may not stop by itself. Eventually you will notice that things stopped, but dd is still running and netcat is still waiting. To stop it cleanly, press ctrl-C on the sending machine. The other side will then shut down too.


Notes

A Knoppix CD is good for this on the PC side, since it has nc and dd.

It is best to experiment with a second disk drive until you are confident. Do not overwrite the original disk drive until you are sure that the copy is good!

I also save an image *before* I repair a PC that is infested with spyware, since the repair tools sometimes render the PC unbootable. If I have an image, then I can restore it with all the crap and try again.

Note that the parameters of nc is a little inconsistent. You sometimes have to supply a -p before the port number and sometimes not - so save the above for future reference.

Also note that the image send may hang once done. You will get a message from dd on screen saying how many bytes were read/written but the program will not terminate and netcat will keep waiting for more data. Press Ctrl-C to quit at this point.

You can watch the progress of dd, by opening another console and sending it a signal using kill. First ps to get the numeric PID of dd:

ps | grep dd
kill -USR1 PID

Dd will then print a progress report on the first console and immediately carry on without interruption.


Using SSH as a Secure Transport

You could also use SSH instead of netcat, but the additional overhead of SSH will make things even slower, so use a fast cypher such as Blowfish. The neat thing with SSH, is that since the server is usually running by default already, you only need to type a command on the client side:

dd if=/dev/hda |gzip -9 |ssh -c blowfish username@domain.tld "dd
of=image.gz"

I think that instead of dd, you can also use cat, though I have never tried cat for low level disk I/O - try it for fun.

Slow, but secure...




Copyright © 2005-2008, Aerospace Software Ltd., GPL.