Linux dd вывод прогресса

How do you monitor the progress of dd?

dd is a wonder. It lets you duplicate a hard drive to another, completely zero a hard drive, etc. But once you launch a dd command, there’s nothing to tell you of its progress. It just sits there at the cursor until the command finally finishes. So how does one monitor dd’s progress?

21 Answers 21

Update 2016: If you use GNU coreutils >= 8.24 (default in Ubuntu Xenial 16.04 upwards), see method 2 below for an alternate way to display the progress.

Method 1: By using pv

Install pv and put it between input / output only dd commands.

Note: you cannot use it when you already started dd .

pv — Pipe Viewer — is a terminal-based tool for monitoring the progress of data through a pipeline. It can be inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion.

Installation

dd if=/dev/urandom | pv | dd of=/dev/null 

You could specify the approximate size with the —size if you want a time estimation.

Example Assuming a 2GB disk being copied from /dev/sdb

Command without pv would be:

sudo dd if=/dev/sdb of=DriveCopy1.dd bs=4096 
sudo dd if=/dev/sdb | pv -s 2G | dd of=DriveCopy1.dd bs=4096 
440MB 0:00:38 [11.6MB/s] [======> ] 21% ETA 0:02:19 

You can of course use pv directly to pipe the output to stdout:

pv /home/user/bigfile.iso | md5sum 
50,2MB 0:00:06 [8,66MB/s] [=======> ] 49% ETA 0:00:06 

Note that in this case, pv recognizes the size automatically.

Method 2: New status option added to dd (GNU Coreutils 8.24+)

dd in GNU Coreutils 8.24+ (Ubuntu 16.04 and newer) got a new status option to display the progress:

Example

dd if=/dev/urandom of=/dev/null status=progress 

Output

462858752 bytes (463 MB, 441 MiB) copied, 38 s, 12,2 MB/s 

Note that the parameters for «dd» are appropriate in the first half (the input part of the pipe): dd if=/dev/zero bs=1M count=35000 | pv | dd of=VirtualDisk.raw .

pv bigfile.iso | dd of=VirtualDisk.raw bs=1M count=35000 works, verified. @SopalajodeArrierez, parameters can be given in the second dd.

FYI on speed. Tests on my computer with Samsung 840 PRO SSD: dd if=/dev/urandom | pv | of=/dev/sdb gives ~18MB/s write, dd if=/dev/zero | pv | of=/dev/sdb gives ~80MB/s, and plain old dd if=/dev/zero of=/dev/sdb gives ~550MB/s (close to SSD max write speed). All with bs=4096000 .

You can monitor the progress of dd once it’s running without halting it by using the kill command to send a signal to the process.

Читайте также:  Linux вывести содержимое всех файлов

After you start dd , open another terminal and enter either:

Or, if you’re on BSD or OS X:

This will display the progress in the dd terminal window without halting the process (by printing to its stderr stream). For example:

# dd if=/dev/urandom of=rando bs=1024 count=1048576 335822+0 records in 335821+0 records out 343880704 bytes (344 MB, 328 MiB) copied, 6.85661 s, 50.2 MB/s 

If you would like to get regular updates of the dd progress, then enter:

watch -n5 'sudo kill -USR1 $(pgrep ^dd$)' 

watch will probe the dd process every -n seconds ( -n5 = 5 seconds) and report without halting it.

Note the proper single quotes in the commands above.

This worked, but a couple of comments. First of all, I’m not sure why you escaped your backticks (if it’s for the SO editor, you did it incorrectly). Secondly I’d recommend using ^dd$, just in case something else is running with the prefix dd. Finally, you don’t need sudo to send the USR1 signal. Otherwise, good answer, +1.

sudo pkill -usr1 dd is easier to remember, works perfectly fine (at least on Ubuntu 14.04), and is less to type.

I like this because I’m afraid pv will slow down the transfer, as TeddHansen showed it does. Also, I’ll bet lots of people are Googling this because they already started the dd operation 😉

A few handy sample usages with pv and less typing or more progress then other answers:

First you will need to install pv , with the command:

pv -n /dev/urandom | dd of=/dev/null pv -tpreb source.iso | dd of=/dev/BLABLA bs=4096 conv=notrunc,noerror 

Note: the first sample is 5 characters less typing then dd if=/dev/urandom | pv | dd of=/dev/null .

And my favorite for cloning a disk drive (replace X with drive letters):

(pv -n /dev/sdX | dd of=/dev/sdX bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait. " 10 70 0 

screenshot

Also for archiving myself.

Calling from python? You may use it with «subprocess.Popoen». Despite not recommended because of security issues. Without graphicish results, this guy has made a similar impact: code.activestate.com/recipes/578907-python-awesome-dd Check out I guess.

For the sake of completeness:

Version 8.24 of the GNU coreutils includes a patch for dd introducing a parameter to print the progress.

The commit introducing this change has the comment:

dd: new status=progress level to print stats periodically

Many distributions, including Ubuntu 16.04.2 LTS use this version.

just wanna add how I’ve compiled 8.24 coreutils: apt install build-essential and apt-get build-dep coreutils , then download coreutils-8.25.tar.xz, tar xvf coreutils-8.25.tar.xz configure —prefix=$HOME/usr/local and run make . Newly compiled dd will be under src dir. You can copy it to /bin and replace existing one or jus run as src/dd

Note that the status will sometimes print with two numbers, one in SI units and the equivalent value in binary units (e.g.10 MB, 9.5 MiB).

Читайте также:  Установка шрифтов linux debian

Use Ctrl + Shift + T while dd is running, and it will output the progress (in bytes):

load: 1.51 cmd: dd 31215 uninterruptible 0.28u 3.67s 321121+0 records in 321120+0 records out 164413440 bytes transferred in 112.708791 secs (1458745 bytes/sec) 

This doesn’t work on Ubuntu. Ctrl-T/Ctrl-Shift-T only output ^T to the terminal (except many terminal apps will intercept Ctrl-Shift-T and open a new tab). Many searchers on OSX/BSD may appreciate this answer, but it should be made clear that it’s not for Ubuntu (or GNU/LInux in general?)

The best is using http://dcfldd.sourceforge.net/ it is easy to install through apt-get

thanks for the pointer to dcfldd, very compatible with dd but some good new features. I especially like the standard progress.

It has the options of dd and option status=on by default, for progress messages, statusinterval=N (N in blocks) for message update frequency and sizeprobe=[if|of] for a percentage indicator. I will alias it to DD 🙂

Native progress status was added to dd.

The new version of Coreutils (8.24) adds a progress status to the dd tool:

Open a terminal 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) 
sudo su cd src ./dd if=/dev/sdc of=/dev/sda conv=noerror status=progress 

You will see: Bytes, seconds and speed (Bytes/second).

To check the versions of dd :

cd coreutils-8.24/src ./dd --version 

If you have already started dd, and if you are writing a file such as when creating a copy of a pendrive to disk, you can use the watch command to constantly observe the size of the output file to see changes and estimate completion.

watch ls -l /pathtofile/filename 

To see only file size (h-human view):

watch ls -sh /pathtofile/filename 

Useful, though this doesn’t necessarily work if you’re piping the dd output to something other than a file (eg gzip’ing before writing it to disk).

The dd | pv | dd triad made my 50GB vm copy take 800 seconds, as opposed to 260 seconds using just dd. With this pipeline, at least, pv has no idea how big the input file is so it won’t be able to tell you how far along you are so there’s no disadvantage to doing it as follows- and you get a nice speed advantage:

I would avoid pv on anything large, and (if using Bash):

bg to put it in background. Observe that bg will give you output like [1] 6011 where the latter number is a process id. So, do:

while true; do kill -USR1 process_id ; sleep 5; done

where process_id is the process id you observed. Hit Control-C when you see something like:

[1]+ Done dd if=/path/file.qcow2 of=/dev/kvm/pxetest bs=4194304 conv=sparse -bash: kill: (60111) - No such process 

Edit: Silly Systems Administrator! Automate your life, don’t work! If I have a long dd process that I want to monitor, here’s a one-liner that will take care of the whole enchilada for you; put this all on one line:

 dd if=/path/to/bigimage of=/path/to/newimage conv=sparse bs=262144 & bgid=$!; while true; do sleep 1; kill -USR1 $bgid || break; sleep 4; done 

You can, of course, script it, perhaps make $1 your input file and $2 your output file. This is left as an exercise for the reader. Note that you need that little sleep before the kill or the kill may die trying to send a signal to dd when it’s not ready yet. Adjust your sleeps as desired (maybe even remove the second sleep altogether).

Читайте также:  Astra linux puppet foreman

Источник

Show dd Progress in Linux with these 2 Methods

The Linux dd command is a well-known tool to create live USB. One drawback of this tool is that it doesn’t show progress and thus you don’t know what’s going on while creating live USB. This tutorial explains how to show dd progress in 2 methods.

Show dd Progress with Status option

The dd command is part of the GNU core utilities, aka coreutils. A dd progress indicator has been built into this utility since coreutils version 8.24. To check the version of coreutils on your Linux OS, simply run this command:

show dd progress coreutils

Ubuntu 16.04, Debian 9 and Arch Linux-based distros has latest version 8.25. To let dd show progress you need to add status=progress option like below:

sudo dd if=/path/to/iso/file of=/dev/sdX bs=4M status=progress

linux dd progress indicator

You can see how much has been copied, how many seconds has passed and write speed.

The exact device name for your USB drive can be obtained from fdisk command.

Monitor Progress of dd with PV

For those who don’t have access to coreutils v8.24+, this method is for you. pv is a pipe viewer which can be used to monitor the progress of data flow in Linux pipeline. To install it, issue the following command:

To see dd progress, combine pv and dd command like below.

pv /path/to/isofile | sudo dd of=/dev/sdX

| is the symbol for pipe in Linux. In the above command, pv puts the iso file into the pipe and dd will get the iso file from the pipe then write the iso file to your USB device identified by /dev/sdX.

dd get status

You can get status of how much has been copied, how many seconds has passed, write speed, a percentage progress indicator and estimated remaining time.

I personally prefer dd over Unetbootin because dd always worked for me whereas sometimes live USB created by Unetbootin won’t boot.

As always, if you found this post useful, subscribe to our free newsletter or follow us on Google+, Twitter or like our Facebook page.

Источник

Оцените статью
Adblock
detector