1SGP_DD(8) SG3_UTILS SGP_DD(8)
2
3
4
6 sgp_dd - copy data to and from files and devices, especially SCSI
7 devices
8
10 sgp_dd [bs=BS] [count=COUNT] [ibs=BS] [if=IFILE] [iflag=FLAGS] [obs=BS]
11 [of=OFILE] [oflag=FLAGS] [seek=SEEK] [skip=SKIP] [--help] [--version]
12
13 [bpt=BPT] [coe=0|1] [cdbsz=6|10|12|16] [deb=VERB] [dio=0|1] [sync=0|1]
14 [thr=THR] [time=0|1] [verbose=VERB]
15
17 Copy data to and from any files. Specialised for "files" that are Linux
18 SCSI generic (sg) and raw devices. Similar syntax and semantics to
19 dd(1) but does not perform any conversions. Uses POSIX threads to
20 increase the amount of parallelism. This improves speed in some cases.
21
22 The first group in the synopsis above are "standard" Unix dd(1) oper‐
23 ands. The second group are extra options added by this utility. Both
24 groups are defined below.
25
27 bpt=BPT
28 each IO transaction will be made using BPT blocks (or less if
29 near the end of the copy). Default is 128 for block sizes less
30 that 2048 bytes, otherwise the default is 32. So for bs=512 the
31 reads and writes will each convey 64 KiB of data by default
32 (less if near the end of the transfer or memory restrictions).
33 When cd/dvd drives are accessed, the block size is typically
34 2048 bytes and bpt defaults to 32 which again implies 64 KiB
35 transfers.
36
37 bs=BS where BS must be the block size of the physical device. Note
38 that this differs from dd(1) which permits 'bs' to be an inte‐
39 gral multiple of the actual device block size. Default is 512
40 which is usually correct for disks but incorrect for cdroms
41 (which normally have 2048 byte blocks).
42
43 cdbsz=6 | 10 | 12 | 16
44 size of SCSI READ and/or WRITE commands issued on sg device
45 names. Default is 10 byte SCSI command blocks (unless calcula‐
46 tions indicate that a 4 byte block number may be exceeded, in
47 which case it defaults to 16 byte SCSI commands).
48
49 coe=0 | 1
50 set to 1 for continue on error. Only applies to errors on sg
51 devices. Thus errors on other files will stop sgp_dd. Default
52 is 0 which implies stop on any error. See the 'coe' flag for
53 more information.
54
55 count=COUNT
56 copy COUNT blocks from IFILE to OFILE. Default is the minimum
57 (of IFILE and OFILE) number of blocks that sg devices report
58 from SCSI READ CAPACITY commands or that block devices (or their
59 partitions) report. Normal files are not probed for their size.
60 If skip=SKIP or skip=SEEK are given and the count is deduced
61 (i.e. not explicitly given) then that count is scaled back so
62 that the copy will not overrun the device. If the file name is a
63 block device partition and COUNT is not given then the size of
64 the partition rather than the size of the whole device is used.
65 If COUNT is not given and cannot be deduced then an error mes‐
66 sage is issued and no copy takes place.
67
68 deb=VERB
69 outputs debug information. If VERB is 0 (default) then there is
70 minimal debug information and as VERB increases so does the
71 amount of debug (max debug output when VERB is 9).
72
73 dio=0 | 1
74 default is 0 which selects indirect IO. Value of 1 attempts
75 direct IO which, if not available, falls back to indirect IO and
76 notes this at completion. If direct IO is selected and
77 /proc/scsi/sg/allow_dio has the value of 0 then a warning is
78 issued (and indirect IO is performed) For finer grain control
79 use 'iflag=dio' or 'oflag=dio'.
80
81 ibs=BS if given must be the same as BS given to 'bs=' option.
82
83 if=IFILE
84 read from IFILE instead of stdin. If IFILE is '-' then stdin is
85 read. Starts reading at the beginning of IFILE unless SKIP is
86 given.
87
88 iflag=FLAGS
89 where FLAGS is a comma separated list of one or more flags out‐
90 lined below. These flags are associated with IFILE and are
91 ignored when IFILE is stdin.
92
93 obs=BS if given must be the same as BS given to 'bs=' option.
94
95 of=OFILE
96 write to OFILE instead of stdout. If OFILE is '-' then writes to
97 stdout. If OFILE is /dev/null then no actual writes are per‐
98 formed. If OFILE is '.' (period) then it is treated the same
99 way as /dev/null (this is a shorthand notation). If OFILE exists
100 then it is _not_ truncated; it is overwritten from the start of
101 OFILE unless 'oflag=append' or SEEK is given.
102
103 oflag=FLAGS
104 where FLAGS is a comma separated list of one or more flags out‐
105 lined below. These flags are associated with OFILE and are
106 ignored when OFILE is /dev/null, '.' (period), or stdout.
107
108 seek=SEEK
109 start writing SEEK bs-sized blocks from the start of OFILE.
110 Default is block 0 (i.e. start of file).
111
112 skip=SKIP
113 start reading SKIP bs-sized blocks from the start of IFILE.
114 Default is block 0 (i.e. start of file).
115
116 sync=0 | 1
117 when 1, does SYNCHRONIZE CACHE command on OFILE at the end of
118 the transfer. Only active when OFILE is a sg device file name.
119
120 thr=THR
121 where THR is the number or worker threads (default 4) that
122 attempt to copy in parallel. Minimum is 1 and maximum is 16.
123
124 time=0 | 1
125 when 1, the transfer is timed and throughput calculation is per‐
126 formed, outputting the results (to stderr) at completion. When 0
127 (default) no timing is performed.
128
129 verbose=VERB
130 increase verbosity. Same as deb=VERB. Added for compatibility
131 with sg_dd and sgm_dd.
132
133 --help outputs usage message and exits.
134
135 --version
136 outputs version number information and exits.
137
139 Here is a list of flags and their meanings:
140
141 append causes the O_APPEND flag to be added to the open of OFILE. For
142 normal files this will lead to data appended to the end of any
143 existing data. Cannot be used together with the seek=SEEK
144 option as they conflict. The default action of this utility is
145 to overwrite any existing data from the beginning of the file
146 or, if SEEK is given, starting at block SEEK. Note that attempt‐
147 ing to 'append' to a device file (e.g. a disk) will usually be
148 ignored or may cause an error to be reported.
149
150 coe continue on error. When given with 'iflag=', an error that is
151 detected in a single SCSI command (typically 'bpt' blocks) is
152 noted (by an error message sent to stderr), then zeros are sub‐
153 stituted into the buffer for the corresponding write operation
154 and the copy continues. Note that the sg_dd utility is more
155 sophisticated in such error situations when 'iflag=coe'. When
156 given with 'oflag=', any error reported by a SCSI WRITE command
157 is reported to stderr and the copy continues (as if nothing went
158 wrong).
159
160 dio request the sg device node associated with this flag does direct
161 IO. If direct IO is not available, falls back to indirect IO
162 and notes this at completion. If direct IO is selected and
163 /proc/scsi/sg/allow_dio has the value of 0 then a warning is
164 issued (and indirect IO is performed).
165
166 direct causes the O_DIRECT flag to be added to the open of IFILE and/or
167 OFILE. This flag requires some memory alignment on IO. Hence
168 user memory buffers are aligned to the page size. Has no effect
169 on sg, normal or raw files.
170
171 dpo set the DPO bit (disable page out) in SCSI READ and WRITE com‐
172 mands. Not supported for 6 byte cdb variants of READ and WRITE.
173 Indicates that data is unlikely to be required to stay in device
174 (e.g. disk) cache. May speed media copy and/or cause a media
175 copy to have less impact on other device users.
176
177 dsync causes the O_SYNC flag to be added to the open of IFILE and/or
178 OFILE. The 'd' is prepended to lower confusion with the
179 'sync=0|1' option which has another action (i.e. a synchronisa‐
180 tion to media at the end of the transfer).
181
182 excl causes the O_EXCL flag to be added to the open of IFILE and/or
183 OFILE.
184
185 fua causes the FUA (force unit access) bit to be set in SCSI READ
186 and/or WRITE commands. This only has effect with sg devices. The
187 6 byte variants of the SCSI READ and WRITE commands do not sup‐
188 port the FUA bit. Only active for sg device file names.
189
190 null has no affect, just a placeholder.
191
193 Here are some retired options that are still present:
194
195 coe=0 | 1
196 continue on error is 0 (off) by default. When it is 1, it is
197 equivalent to 'iflag=coe oflag=coe' described in the FLAGS sec‐
198 tion above. Similar to 'conv=noerror,sync' in dd(1) utility.
199 Default is 0 which implies stop on error. More advanced coe=1
200 processing on reads is performed by the sg_dd utility.
201
202
203 fua=0 | 1 | 2 | 3
204 force unit access bit. When 3, fua is set on both IFILE
205 and OFILE; when 2, fua is set on IFILE;, when 1, fua is
206 set on OFILE; when 0 (default), fua is cleared on both.
207 See the 'fua' flag.
208
210 A raw device must be bound to a block device prior to using
211 sgp_dd. See raw(8) for more information about binding raw
212 devices. To be safe, the sg device mapping to SCSI block devices
213 should be checked with 'cat /proc/scsi/scsi' before use.
214
215 Raw device partition information can often be found with
216 fdisk(8) [the "-ul" argument is useful in this respect].
217
218 Various numeric arguments (e.g. SKIP) may include multiplicative
219 suffixes or be given in hexadecimal. See the "NUMERIC ARGUMENTS"
220 section in the sg3_utils(8) man page.
221
222 The COUNT, SKIP and SEEK arguments can take 64 bit values (i.e.
223 very big numbers). Other values are limited to what can fit in a
224 signed 32 bit number.
225
226 Data usually gets to the user space in a 2 stage process: first
227 the SCSI adapter DMAs into kernel buffers and then the sg driver
228 copies this data into user memory (write operations reverse this
229 sequence). This is called "indirect IO" and there is a 'dio'
230 option to select "direct IO" which will DMA directly into user
231 memory. Due to some issues "direct IO" is disabled in the sg
232 driver and needs a configuration change to activate it.
233
234 All informative, warning and error output is sent to stderr so
235 that dd's output file can be stdout and remain unpolluted. If no
236 options are given, then the usage message is output and nothing
237 else happens.
238
239 Why use sgp_dd? Because in some cases it is twice as fast as dd
240 (mainly with sg devices, raw devices give some improvement).
241 Another reason is that big copies fill the block device caches
242 which has a negative impact on other machine activity.
243
245 The signal handling has been borrowed from dd: SIGINT, SIGQUIT
246 and SIGPIPE output the number of remaining blocks to be trans‐
247 ferred and the records in + out counts; then they have their
248 default action. SIGUSR1 causes the same information to be out‐
249 put yet the copy continues. All output caused by signals is
250 sent to stderr.
251
253 Looks quite similar in usage to dd:
254
255 sgp_dd if=/dev/sg0 of=t bs=512 count=1MB
256
257 This will copy 1 million 512 byte blocks from the device associ‐
258 ated with /dev/sg0 (which should have 512 byte blocks) to a file
259 called t. Assuming /dev/sda and /dev/sg0 are the same device
260 then the above is equivalent to:
261
262 dd if=/dev/sda of=t bs=512 count=1000000
263
264 although dd's speed may improve if bs was larger and count was
265 correspondingly scaled. Using a raw device to do something simi‐
266 lar on a ATA disk:
267
268 raw /dev/raw/raw1 /dev/hda
269 sgp_dd if=/dev/raw/raw1 of=t bs=512 count=1MB
270
271 To copy a SCSI disk partition to an ATA disk partition:
272
273 raw /dev/raw/raw2 /dev/hda3
274 sgp_dd if=/dev/sg0 skip=10123456 of=/dev/raw/raw2 bs=512
275
276 This assumes a valid partition is found on the SCSI disk at the
277 given skip block address (past the 5 GB point of that disk) and
278 that the partition goes to the end of the SCSI disk. An explicit
279 count is probably a safer option.
280
281 To do a fast copy from one SCSI disk to another one with similar
282 geometry (stepping over errors on the source disk):
283
284 sgp_dd if=/dev/sg0 of=/dev/sg1 bs=512 coe=1
285
287 The exit status of sgp_dd is 0 when it is successful. Otherwise
288 see the sg3_utils(8) man page. Since this utility works at a
289 higher level than individual commands, and there are 'coe' and
290 'retries' flags, individual SCSI command failures do not neces‐
291 sary cause the process to exit.
292
294 Written by Douglas Gilbert and Peter Allworth.
295
297 Report bugs to <dgilbert at interlog dot com>.
298
300 Copyright © 2000-2012 Douglas Gilbert
301 This software is distributed under the GPL version 2. There is
302 NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PAR‐
303 TICULAR PURPOSE.
304
306 A simpler, non-threaded version of this utility but with more
307 advanced "continue on error" logic is called sg_dd and is also
308 found in the sg3_utils package. The lmbench package contains
309 lmdd which is also interesting. raw(8), dd(1)
310
311
312
313sg3_utils-1.35 November 2012 SGP_DD(8)