dd and netcat - like peanut butter and jelly

You can dd a device to another device, a file to a device, or a device to a file. But it’s really all just file’s since character devices are just files too. You probably already know how to “double buffer” your dd’s by piping dd with an input to dd with an output, but you can make it a party with by inviting netcat and gzip! Aren’t pipes great? Just make sure you’re writing from a disk that’s the same size or larger than the target. Unless you don’t mind broken partitions that you’ll have to fix manually with a live dvd and parted or some other utility.

Use dd over a network connection to copy one file or disk to another, like magic! wow i like magic!

Start listening on the target machine:

# nc -l 1234 | dd of=/dev/sda

Start reading the disk and pipe it to netcat:

# dd if=/dev/sda | nc rootninja.com 1234

You can reduce bandwidth by compressing the stream of data between both dd’s.

On the target - start netcat listening on a port, pipe it to gzip with stdout, decompress, and force flags, and pipe that to dd with an output:

# nc -l 1234 | gzip –cdf | dd of=/dev/sda

On the source - start dd with an input, pipe it to gzip with stdout and force flags, and pipe that to netcat with a host and port:

# dd if=/dev/hda | gzip -cf | nc rootninja.com 1234

You don’t have to write directly to another device. You can use this method to store images on a remote machine. DIY backups?! zomglolbbq!!! kaboom!!!

netcat uses TCP by default, which is good, so if you get errors on the target (but it didn’t just fail completely), then it’s probably from dd. It either hiccuped reading or writing. However, to this very day, i’ve never had a…… i’m not going to say it, I’ll just jinx myself!

Posted by admica   @   29 September 2009
Tags : , , , , , , ,

Related Posts

1 Comments

Comments
Sep 30, 2009
2:16 am
#1 Clemento :

I really like your blog and i respect your work. I’ll be a frequent visitor.

Leave a Comment

Name

Email

Website

Previous Post
« Fuel Injector Spray Timing for Reduced Hydrocarbon Emissions and Higher BSFC
Next Post
Do you organize your internal DNS to allow for future expansion? »
Powered by Wordpress   |   Lunated designed by ZenVerse