3

I'm trying to use dd with pv to write an iso to a usb drive. I did:

iso="myiso.iso"; dd if="$iso" bs=1M | pv --eta --size $(ls -l "$iso" | awk '{print $5}') --progress --bytes --rate --wait > /dev/sdg

Following this guide: https://gist.github.com/rriemann/1406035

However, what happens is that the iso is "written" very quickly according to the output of pv. I'm guessing it's all put into disk cache or similar. Then pv just hangs. ps shows that pv is still running, but dd isn't. I tried stracing pv, but there is no output, and strace hangs as well! ctrl+c has no effect on strace. In fact, it does not respond to signals 15, 3, 2, or 1. Waited a few minutes for each signal. I was eventually forced to send 9.

According to this: http://www.reddit.com/r/linux/comments/1xvr25/linux_tip_dont_use_kill_9/ The strace binary is badly behaved.

Here are my questions:

  1. How can I make pv report more useful data? I know it is probably doing what it is "supposed to", ie, just reporting on bytes that it pipes. But that is not helpful for what I want to know, which is rough estimate for bytes written to usb drive, eta, etc.

  2. Why is strace not responding to any signals? My guess is that strace waits for a system call from the process it is watching before handling the next signal, which I would consider a bug. But that is just a guess. strace version 4.5.20.

4
  • 3
    That would appear to be a useless use of dd. pv --eta --progress --bytes --rate --wait "$iso" > /dev/sdg would be much simpler. Probably has the same problem, though. – derobert Jul 25 '14 at 21:45
  • Can pv specify block size though? bs=1M is much faster than the default. – cat pants Jul 25 '14 at 21:49
  • 1
    I think you'll find pv just as fast at hurrying up and waiting for the cache to flush... And, actually, yes; that's the -B option. I suspect the default will be fine, though. – derobert Jul 25 '14 at 21:50
  • 1
    @catpants "bs=1M is much faster than the default" <-- The default of dd. Without dd even being used, you don't have to deal with its bottlenecks. – phemmer Jul 25 '14 at 22:52
4

Maybe you could put dd on the other end of the stick and try to avoid caches by using its direct and sync flags.

pv "$iso" | dd bs=1M oflag=direct,sync of=/dev/sdg

With that you should be caching at most dd's blocksize, in this case 1M... well plus whatever is in the pipe | itself I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.