1SG_DD(8) SG3_UTILS SG_DD(8)
2
3
4
6 sg_dd - copy data to and from files and devices, especially SCSI de‐
7 vices
8
10 sg_dd [bs=BS] [conv=CONV] [count=COUNT] [ibs=BS] [if=IFILE]
11 [iflag=FLAGS] [obs=BS] [of=OFILE] [oflag=FLAGS] [seek=SEEK] [skip=SKIP]
12 [--help] [--verbose] [--version]
13
14 [blk_sgio={0|1}] [bpt=BPT] [cdbsz={6|10|12|16}] [cdl=CDL]
15 [coe={0|1|2|3}] [coe_limit=CL] [dio={0|1}] [odir={0|1}] [of2=OFILE2]
16 [retries=RETR] [sync={0|1}] [time={0|1}[,TO]] [verbose=VERB]
17 [--dry-run] [--progress] [--verify]
18
20 Copy data to and from any files. Specialized for "files" that are Linux
21 SCSI generic (sg) devices, raw devices or other devices that support
22 the SG_IO ioctl (which are only found in the lk 2.6 series). Similar
23 syntax and semantics to dd(1) command.
24
25 The first group in the synopsis above are "standard" Unix dd(1) oper‐
26 ands. The second group are extra options added by this utility. Both
27 groups are defined below.
28
29 When the --verify option is given, then the read side is the same but
30 the on the write side, the WRITE SCSI command is replaced by the VERIFY
31 SCSI command. If any VERIFY commands yields a sense key of MISCOMPARE
32 then the verify operation will stop. The --verify option can only be
33 used when OFILE is either a sg device or a block device with oflag=sgio
34 also given. When the --verify option is used, this utility works in a
35 similar fashion to the Unix cmp(1) command.
36
37 This utility is only supported on Linux whereas most other utilities in
38 the sg3_utils package have been ported to other operating systems. A
39 utility called "ddpt" has similar syntax and functionality to sg_dd.
40 ddpt drops some Linux specific features while adding some other generic
41 features. This allows ddpt to be ported to other operating systems.
42
44 blk_sgio={0|1}
45 when set to 0, block devices (e.g. /dev/sda) are treated like
46 normal files (i.e. read(2) and write(2) are used for IO). When
47 set to 1, block devices are assumed to accept the SG_IO ioctl
48 and SCSI commands are issued for IO. This is only supported for
49 2.6 series kernels. Note that ATAPI devices (e.g. cd/dvd play‐
50 ers) use the SCSI command set but ATA disks do not (unless there
51 is a protocol conversion as often occurs in the USB mass storage
52 class). If the input or output device is a block device parti‐
53 tion (e.g. /dev/sda3) then setting this option causes the parti‐
54 tion information to be ignored (since access is directly to the
55 underlying device). Default is 0. See the 'sgio' flag.
56
57 bpt=BPT
58 each IO transaction will be made using BPT blocks (or less if
59 near the end of the copy). Default is 128 for logical block
60 sizes less that 2048 bytes, otherwise the default is 32. So for
61 bs=512 the reads and writes will each convey 64 KiB of data by
62 default (less if near the end of the transfer or memory restric‐
63 tions). When cd/dvd drives are accessed, the logical block size
64 is typically 2048 bytes and bpt defaults to 32 which again im‐
65 plies 64 KiB transfers. The block layer when the blk_sgio=1 op‐
66 tion is used has relatively low upper limits for transfer sizes
67 (compared to sg device nodes, see
68 /sys/block/<dev_name>/queue/max_sectors_kb ).
69
70 bs=BS where BS must be the logical block size of the physical device
71 (if either the input or output files are accessed via SCSI com‐
72 mands). Note that this differs from dd(1) which permits BS to be
73 an integral multiple. Default is 512 which is usually correct
74 for disks but incorrect for cdroms (which normally have 2048
75 byte blocks). For this utility the maximum size of each individ‐
76 ual IO operation is BS * BPT bytes.
77
78 cdbsz={6|10|12|16}
79 size of SCSI READ and/or WRITE commands issued on sg device
80 names (or block devices when 'iflag=sgio' and/or 'oflag=sgio' is
81 given). Default is 10 byte SCSI command blocks (unless calcula‐
82 tions indicate that a 4 byte block number may be exceeded or BPT
83 is greater than 16 bits (65535), in which case it defaults to 16
84 byte SCSI commands).
85
86 cdl=CDL
87 allows setting of command duration limits. CDL is either a sin‐
88 gle value or two values separated by a comma. If one value is
89 given, it applies to both IFILE and OFILE (if they are
90 pass-through devices). If two values are given, the first ap‐
91 plies to IFILE while the second applies to OFILE. The value may
92 be from 0 to 7 where 0 is the default and means there are no
93 command duration limits. Command duration limits are only sup‐
94 ported by 16 byte READ and WRITE commands (plus READ(32),
95 WRITE(32) and the WRITE SCATTERED command, bit thay are used by
96 this utility). If the cdbsz operand is not given and would have
97 a value less than 16, then if CDL is greater than 0, the cdbsz
98 is increased to 16.
99 Command duration limits can be accesses and changed in the Com‐
100 mand duration limit A and B mode pages, plus the Command dura‐
101 tion limit T2A and T2B mode pages. The sdparm utility may be
102 used to access and change these mode pages.
103
104 coe={0|1|2|3}
105 set to 1 or more for continue on error ('coe'). Only applies to
106 errors on sg devices or block devices with the 'sgio' flag set.
107 Thus errors on other files will stop sg_dd. Default is 0 which
108 implies stop on any error. See the 'coe' flag for more informa‐
109 tion.
110
111 coe_limit=CL
112 where CL is the maximum number of consecutive bad blocks stepped
113 over (due to "coe>0") on reads before the copy terminates. This
114 only applies when IFILE is accessed via the SG_IO ioctl. The de‐
115 fault is 0 which is interpreted as no limit. This option is
116 meant to stop the copy soon after unrecorded media is detected
117 while still offering "continue on error" capability.
118
119 conv=sparse
120 see the CONVERSIONS section below.
121
122 count=COUNT
123 copy COUNT blocks from IFILE to OFILE. Default is the minimum
124 (of IFILE and OFILE) number of blocks that sg devices report
125 from SCSI READ CAPACITY commands or that block devices (or their
126 partitions) report. Normal files are not probed for their size.
127 If skip=SKIP or seek=SEEK are given and the count is derived
128 (i.e. not explicitly given) then the derived count is scaled
129 back so that the copy will not overrun the device. If the file
130 name is a block device partition and COUNT is not given then the
131 size of the partition rather than the size of the whole device
132 is used. If COUNT is not given (or count=-1) and cannot be de‐
133 rived then an error message is issued and no copy takes place.
134
135 dio={0|1}
136 default is 0 which selects indirect (buffered) IO on sg devices.
137 Value of 1 attempts direct IO which, if not available, falls
138 back to indirect IO and notes this at completion. If direct IO
139 is selected and /proc/scsi/sg/allow_dio has the value of 0 then
140 a warning is issued (and indirect IO is performed). For finer
141 grain control use 'iflag=dio' or 'oflag=dio'.
142
143 ibs=BS if given must be the same as BS given to 'bs=' option.
144
145 if=IFILE
146 read from IFILE instead of stdin. If IFILE is '-' then stdin is
147 read. Starts reading at the beginning of IFILE unless SKIP is
148 given.
149
150 iflag=FLAGS
151 where FLAGS is a comma separated list of one or more flags out‐
152 lined below. These flags are associated with IFILE and are ig‐
153 nored when IFILE is stdin.
154
155 obs=BS if given must be the same as BS given to 'bs=' option.
156
157 odir={0|1}
158 when set to one opens block devices (e.g. /dev/sda) with the
159 O_DIRECT flag. User memory buffers are aligned to the page size
160 when set. The default is 0 (i.e. the O_DIRECT flag is not used).
161 Has no effect on sg, normal or raw files. If blk_sgio is also
162 set then both are honoured: block devices are opened with the
163 O_DIRECT flag and SCSI commands are issued via the SG_IO ioctl.
164
165 of=OFILE
166 write to OFILE instead of stdout. If OFILE is '-' then writes to
167 stdout. If OFILE is /dev/null then no actual writes are per‐
168 formed. If OFILE is '.' (period) then it is treated the same
169 way as /dev/null (this is a shorthand notation). If OFILE exists
170 then it is _not_ truncated; it is overwritten from the start of
171 OFILE unless 'oflag=append' or SEEK is given.
172
173 of2=OFILE2
174 write output to OFILE2. The default action is not to do this ad‐
175 ditional write (i.e. when this option is not given). OFILE2 is
176 assumed to be a normal file or a fifo (i.e. a named pipe).
177 OFILE2 is opened for writing, created if necessary, and closed
178 at the end of the transfer. If OFILE2 is a fifo (named pipe)
179 then some other command should be consuming that data (e.g.
180 'md5sum OFILE2'), otherwise this utility will block.
181
182 oflag=FLAGS
183 where FLAGS is a comma separated list of one or more flags out‐
184 lined below. These flags are associated with OFILE and are ig‐
185 nored when OFILE is /dev/null, '.' (period), or stdout.
186
187 retries=RETR
188 sometimes retries at the host are useful, for example when there
189 is a transport error. When RETR is greater than zero then SCSI
190 READs and WRITEs are retried on error, RETR times. Default value
191 is zero.
192
193 seek=SEEK
194 start writing SEEK bs-sized blocks from the start of OFILE. De‐
195 fault is block 0 (i.e. start of file).
196
197 skip=SKIP
198 start reading SKIP bs-sized blocks from the start of IFILE. De‐
199 fault is block 0 (i.e. start of file).
200
201 sync={0|1}
202 when 1, does SYNCHRONIZE CACHE command on OFILE at the end of
203 the transfer. Only active when OFILE is a sg device file name or
204 a block device and 'blk_sgio=1' is given.
205
206 time={0|1}[,TO]
207 when 1, times transfer and does throughput calculation, out‐
208 putting the results (to stderr) at completion. When 0 (default)
209 doesn't perform timing.
210 If that value is followed by a comma, then TO is the command
211 timeout in seconds for SCSI READ, WRITE or VERIFY commands is‐
212 sued by this utility. The default is 60 seconds.
213
214 verbose=VERB
215 as VERB increases so does the amount of debug output sent to
216 stderr. Default value is zero which yields the minimum amount
217 of debug output. A value of 1 reports extra information that is
218 not repetitive. A value 2 reports cdbs and responses for SCSI
219 commands that are not repetitive (i.e. other that READ and
220 WRITE). Error processing is not considered repetitive. Values of
221 3 and 4 yield output for all SCSI commands (and Unix read() and
222 write() calls) so there can be a lot of output. This only oc‐
223 curs for scsi generic (sg) devices and block devices when the
224 'blk_sgio=1' option is set.
225
226 -d, --dry-run
227 does all the command line parsing and preparation but bypasses
228 the actual copy or read. That preparation may include opening
229 IFILE or OFILE to determine their lengths. This option may be
230 useful for testing the syntax of complex command line invoca‐
231 tions in advance of executing them.
232
233 -h, --help
234 outputs usage message and exits.
235
236 -p, --progress
237 this option causes a progress report to be output every two min‐
238 utes until the copy is complete. After the copy is complete a
239 line with "completed" is printed to distinguish the final report
240 from the prior progress reports. When used twice the progress
241 report is every minute, when used three times the progress re‐
242 port is every 30 seconds.
243
244 -v, --verbose
245 when used once, this is equivalent to verbose=1. When used twice
246 (e.g. "-vv") this is equivalent to verbose=2, etc.
247
248 -x, --verify
249 do a verify operation (like Unix command cmp(1)) rather than a
250 copy. Cannot be used with "oflag=sparse". of=OFILE must be given
251 and OFILE must be an sg device or a block device with
252 "oflag=sgio" also given. Uses the SCSI VERIFY command with the
253 BYTCHK field set to 1. The VERIFY command is used instead of
254 WRITE when this option is given. There is no VERIFY(6) command.
255 Stops on the first miscompare unless oflag=coe is given.
256
257 -V, --version
258 outputs version number information and exits.
259
261 One or more conversions can be given to the "conv=" option. If more
262 than one is given, they should be comma separated. sg_dd does not per‐
263 form the traditional dd conversions (e.g. ASCII to EBCDIC). Recently
264 added conversions overlap somewhat with the flags so some conversions
265 are now supported by sg_dd.
266
267 nocreat
268 this conversion has the same effect as "oflag=nocreat", namely:
269 OFILE must exist, it will not be created.
270
271 noerror
272 this conversion is very close to "iflag=coe" and is treated as
273 such. See the "coe" flag. Note that an error on OFILE will stop
274 the copy.
275
276 notrunc
277 this conversion is accepted for compatibility with dd and ig‐
278 nored since the default action of this utility is not to trun‐
279 cate OFILE.
280
281 null has no affect, just a placeholder.
282
283 sparse FreeBSD supports "conv=sparse" so the same syntax is supported
284 in sg_dd. See "sparse" in the FLAGS sections for more informa‐
285 tion.
286
287 sync is ignored by sg_dd. With dd it means supply zero fill (rather
288 than skip) and is typically used like this "conv=noerror,sync"
289 to have the same functionality as sg_dd's "iflag=coe".
290
292 Here is a list of flags and their meanings:
293
294 00 this flag is only active with iflag= and when given replaces
295 if=IFILE. If both are given an error is generated. The input
296 will be a stream of zeros, similar to using "if=/dev/zero" alone
297 (but a little quicker).
298
299 append causes the O_APPEND flag to be added to the open of OFILE. For
300 regular files this will lead to data appended to the end of any
301 existing data. Cannot be used together with the seek=SEEK option
302 as they conflict. The default action of this utility is to over‐
303 write any existing data from the beginning of the file or, if
304 SEEK is given, starting at block SEEK. Note that attempting to
305 'append' to a device file (e.g. a disk) will usually be ignored
306 or may cause an error to be reported.
307
308 coe continue on error. Only active for sg devices and block devices
309 that have the 'sgio' flag set. 'iflag=coe oflag=coe' and 'coe=1'
310 are equivalent. Use this flag twice (e.g. 'iflag=coe,coe') to
311 have the same action as the 'coe=2'. A medium, hardware or
312 blank check error while reading will re-read blocks prior to the
313 bad block, then try to recover the bad block, supplying zeros if
314 that fails, and finally re-read the blocks after the bad block.
315 A medium, hardware or blank check error while writing is noted
316 and ignored. A miscompare sense key during a VERIFY command
317 (i.e. --verify given) is noted and ignored when 'oflag=coe'. The
318 recovery of the bad block when reading uses the SCSI READ LONG
319 command if 'coe' given twice or more (also with the command line
320 option 'coe=2'). Further, the READ LONG will set its CORRCT bit
321 if 'coe' given thrice. SCSI disks may automatically try and
322 remap faulty sectors (see the AWRE and ARRE in the read write
323 error recovery mode page (the sdparm utility can access and pos‐
324 sibly change these attributes)). Errors occurring on other files
325 types will stop sg_dd. Error messages are sent to stderr. This
326 flag is similar to 'conv=noerror,sync' in the dd(1) utility. See
327 note about READ LONG below.
328
329 dio request the sg device node associated with this flag does direct
330 IO. If direct IO is not available, falls back to indirect IO and
331 notes this at completion. If direct IO is selected and
332 /proc/scsi/sg/allow_dio has the value of 0 then a warning is is‐
333 sued (and indirect IO is performed).
334
335 direct causes the O_DIRECT flag to be added to the open of IFILE and/or
336 OFILE. This flag requires some memory alignment on IO. Hence
337 user memory buffers are aligned to the page size. Has no effect
338 on sg, normal or raw files. If 'iflag=sgio' and/or 'oflag=sgio'
339 is also set then both are honoured: block devices are opened
340 with the O_DIRECT flag and SCSI commands are issued via the
341 SG_IO ioctl.
342
343 dpo set the DPO bit (disable page out) in SCSI READ and WRITE com‐
344 mands. Not supported for 6 byte cdb variants of READ and WRITE.
345 Indicates that data is unlikely to be required to stay in device
346 (e.g. disk) cache. May speed media copy and/or cause a media
347 copy to have less impact on other device users.
348
349 dsync causes the O_SYNC flag to be added to the open of IFILE and/or
350 OFILE. The 'd' is prepended to lower confusion with the
351 'sync=0|1' option which has another action (i.e. a synchronisa‐
352 tion to media at the end of the transfer).
353
354 excl causes the O_EXCL flag to be added to the open of IFILE and/or
355 OFILE.
356
357 ff this flag is only active with iflag= and when given replaces
358 if=IFILE. If both are given an error is generated. The input
359 will be a stream of 0xff bytes (or all bits set).
360
361 flock after opening the associated file (i.e. IFILE and/or OFILE) an
362 attempt is made to get an advisory exclusive lock with the
363 flock() system call. The flock arguments are "FLOCK_EX |
364 FLOCK_NB" which will cause the lock to be taken if available
365 else a "temporarily unavailable" error is generated. An exit
366 status of 90 is produced in the latter case and no copy is done.
367
368 fua causes the FUA (force unit access) bit to be set in SCSI READ
369 and/or WRITE commands. This only has an effect with sg devices
370 or block devices that have the 'sgio' flag set. The 6 byte vari‐
371 ants of the SCSI READ and WRITE commands do not support the FUA
372 bit.
373
374 nocache
375 use posix_fadvise() to advise corresponding file there is no
376 need to fill the file buffer with recently read or written
377 blocks.
378
379 nocreat
380 this flag is only active in oflag=FLAGS. If present then OFILE
381 will be opened if it exists. If OFILE doesn't exist then an er‐
382 ror is generated. Without this flag a regular (empty) file named
383 OFILE will be created (and then filled). For production quality
384 scripts where OFILE is a device node (e.g. '/dev/sdc') this flag
385 is recommended. It guards against the remote possibility of
386 'dev/sdc' disappearing temporarily (e.g. a USB memory key re‐
387 moved) resulting in a large regular file called '/dev/sdc' being
388 created.
389
390 null has no affect, just a placeholder.
391
392 random this flag is only active with iflag= and when given replaces
393 if=IFILE. If both are given an error is generated. The input
394 will be a stream of pseudo random bytes. The Linux getrandom(2)
395 system call is used to create a seed and thereadter mrand48_r(3)
396 is used to generate a pseudo random sequence, 4 bytes at a time.
397 The quality of the randomness can be viewed with the ent(1)
398 utility. This is not a high quality random number generator, it
399 is built for speed, not quality. One application is checking the
400 correctness of the copy and verify operations of this utility.
401
402 sgio causes block devices to be accessed via the SG_IO ioctl rather
403 than standard UNIX read() and write() commands. When the SG_IO
404 ioctl is used the SCSI READ and WRITE commands are used directly
405 to move data. sg devices always use the SG_IO ioctl. This flag
406 offers finer grain control compared to the otherwise identical
407 'blk_sgio=1' option.
408
409 sparse after each BS * BPT byte segment is read from the input, it is
410 checked for being all zeros. If so, nothing is written to the
411 output file unless this is the last segment of the transfer.
412 This flag is only active with the oflag option. It cannot be
413 used when the output is not seekable (e.g. stdout). It is ig‐
414 nored if the output file is /dev/null . Note that this utility
415 does not remove the OFILE prior to starting to write to it.
416 Hence it may be advantageous to manually remove the OFILE if it
417 is large prior to using oflag=sparse. The last segment is always
418 written so regular files will show the same length and so pro‐
419 grams like md5sum and sha1sum will generate the same value re‐
420 gardless of whether oflag=sparse is given or not. This option
421 may be used when the OFILE is a raw device but is probably only
422 useful if the device is known to contain zeros (e.g. a SCSI disk
423 after a FORMAT command).
424
426 Here are some retired options that are still present:
427
428 append=0 | 1
429 when set, equivalent to 'oflag=append'. When clear the action is
430 to overwrite the existing file (if it exists); this is the de‐
431 fault. See the 'append' flag.
432
433 fua=0 | 1 | 2 | 3
434 force unit access bit. When 3, fua is set on both IFILE and
435 OFILE; when 2, fua is set on IFILE;, when 1, fua is set on
436 OFILE; when 0 (default), fua is cleared on both. See the 'fua'
437 flag.
438
440 Block devices (e.g. /dev/sda and /dev/hda) can be given for IFILE. If
441 neither '-iflag=direct', 'iflag=sgio' nor 'blk_sgio=1' is given then
442 normal block IO involving buffering and caching is performed. If only
443 '-iflag=direct' is given then the buffering and caching is bypassed
444 (this is applicable to both SCSI devices and ATA disks). If
445 'iflag=sgio' or 'blk_sgio=1' is given then the SG_IO ioctl is used on
446 the given file causing SCSI commands to be sent to the device and that
447 also bypasses most of the actions performed by the block layer (this is
448 only applicable to SCSI devices, not ATA disks). The same applies for
449 block devices given for OFILE.
450
451 Various numeric arguments (e.g. SKIP) may include multiplicative suf‐
452 fixes or be given in hexadecimal. See the "NUMERIC ARGUMENTS" section
453 in the sg3_utils(8) man page.
454
455 The COUNT, SKIP and SEEK arguments can take 64 bit values (i.e. very
456 big numbers). Other values are limited to what can fit in a signed 32
457 bit number.
458
459 Data usually gets to the user space in a 2 stage process: first the
460 SCSI adapter DMAs into kernel buffers and then the sg driver copies
461 this data into user memory (write operations reverse this sequence).
462 This is called "indirect IO" and there is a 'dio' option to select "di‐
463 rect IO" which will DMA directly into user memory. Due to some issues
464 "direct IO" is disabled in the sg driver and needs a configuration
465 change to activate it. This is typically done with 'echo 1 >
466 /proc/scsi/sg/allow_dio'.
467
468 All informative, warning and error output is sent to stderr so that
469 dd's output file can be stdout and remain unpolluted. If no options are
470 given, then the usage message is output and nothing else happens.
471
472 Even if READ LONG succeeds on a "bad" block when 'coe=2' (or 'coe=3')
473 is given, the recovered data may not be useful. There are no guarantees
474 that the user data will appear "as is" in the first 512 bytes.
475
476 A raw device must be bound to a block device prior to using sg_dd. See
477 raw(8) for more information about binding raw devices. To be safe, the
478 sg device mapping to SCSI block devices should be checked with 'cat
479 /proc/scsi/scsi', or sg_map before use.
480
481 Disk partition information can often be found with fdisk(8) [the "-ul"
482 argument is useful in this respect].
483
484 For sg devices (and block devices when blk_sgio=1 is given) this util‐
485 ity issues SCSI READ and WRITE (SBC) commands which are appropriate for
486 disks and reading from CD/DVD/HD-DVD/BD drives. Those commands are not
487 formatted correctly for tape devices so sg_dd should not be used on
488 tape devices. If the largest block address of the requested transfer
489 exceeds a 32 bit block number (i.e 0xffff) then a warning is issued and
490 the sg device is accessed via SCSI READ(16) and WRITE(16) commands.
491
492 The attributes of a block device (partition) are ignored when
493 'blk_sgio=1' is used. Hence the whole device is read (rather than just
494 the second partition) by this invocation:
495
496 sg_dd if=/dev/sdb2 blk_sgio=1 of=t bs=512
497
499 Looks quite similar in usage to dd:
500
501 sg_dd if=/dev/sg0 of=t bs=512 count=1MB
502
503 This will copy 1 million 512 byte blocks from the device associated
504 with /dev/sg0 (which should have 512 byte blocks) to a file called t.
505 Assuming /dev/sda and /dev/sg0 are the same device then the above is
506 equivalent to:
507
508 dd if=/dev/sda iflag=direct of=t bs=512 count=1000000
509
510 although dd's speed may improve if bs was larger and count was suitably
511 reduced. The use of the 'iflag=direct' option bypasses the buffering
512 and caching that is usually done on a block device.
513
514 Using a raw device to do something similar on a ATA disk:
515
516 raw /dev/raw/raw1 /dev/hda
517 sg_dd if=/dev/raw/raw1 of=t bs=512 count=1MB
518
519 To copy a SCSI disk partition to an ATA disk partition:
520
521 raw /dev/raw/raw2 /dev/hda3
522 sg_dd if=/dev/sg0 skip=10123456 of=/dev/raw/raw2 bs=512
523
524 This assumes a valid partition is found on the SCSI disk at the given
525 skip block address (past the 5 GB point of that disk) and that the par‐
526 tition goes to the end of the SCSI disk. An explicit count is probably
527 a safer option. The partition is copied to /dev/hda3 which is an offset
528 into the ATA disk /dev/hda . The exact number of blocks read from
529 /dev/sg0 are written to /dev/hda (i.e. no padding).
530
531 To time a streaming read of the first 1 GB (2 ** 30 bytes) on a disk
532 this utility could be used:
533
534 sg_dd if=/dev/sg0 of=/dev/null bs=512 count=2m time=1
535
536 On completion this will output a line like: "time to transfer data was
537 18.779506 secs, 57.18 MB/sec". The "MB/sec" in this case is 1,000,000
538 bytes per second.
539
540 The 'of2=' option can be used to copy data and take a md5sum of it
541 without needing to re-read the data:
542
543 mkfifo fif
544 md5sum fif &
545 sg_dd if=/dev/sg3 iflag=coe of=sg3.img oflag=sparse of2=fif bs=512
546
547 This will image /dev/sg3 (e.g. an unmounted disk) and place the con‐
548 tents in the (sparse) file sg3.img . Without re-reading the data it
549 will also perform a md5sum calculation on the image.
550
552 The signal handling has been borrowed from dd: SIGINT, SIGQUIT and SIG‐
553 PIPE output the number of remaining blocks to be transferred and the
554 records in + out counts; then they have their default action. SIGUSR1
555 causes the same information to be output yet the copy continues. All
556 output caused by signals is sent to stderr.
557
559 The exit status of sg_dd is 0 when it is successful. Otherwise see the
560 sg3_utils(8) man page. Since this utility works at a higher level than
561 individual commands, and there are 'coe' and 'retries' flags, individ‐
562 ual SCSI command failures do not necessary cause the process to exit.
563
564 An additional exit status of 90 is generated if the flock flag is given
565 and some other process holds the advisory exclusive lock.
566
568 Written by Douglas Gilbert and Peter Allworth.
569
571 Report bugs to <dgilbert at interlog dot com>.
572
574 Copyright © 2000-2021 Douglas Gilbert
575 This software is distributed under the GPL version 2. There is NO war‐
576 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
577 POSE.
578
580 cmp(1)
581
582 There is a web page discussing sg_dd at
583 http://sg.danny.cz/sg/sg_dd.html
584
585 A POSIX threads version of this utility called sgp_dd is in the
586 sg3_utils package. Another version from that package is called sgm_dd
587 and it uses memory mapped IO to speed transfers from sg devices.
588
589 The lmbench package contains lmdd which is also interesting. For moving
590 data to and from tapes see dt which is found at http://www.scsi‐
591 faq.org/RMiller_Tools/index.html
592
593 To change mode parameters that effect a SCSI device's caching and error
594 recovery see sdparm(sdparm)
595
596 To verify the data on the media or to verify it against some other copy
597 of the data see sg_verify(sg3_utils)
598
599 See also raw(8), dd(1), ddrescue(GNU), ddpt
600
601
602
603sg3_utils-1.46 March 2021 SG_DD(8)