Printing dd status

I recently used dd to zero out some hard drives on my Fedora Core workstation, and found that this operation takes a good deal of time (even when large blocksizes are used, it still takes a while). The dd utility doesn’t report status information by default, but when fed a SIGUSR1 signal it will dump the status of the current operation:

$ dd if=/dev/zero of=/dev/hda1 bs=512 &

$ kill -SIGUSR1 1749
1038465+0 records in
1038465+0 records out
531694080 bytes (532 MB) copied, 11.6338 seconds, 45.7 MB/s

It still amazes me how much stuff I have left to learn about the utilities I use daily.

13 thoughts on “Printing dd status”

  1. short version: good for linux, don’t try on OSX. :)

    long version:

    i found this entry looking for a way to find out how long this dd i am currently running was going to take. my command ‘dd bs=512 if=/dev/disk3 of=/dev/disk2 conv=noerror,sync’ was meant to clone the failing drive in my powerbook (attached in firewire target mode (disk3) to my workstation powerbook) to another attached drive of identical geometry also on firewire (disk2).

    i played with lsof and a few other commands in an attempt to derive total capacity or blocks or something in hex and compare them to the number of instruction calls dd has performed… and was getting WAY in depth on this. I decided there should be a simpler way … I should have known – BSD != linux. ;)

    kill -SIGUSR1 will cause abrupt termination of dd with the result “User defined signal 1”.

    WHoops! Now I gotta start over.

    Good learning experience though.

    I know there’s stuff like “Carbon Copy Clone” for OSX but i refuse to believe a good dessert can’t be made from a recipe of dd, disklabel, diskutil, and a sprinkle of some other stuff without using some GUI that removes you from what’s really happening underneath.

    but.. just in case anyone else finds this, is using OSX, and wants to try it – beware, you might be starting your dd over again. in my case, i was 2 hrs into it. :) doh!

    -jre

  2. as a followup to my last comment… this worked
    (gosh, helps to read man pages – commands differ on different OSes. whod’a thunkit?)
    $ kill -s SIGINFO 9923
    and on my other screen window:
    $ dd bs=512 if=/dev/disk3 of=/dev/disk2 conv=noerror,sync
    8550657+0 records in
    8550656+0 records out
    4377935872 bytes transferred in 2619.316508 secs (1671404 bytes/sec)

    Yay. getting there! (darn slow FireWire v1 drives)
    -jre

  3. It is useful to use this command with the command ‘watch’.

    for some reason it did not work for me to do this:

    watch -n 30 kill -SIGUSR1 1234

    Instead I had to do this:

    watch -n 30 kill -USR1 1234

    -n 30 specifies for the action to be performed every 30 seconds

    As should be clear from the article 1234 should be replaced with whatever the process id of dd is. (use ‘top’ or ‘ps -e’ to find pid)

  4. Or you can skip all that pid crap and use pkill:

    watch -n 5 pkill -SIGUSR1 dd

    Boom, status updates every 5 seconds

  5. or you could follow the example in the frickin’ man page:
    dd if=whatever of=whatever; pid=$!
    Now you have the PID for DD in $pid
    kill -USR1 $pid

  6. On OS X and FreeBSD it’s even easier – just use ctrl-t interactively to get SIGINFO from dd or any other utility that supports it. No background/kill necessary.

Leave a Reply

Your email address will not be published. Required fields are marked *