Every time I've written a file to an empty raw block device, e.g.
# dd if=image.iso of=/dev/sdb status=progress
I've never used any type of sync
(i.e. sync
; conv=fsync
; conv=fdatasync
; oflag=sync
; oflag=dsync
).
I've noticed that dd
doesn't ever exit until all writing has finished.
I always verify this using Conky's I/O facility and grep Dirty /proc/meminfo
. Also, the checksum of the device always matches that of the file that was written to it. So I am always 100% sure that the whole file was written to the device.
I've written files to an ext4 volume to compare. For example using:
$ dd if=/dev/urandom of=~/file bs=1M count=50 iflag=fullblock
When writing to an ext4 volume, after dd
exits there is always a delay of about 20 seconds before the data is actually written to the disk.
Many people advocate using the sync
command after the dd
command, or including one of the several sync
options in the dd
command when writing to a block device. E.g. here and here. However, I've not known anyone actually prove that it is necessary.
One of the comments on this page is:
sync
is pointless here [i.e. writing directly to/dev/sdX
]. It only affects file system operations.
Five people have upvoted this comment and it is consistent with my experience.
So when writing to a block device, are the any circumstances in which dd
will exit before all writing has completely finished? Has this actually ever happened to anyone?
What about other writing options, such as cp
and cat
? Can they exit before writing to a block device has finished?
sync
command and alldd
's sync options.sync
flushes filesystem metadata and cached file data to the underlying filesystem. When you're dealing with the device directly, there is no "filesystem". I suspect async
after add
is unnecessary.