Linux Tips and Tricks

A collection of tips, tricks and everything linux

Archive for the ‘dd’ tag

Disk imaging with netcat and dd with ubuntu linux

with 3 comments

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.

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

root@leaf:~# dd if=/dev/sda1 | netcat destination-machine-ip 4444

Now 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.

Destination Machine

root@root:~# ls -la remote-machine.img
-rw-r--r-- 1 root root 15804137472 2010-02-04 10:53 remote-machine.img

Source Machine

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

Written by mnk0

February 4th, 2010 at 12:29 pm

Posted in Linux, Ubuntu, shell

Tagged with , , ,

Display dd progress during dd in ubuntu linux

with 2 comments

Started a dd but wondering what the progress is? I haven’t found a way to do a verbose mode for dd, but this command seems to do the trick.

Lets start off by creating a dd of /dev/sda1

mnk0@tree:~# dd if=/dev/sda1 of=my-dd.img

We’ll need to find the process number of our dd which can easily be done with the following command.

ps -ef | grep dd

we’ll get something like this

root 31733 31268 54 10:44 pts/0 00:01:55 dd of my-dd.img

Now we can run our command to find the status of this dd. Open another terminal session.

kill -SIGUSR1 31733

and looking back at our dd page we should see dd dump out a status of its current progress.

mnk0@tree:~# dd if=/dev/sda1 of=my-dd.img
12574781+40555 records in
12601304+0 records out
6451867648 bytes (6.5 GB) copied, 224.634 s, 28.7 MB/s

Written by mnk0

February 4th, 2010 at 11:45 am

Posted in Linux, Ubuntu, shell

Tagged with , ,