I would like to copy an image to a USB thumb drive. As I would like to get "real" speeds, and don't want to wait ages for the device to sync after copying the image, I would like to know which options to use for that.
2 Answers
Reading through the source code shows that you should also be asking about the nocache
option as well. The direct
option should get you what you want, but it also depends on what version of dd
you're playing around with. Doing a large copy an an Ubuntu 11.04 system showed me even slower (=closer to reality?) times with the dsync
option uses synchronized i/o for data, which likely loses the aggregation advantage that modern disk controllers give us. To know "exactly" what's going on, you're going to have to dig into the source code for the particular kernel you're running, but even then you're at the mercy of the interface board on the drive, which does its own buffering.
-
You're not at the mercy of the drive; when the fsync() or direct write() completes, the data is on the platter.– psusiJan 30, 2012 at 16:25
-
The fsync option will flush the data at the end of the copy. The dsync option will flush the data after every block. The direct option will have similar results as dsync, only without polluting the filesystem cache with the data. This is good for caching the rest of the system, and saves some cpu overhead.
Either dsync or direct will give lower throughput, but that can be mostly offset by using a large block size, such as 1MB or more.
-
What happens when oflag=direct makes writes faster? I have an extended question about just that on serverfault.com/questions/751752/… Jan 27, 2016 at 20:29