Tips from an RHCE: How can I make dd give me a progress report?
by the editorial team
Contributed by Andrew C. Dingman
If you’ve been working with Linux very long, you’ve probably encountered dd, the deceptively simple utility for copying a stream of data from here to there. You may have used it to zero a disk before letting it leave the building, to benchmark io hardware by writing a certain number of bytes, to put a disk image on a floppy or usb drive, or even to back up an entire disk.
Like many commands, dd doesn’t generate much output as long as things are going well. This is great for scripting, but can be frustrating when you run it interactively. On large transfers, such as wiping or imaging a disk, it can be a total mystery how much longer you have to wait.
Also like many other commands, dd has some tricks up its sleeve that it will show off if it gets the right signal. In particular, dd will respond to the USR1 signal with a status report on TDERR. It is the same data you’d normally get at the very end of the transfer and will look something like this:
$ dd if=/dev/zero of=/tmp/demo bs=1M count=1536
33+0 records in
33+0 records out
34603008 bytes (35 MB) copied, 0.355191 seconds, 97.4 MB/s
So how do we send this signal? Using your choice of kill, killall, or pkill. All of these will, by default, send a TERM signal (15), which is not what we want at all. Instead, use the following to send the USR1 signal to all processes you own named dd.
$ pkill -USR1 ^dd$
Kill and killall support the -USR1 option in the same manner.
If you want a periodic status report, you can extend the same idea with watch in another terminal. Since we’re just sending a signal, there won’t be any output in the display from watch, but it’s a nice shortcut for periodic execution.
$ watch -n5 -- pkill -USR1 ^dd$
Will send signal USR1 to any dd process you own every five seconds, triggering dd to tell you where it is in the transfer and how fast it’s going. Remember, look at dd’s terminal for the output!
$ dd if=/dev/zero of=/tmp/demo bs=1M count=1536
137+0 records in
137+0 records out
143654912 bytes (144 MB) copied, 5.66717 seconds, 25.3 MB/s
249+0 records in
249+0 records out
261095424 bytes (261 MB) copied, 11.5736 seconds, 22.6 MB/s
388+0 records in
387+0 records out
405798912 bytes (406 MB) copied, 18.8116 seconds, 21.6 MB/s







August 17th, 2007 at 7:01 am
Get Progress Reports from dd
There is a great mini-article up at RedHat Magazine about the dd tool and how you can make it give you progress reports (dd by default is not very talkative). Read the full story here.
…
August 17th, 2007 at 9:34 am
Or use a better tool: http://linux.maruhn.com/sec/sdd.html
August 17th, 2007 at 11:08 am
Allocating a new VT isn’t always an option, especially on a serial terminal. Some systems allocate only one VT in single user mode. In that case, you can use “screen”.
Another problem with the “pkill ^dd$” technique is that it can send unintended signals to processes, other “dd” programs you are running, or all the “dd” processes for all users if you are currently root.
If “screen” isn’t available, you can put “dd” into the background and run the following instead, in Bash:
while true ; do kill -USR1 $! ; sleep 5 ; done
“$!” expands to the PID of the last job put into the background.
August 17th, 2007 at 5:13 pm
You can use dd_rescue instead of dd to get progress on the transfer.
You can also use pv to monitor a dd transfer:
dd if=/dev/zero | pv | dd of=/tmp/demo bs=1M
September 24th, 2007 at 4:10 am
Hello all,
how to use dd command for many times?
can we use it with scripting language?
THanks.
Regards,
Ashish Barot.
October 1st, 2007 at 2:03 pm
Which version of dd are you using to get that output? I tried sending a USR1 to dd on all our RHEL releases (2.1/3/4) and I got the ‘blocks transferred’ but not the nice ‘xMB copied, x seconds, x MB/s’ line at the end. JG
October 8th, 2007 at 3:43 pm
I usually simply ‘watch’ the target with ls -l, du, or whatever is appropriate. It works on any system.
July 7th, 2008 at 5:56 pm
[…] ref: http://www.redhatmagazine.com/2007/08/16/tips-from-an-rhce-how-can-i-make-dd-give-me-a-progress-report/ This entry was posted on Tuesday, July 8th, 2008 at 4:56 am and is filed under Test. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. […]