Want to create a disk image of a system but write it on another hard disk? This can easily be done with the help of netcat and dd.
For this example you will need two computers connected on the same network, and enough room on one machine to hold your disk image
Destination Machine
So we’ll start off this example by preparing our destination machine to listen on tcp port 4444 via netcat. The port is arbitrary so you can really pick any port that is not being used. Just have to make sure that its the same on both ends.
So we’ll start off this example by preparing our destination machine to listen on tcp port 4444 via netcat. The port is arbitrary so you can really pick any port that is not being used. Just have to make sure that its the same on both ends.
root@tree:~# netcat -l -p 4444 | dd of=remote-machine.img
Source Machine
Next we’ll start a dd on the source machine and pipe it to netcat on port 4444
Next we’ll start a dd on the source machine and pipe it to netcat on port 4444
root@leaf:~# dd if=/dev/sda1 | netcat destination-machine-ip 4444Now sit back and wait for your image to be done, when it’s finished dd will print out its status something like
NOTE: you will have to push CTRL+C to cancel out after this is completed, as the netcat session will still be active.
root@leaf:~#
30820468+71926 records in
30867456+0 records out
15804137472 bytes (16 GB) copied, 739.395 s, 21.4 MB/s
^C
If you want to find out the status of dd during the copy theres a couple of ways to do this, open up the system monitor in Ubuntu Linux, and it should tell you the transfer rate. Launch iostat or ifstat through a terminal. Invoke a command from terminal to get dd to display the current progress .
Viola, we’ll now have a dd image of our disk or partition. I like to verify the exact size of the file matches the size output from fdisk.
Viola, we’ll now have a dd image of our disk or partition. I like to verify the exact size of the file matches the size output from fdisk.
Destination Machine
root@root:~# ls -la remote-machine.imgSource Machine
-rw-r--r-- 1 root root 15804137472 2010-02-04 10:53 remote-machine.img
root@leaf:~# fdisk -l /dev/sda
Disk /dev/sda: 15.8 GB, 15804137472 bytes
255 heads, 63 sectors/track, 1921 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes