1

When writing an ISO image to USB flash drive with dd, how do I know I can remove the stick? Obviously I'll wait until the command completes and I'm back at the terminal prompt. But even then the device might still be busy from a cache/buffer. Because I'm writing to the device itself, nothing is mounted, so I also don't call umount and cannot see if the device is still busy.

I've seen dd ... && sync a few times. But doesn't that block until buffers for all media have been written? Not only the one flash drive that I used dd with. So if I have lots of other write processes, wouldn't that block?

Would the conv= argument for dd help? But which one of conv=sync, conv=fsync, conv=fdatasync, ...?

finefoot
  • 3,060
  • I think most people use sync for this purpose (yes, it flushes all buffers, but that's OK in almost all cases). – sudodus Sep 13 '21 at 19:20

3 Answers3

1

Once the dd command has finished, run sudo eject /dev/sd[drive letter]. Once that has finished, you are free to remove it. The data will be sync'd.

Bib
  • 2,380
1

This answer to a related question seems to imply that conv=fdatasync is equivalent to sync for that one dd call.

finefoot
  • 3,060
  • There are short descriptions of fsync and fdatasync' inman ddand with slightly more details ininfo dd`. – sudodus Sep 13 '21 at 19:26
1

There are short descriptions of fsync and fdatasync in man dd and with slightly more details in info dd.

If I don't want to use the separate and global sync, I would use conv=fsync in ddbecause it writes both data and metadata before finishing. From info dd:

 ‘fdatasync’
      Synchronize output data just before finishing.  This forces a
      physical write of output data.

‘fsync’ Synchronize output data and metadata just before finishing. This forces a physical write of output data and metadata.

sudodus
  • 6,421