Do not like the silent dd on unix? Let’s add a progress bar for it. (Using pv)

Though dd is not efficient, it’s still widely used for many years until now, especially when we are “burning” the disk image of the famous Raspberry Pi or some related boards, the worst point I hate about dd is the silence, it makes me worried, we can not know the progress of the process, and if it takes too much time, we may start to think about if the computer hung, the SD card broken, or something else … until the process finished, that’s very bad.

I’ve found pv and also use it for a while, it’s the Pipe Viewer, a terminal-based tool for monitoring the progress of data through a pipeline, I know it’s not so famous and widely used, so I would like to share and talk about it, let’s start it!

pv is a OSI(Open Source Initiative, not the network Open Systems Interconnection model) certified open source software, here is the homepage of it:

The latest release until now is v1.6.0, the version in Ubuntu 14.04 LTS is v1.2.0, but still works well, I am going to use Raspbian Jessie, version February 2016 (Release date:2016-02-09) as the example image in this post, and writing an raw image to a microSD card as the scenario.

Traditionally, we use dd like this, dd in, dd out, with silence:

$ sudo dd if=./2016-02-09-raspbian-jessie.img of=/dev/sdd bs=10M

Trust me, you will like to have pv once you used it, before using pv, we need to manually install it.

On Debian/Ubuntu based GNU/Linux:

$ sudo apt-get install pv

On FreeBSD:

$ sudo pkg install pv

On CentOS/Fedora based GNU/Linux (the “extras” repository may be required):

$ sudo yum install pv

On Mac OS X (via homebrew):

$ brew install pv

Some people put the pv in the middle of dds, I also tried it before:

$ dd if=./2016-02-09-raspbian-jessie.img | pv | sudo dd of=/dev/sdd bs=10M

The previous usage will have info about the speed of copying and the size of copied data and time used, but no real progress, because pv can’t know the size of the whole data.

In fact, pv supports reading a file by itself, and by using pv reading the file, instead of receiving the pipe, it can know the size of the file so that it can calculate the progress!

That’s how I use it now:

Using pv to read file with progress bar, pipe to dd and then output:

$ pv 2016-02-09-raspbian-jessie.img | sudo dd of=/dev/sdd bs=10M
$ zcat OpenELEC-RPi.arm-6.0.1.img.gz | pv  | sudo dd of=/dev/sdd bs=10M

Then you can see now we have the real progress bar, the percentage, and ETA time:

Looks better, right? Do not limit pv usage by this scenario, you can also use pv when reading from a device, you are welcome to share your usage with me in the comment.