dd is a popular, generic command-line tool for copying files from 1 location to another. It is often used to copy entire disk images.
Like many Linux command line tools, it operates silently unless something unexpected happens. Its lack of visual progress feedback is a nice feature for scripting. However, it can leave you wondering about its progress if you are interactively dd-copying a large disk.
To illustrate, you run the following (valid, but perhaps not very useful) dd copy:
$ dd if=/dev/random of=/dev/null bs=1K count=100
It will run for a few minutes as it copies (and immediately discards) 100 blocks of randomly generated data, each of size 1 KB.
To get a progress report while dd is running, you need to open another virtual terminal, and then send a special USR1 signal to the dd process.
First, find out the process id of the dd process by running the following in the new virtual terminal.
$ pgrep -l '^dd$'
8789 dd
$
To send the USR1 signal to the dd prcoess:
$ kill -USR1 8789
$
Note that as soon as the USR1 signal is detected, dd will print out the current statistics to its STDERR.
$ dd if=/dev/random of=/dev/null bs=1K count=100
0+14 records in
0+14 records out
204 bytes (204 B) copied, 24.92 seconds, 0.0 kB/s
After reporting the status, dd will resume copying. You can repeat the above kill command any time you want to see the interim statistics. Alternatively, you can use the watch command to execute kill at a set interval.
$ watch -n 10 kill -USR1 8789
P.S.
Other articles from this blog on the dd command:
Create files of a given size
46 comments:
Thank U!
thanks too. i was trying SIGINFO but that isnt implemented on linux. a wiki article said SIGPWR is SIGINFO - after 2 hrs of cloning my new HDD i managed to kill dd because of a power problem. Gutted. SIGPWR wiki article is a troll :( nice watch idea - i was going to script it :D
Thanks. This was very helpful!
Use "pv" command from "pv" package.
Try for example:
pv -ptre FILE | dd of=FILE bs=1M
Gives a nice output with a progressbar, good for writing cf cards from images.
Just use dcfldd instead. It is an "enhanced version of dd for forensics and security" and is readily available in most *nix package mangers!
you can use killall -s USR1 dd
can be ever better, using only tr as an extracommand:
dd if=/dev/random of=/dev/null bs=1K count=1000
then:
pgrep -l '^dd$' | tr -d [:alpha:]
12320
watch -n 1 kill -USR1 $(pgrep -l '^dd$' | tr -d [:alpha:])
and output will be:
dd if=/dev/random of=/dev/null bs=1K count=1000
0+85 records in
0+85 records out
709 bytes (709 B) copied, 93.5436 s, 0.0 kB/s
0+113 records in
0+113 records out
933 bytes (933 B) copied, 119.764 s, 0.0 kB/s
0+113 records in
0+113 records out
.
.
and so on ...
Handy tip, thanks!
/hERB
Thanks alot
If you're the only one on the system, just do:
pkill -USR1 dd
Saves yourself a step!
By the way, using SIGUSR1 on MacOS will kill dd. You need to use SIGINFO instead.
Careful, I did this on Ubuntu 8.10 and it just killed the process >:(
Thank you! Very useful piece of advice! :)
Thanks a lot. Nice tip! Just helped me to see the status if my prolong running 'dd'!
Dipak
1. Nice hack :)
2. Ubuntu doesn't really count as Linux :)
Thanks. This was exactly what I was looking for.
Ubuntu definitely counts as Linux.
You are a genius, and I thank you so very much. I am glad that I don't have to kill dd and start it over again with a --verbose flag!
Neat!
thanks, very helpfull - I've used:
while sleep 10; do sudo kill -USR1 [PID]; done
Good stuff, very helpful while low-level copying a 750Gb drive. Thanks!!
thanks!!! was very helpfull...
You made my day. Thanks.
very helpful, thank you
I did the following:
$dd if=/dev/sda of=/dev/sdb conv=sync
and on another terminal:
$watch -n 480 kill -USR1 4292
The final message was:
488397168+0 records in
488397168+0 records out
250059350016 bytes (250 GB) copied, 53809 s, 4.6 MB/s
53809 s = 14 h 56 mn 49 s
Before copying I got :
$ fdisk -l
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x35e920cb
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 6092 48829567+ 83 Linux
/dev/sda3 6093 13387 58597087+ 7 HPFS/NTFS
/dev/sda4 13388 30401 136664955 f W95 Ext'd (LBA)
/dev/sda5 13388 21036 61440561 7 HPFS/NTFS
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe8cd189d
Device Boot Start End Blocks Id System
/dev/sdb1 1 60801 488384001 c W95 FAT32 (LBA)
After copying I got :
$ fdisk -l
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x35e920cb
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 6092 48829567+ 83 Linux
/dev/sda3 6093 13387 58597087+ 7 HPFS/NTFS
/dev/sda4 13388 30401 136664955 f W95 Ext'd (LBA)
/dev/sda5 13388 21036 61440561 7 HPFS/NTFS
Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x35e920cb
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 104391 83 Linux
/dev/sdb2 14 6092 48829567+ 83 Linux
/dev/sdb3 6093 13387 58597087+ 7 HPFS/NTFS
/dev/sdb4 13388 30401 136664955 f W95 Ext'd (LBA)
/dev/sdb5 13388 21036 61440561 7 HPFS/NTFS
Thanks, i knew about the USR1 trick, but learnt about the watch command from your blog. It's really useful.
Thx! :)
Exactly what I needed. Thank you!
Thanks. but you need to explain what STDERR means. You don't explain what STDERR is
STDERR is error message destination, a console/monitor by default. Thanks for the article.
Typing ^T (CTRL-T) in the console where dd is running should achieve the same result as the USR1 signal.
Regards
Just thank you for this tip.
Thumb up! Thank you mate!
Really.. nice job! This is what I wanted.
Thank You.
http://webhoststore.tk
Thanks for the help!
Excellent, thank you Master!
Warning: using the USR1 signal on Mac OSX kills dd!
Thank you So Much! I was in pain because I didn't knew if the command was working correctly or not.... i am zeroing my hard drive.Thank you again for your advice.
Warning: using the USR1 signal on Mac OSX kills dd! Use this on OSX:
killall -SIGINFO dd
or (if dd was started as sudo)
sudo killall -SIGINFO dd
dd if=/dev/zero of=/dev/null & pid=$! ; watch -n 3 kill -USR1 $pid
:c)
Thanks. This was very helpful!
I just did
sudo kill -USR1
on Mac, It killed the process!! Damn! it was running more than 1 hour :( Lost it!
I just used it after booting my machine from System Rescue CD and using the dd command to clone my disk to another disk of the same size. Worked like a charm. Thank you for the tip!
Thank you!!! Had many months that I was seeking for this tip!!! tks :))
@iambaskar
yeah, I just did that too, and it killed the process w/o restarting. Also on a Mac.
@Joel Riggs and Mac OS friends: check the man page of your dd implementation. In Linux, "dd" is part of the GNU coreutils package. The man page in a recent Linux system says:
Sending a USR1 signal to a running 'dd' process makes it print I/O sta‐
tistics to standard error and then resume copying.
$ dd if=/dev/zero of=/dev/null& pid=$!
$ kill -USR1 $pid; sleep 1; kill $pid
Other "dd" imprementation may not handle an USR1 signal in which case the process will terminate.
Everything is in the manuals (TM).
Post a Comment