{"id":45,"date":"2011-02-05T08:02:00","date_gmt":"2011-02-04T22:02:00","guid":{"rendered":"https:\/\/www.serenux.com\/?p=45"},"modified":"2021-01-14T08:04:37","modified_gmt":"2021-01-13T22:04:37","slug":"howto-monitor-the-progress-of-dd","status":"publish","type":"post","link":"https:\/\/www.serenux.com\/index.php\/2011\/02\/05\/howto-monitor-the-progress-of-dd\/","title":{"rendered":"HowTo: Monitor the progress of dd."},"content":{"rendered":"\n<p>The&nbsp;<em>dd<\/em>&nbsp;command is a tool used to pipe data in from a source to a destination. It has a multitude of uses ranging from creating large dummy files of a specific size to duplicating hard-drives sector by sector to another disk or to a backup file. It\u2019s also useful for fixing problems with hard-drives that Windows refuses to deal with.<\/p>\n\n\n\n<p>But we\u2019re not looking at the virtues of&nbsp;<em>dd<\/em>&nbsp;here. We\u2019re looking at its annoyances and&nbsp;<em>dd<\/em>&nbsp;has one particularly glaring annoyance \u2013 a lack of display of progress. You could tell&nbsp;<em>dd<\/em>&nbsp;to start imaging your multi-terabyte hard-drive and not have any indication of how far it has gone \u2013 you just have to wait until it finishes. The&nbsp;<em>dd<\/em>&nbsp;command only outputs some information right at the very end of its job, which could well be several hours later. The only indicator that you have that something is happening is your hard-drive light madly flashing away.<\/p>\n\n\n\n<p>Luckily while&nbsp;<em>dd<\/em>&nbsp;doesn\u2019t show progress during its tasks, it can be prodded externally to give up information about itself as it runs, and we can achieve that by using the&nbsp;<em>kill<\/em>&nbsp;command without actually killing the&nbsp;<em>dd<\/em>&nbsp;command\u2019s execution.<\/p>\n\n\n\n<p>Now the&nbsp;<em>kill<\/em>&nbsp;command doesn\u2019t just terminate tasks. It can also send other standard POSIX signals to applications. Many applications are written to acknowledge certain signals and perform an action on receiving them. In the case of&nbsp;<em>dd<\/em>, there is one signal that will make it output its summary information to the console as though it had finished, but rather than terminate, it keeps on going. The signal in question is USR1.<\/p>\n\n\n\n<p>Here\u2019s how to make use of it:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>First we need a\u00a0<em>dd<\/em>\u00a0process running. Let\u2019s say we are imaging our first fixed hard-drive\u00a0<em>\/dev\/sda<\/em>\u00a0to an image file called\u00a0<em>MyHDDBackup.img<\/em>\u00a0using the following command:<br><br><code>$ sudo dd if=\/dev\/sda of=\/home\/jbloggs\/MyHDDBackup.img<\/code><br><\/li><li>Now while that is running, open up a second terminal and type in the following followed by Enter:<br><br><code>$ sudo kill -USR1 `pgrep ^dd`<\/code><br><br>Breakdown of the above command:<ul><li><em>sudo<\/em>\u00a0runs this command as root. In this case since we\u2019re using\u00a0<em>dd<\/em>\u00a0as root, we also need to run the\u00a0<em>kill<\/em>\u00a0command as root or we won\u2019t be able to send anything to\u00a0<em>dd<\/em>.<\/li><li><em>kill<\/em>\u00a0is the command we are using to send\u00a0<em>dd<\/em>\u00a0a signal with.<\/li><li><em>-USR1<\/em>\u00a0is the signal we are sending to\u00a0<em>dd<\/em>.<\/li><li><em>pgrep<\/em>\u00a0is a program that will show you the process ID of a given application, in this case we use the argument \u201c^dd\u201d to say \u201clocate any program that starts with the text \u2018dd\u2019 only\u201d otherwise we would get other processes that containg the letters \u201cdd\u201d together in their name if we left out the chevron character. Note that the\u00a0<em>pgrep<\/em>\u00a0command is enclosed in \u201c`\u201d quotes so that it is executed and returns just a process ID number to the\u00a0<em>kill<\/em>\u00a0command.<br><\/li><\/ul><\/li><li>Now have a look at the terminal that\u00a0<em>dd<\/em>\u00a0is running in. It has suddenly output some data about itself, specifically, how much of the task had been completed, but\u00a0<em>dd<\/em>\u00a0is still running!<br><br>This is great \u2013 but how can we regularly have\u00a0<em>dd<\/em>\u00a0tell us where it\u2019s up to without having to manually enter the above command each time? Simple, by combining it with the\u00a0<em>watch<\/em>\u00a0command:<br><br><code>$ watch 'sudo kill -USR1 `pgrep ^dd`' <\/code><br><br>The\u00a0<em>watch<\/em>\u00a0command will will re-execute the\u00a0<em>kill<\/em>\u00a0command once every two seconds, giving you near-realtime status to what\u00a0<em>dd<\/em>\u00a0is doing. If you want to change how often the\u00a0<em>watch<\/em>\u00a0command polls for, you can change it with the\u00a0<em>-n<\/em>\u00a0parameter, for example to change the polling to every 5 seconds, you would use:<br><br><code>$ watch -n5 'sudo kill -USR1 `pgrep ^dd`'<\/code><\/li><\/ol>\n\n\n\n<p>While not providing any means of showing you how long it will take for&nbsp;<em>dd<\/em>&nbsp;to ultimately finish, you can now make use of the transfer speed shown along with the data processed thus far and calculate a rough idea of when&nbsp;<em>dd<\/em>&nbsp;will complete its task now.<\/p>\n\n\n\n<p>Pat yourself on the back. You can now rest easy knowing that you can find out at anytime where&nbsp;<em>dd<\/em>&nbsp;is up to.&nbsp;<img decoding=\"async\" src=\"https:\/\/web.archive.org\/web\/20150315210029im_\/http:\/\/www.serenux.com\/wp-content\/themes\/grey-opaque\/images\/smilies\/icon_smile.gif\" alt=\"Smilie: :)\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The&nbsp;dd&nbsp;command is a tool used to pipe data in from a source to a destination. It has a multitude of uses ranging from creating large dummy files of a specific size to duplicating hard-drives sector by sector to another disk or to a backup file. It\u2019s also useful for fixing problems with hard-drives that Windows [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":1,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":46,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/posts\/45\/revisions\/46"}],"wp:attachment":[{"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/media?parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/categories?post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.serenux.com\/index.php\/wp-json\/wp\/v2\/tags?post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}