2

Is it necessary to synchronize cached writes to persistent storage with the sync command when wiping a USB, or any device, with /dev/urandom?

This is a common practice, i.e. dd if=/dev/urandom of=/dev/sdx && sync.

But is that really necessary? Is it okay to omit the sync command?

Please note this question is not referring to the conv=sync option of the dd utility, it refers to sync as a stand alone command that can also be used apart from dd. Here is a reference to sync, and here is a reference to conv=sync. Both are from https://www.kernel.org/doc/man-pages/.

Thank you

  • 1
    You can omit sync of course. Keep in mind if there is caching involved, that not all the writes are not necessarily on the medium. sync ensures that before countinuing. – stoney Jun 13 '18 at 12:12
  • Are you sure that you need /dev/urandom? I think it is good enough to wipe a USB drive or memory card with zeros from /dev/zero which is faster. And there are other tools to wipe a HDD or SSD, tools that are more efficient than dd. Ask for details, if you wish. – sudodus Jun 13 '18 at 12:21
2

sync isn’t used specifically because /dev/urandom is involved; it’s used to ensure that all pending writes have been sent to the device. This is especially important when using removable devices: running sync, and waiting for it to finish, ensures that the device can be safely removed.

When wiping a device, if you omit the sync and disconnect the device, you might not have finished wiping the device...

0

The sync() call is related to filesystems - not to devices.

If you write to a block device, sync() may cause a buffer flush, but if you use the raw device, as recommended in this case, sync() does not make sense.

WARNING: On Linux, it may be hard to find out the related raw device. Check the Linux documentation on how to get the related raw device.

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.