Command to output ones (like zero-fill), with progress indicator

Well, I was originally going to post this snippet in the original thread titled "how to output ones endlessly like /dev/zero", but that topic was closed without an efficient answer.

It was difficult to find (build) a satisfactory answer to this one, so I thought I'd share it here and as a "fill hard drive with ones like zero-fill" entry on commandlinefu.

This command seems to get me about 500MByte/min, though this is with a 1.5TB 'green' drive running only at 5400rpm so I imagine it'd be faster in most other cases.

tr '\000' '\377' < /dev/zero | dd bs=512 count=[drive bytes/512] status=noxfer | pipebench | sudo dd of=[output disk/partition, e.g. /dev/sdb]

Hope that helps someone :slight_smile:

  • Gliktch

P.S: Note that pipebench is required - this is probably available in your distro's repositories :wink:

Eight megabytes per second seems a bit slow even for a green drive, I think this can be optimized a bit.

The first dd does nothing but waste time, pipebench can read fine directly from tr. If you mean to fill the entire drive, count is redundant anyway -- dd will stop when it reaches the end. Or you could put bs and count on the final dd instead of the first.

Increasing the blocksize may make it more efficient. It doesn't need to match the drive's block size -- this isn't raw I/O.

tr '\000' '\377' < /dev/zero | pipebench | sudo dd of=/dev/wtf

It's also possible to get progress statistics from dd itself instead of using pipebench, by sending it SIGUSR1:

kill -USR1 pid