Upgrading software on Linux / Android boards or devices often involves copying images to an SD card or microSD. In Linux, you’d usually do that with dd, a utility that provides binary copy of data to files or block devices. A typical command would be:
1 |
sudo dd if=new_firmware.bin of=/dev/sdc |
However, during the copy, dd does not show a progress bar by default. But dd actually supports progress report, as indicated in the manpage: you can run dd, and send USR1 signal to display the current progress once, and resume copying. Linux commando explains how to continuously return the progress. First run the dd command:
1 |
sudo dd if=/dev/random of=/dev/null bs=1K count=100 |
Open another terminal window to find out the process id:
1 2 |
pgrep -l '^dd$' 10152 dd |
And use the watch command to send USR1 at regular interval.
1 |
watch -n 10 sudo kill -USR1 10152 |
You should see dd progress in the first window every 10 seconds. It works, but the output is not very nice because dd will just output 3 lines at a time, and you’ll see something like:
1 2 3 4 5 6 |
3252612+0 records in 3252612+0 records out 3330674688 bytes (3.3 GB) copied, 12.9668 s, 257 MB/s 3872256+0 records in 3872256+0 records out 3965190144 bytes (4.0 GB) copied, 23.1629 s, 171 MB/s |
I’ve recently come across a script (dd.sh) that handles all those steps for you, and display the progress nicely. First download it, and install it in your path:
1 2 3 |
wget http://shellscripts.org/dl/projects/d/ddprogress/version_2/dd.sh sudo cp dd.sh /usr/local/bin sudo chmod 755 /usr/local/bin/dd.sh |
Then use it just as you would with dd:
1 2 3 |
sudo dd.sh if=/dev/sdc of=test.img bs=1M Getting blocksize from '/dev/sdc': 7744512 In: 781M (8M/sec) - Out: 781M (8M/sec) ETA: 00:03:20 |
The last line is updated regularly, and shows transfer rate, as well as the estimated time to completion.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
Or you can just use dcfldd instead dd
Useful!! Thx
With pv:
zoobab@buzek /home/zoobab [11]$ dd if=/dev/zero |pv|dd of=/dev/null bs=1M count=1000000
dd: warning: partial read (60416 bytes); suggest iflag=fullblock
^C2419864+0 records iniB/s] [ ]
@zoobab: +1 I just pipe through ‘pv’.
New version of coreutils (8.24) adding a status progress to dd tool:
Usage on Xubuntu 15.10:
Open terminal shell and type these commands:
wget ftp://ftp.gnu.org/pub/gnu/coreutils/coreutils-8.24.tar.xz
tar -xf coreutils-8.24.tar.xz
cd coreutils-8.24
./configure && make -j $(nproc)
Run dd as root:
sudo ./dd if=/dev/sdc of=/dev/sda conv=noerror status=progress
You will see: Bytes, Seconds and Velocity (Bytes/seconds)
To check versions of dd:
Native:
dd –version
New (cd coreutils-8.24/src):
./dd –version