Sap IT notes

How to check ‘dd’ progress.


dd is useful enough tool for data copying but it does not show a progress.
There is a way to check dd progress. May be it’s not convenient but it works.

Let’s start data copying:
[root@fedora23 ~]# dd if=/dev/urandom of=/root/test.img bs=1M count=1000 oflag=direct &
[1] 35101

flag ‘oflag=direct’ use to bypass RAM cache and save data directly on disk.

Now we have process ID – 35101. Run lsof:
[root@fedora23 ~]# lsof -p 35101
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dd 35101 root cwd DIR 253,0 4096 33575009 /root
dd 35101 root rtd DIR 253,0 244 96 /
dd 35101 root txt REG 253,0 74096 16951651 /usr/bin/dd
dd 35101 root mem REG 253,0 111950656 36802544 /usr/lib/locale/locale-archive
dd 35101 root mem REG 253,0 2103656 33631736 /usr/lib64/libc-2.22.so
dd 35101 root mem REG 253,0 160624 33631727 /usr/lib64/ld-2.22.so
dd 35101 root 0r CHR 1,9 0t0 1033 /dev/urandom
dd 35101 root 1w REG 253,0 102760448 34900243 /root/test.img
dd 35101 root 2u CHR 136,0 0t0 3 /dev/pts/0

Let’s look at this string: dd 35101 root 1w REG 253,0 102760448 34900243 /root/test.img, here 1w is File Descriptor (FD), a letter ‘w’ says that file /root/test.img open with write permission.

Now change directory to /proc/35101/fdinfo/ and run ‘ls -l’:
[root@fedora23 fdinfo]# ls -l
total 0
-r--------. 1 root root 0 Nov 25 16:19 0
-r--------. 1 root root 0 Nov 25 16:19 1
-r--------. 1 root root 0 Nov 25 16:19 2

file with name ‘1’ like file descriptor above.

Just look inside:
[root@fedora23 fdinfo]# cat 1
pos: 787480576
flags: 0140001
mnt_id: 62

‘pos’ says about amount of data wich have been written to the /root/test.img file in bytes, pos: 787480576/1024/1024 = 751 MB.

It could be more convenient to run bash script like this one:
while [ 1 ]; do grep pos /proc/35101/fdinfo/1 | awk '{print $2/1024/1024}';sleep 1; clear;done

 

There is a similar way to check how much data was read from source file. In this example /dev/urandom is the source and lsof above showed:
dd 35101 root 0r CHR 1,9 0t0 1033 /dev/urandom

Here File Descriptor is 0r, just look at ‘0’ file content and ‘pos’ shows us how much data have been read.

Sometimes it could be very useful to check ‘dd’ progress, especially when you use it to copy huge piece of data through the network.

Leave a Reply

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

© 2015