1SG_FORMAT(8) SG3_UTILS SG_FORMAT(8)
2
3
4
6 sg_format - format, format with preset, resize SCSI disk; format tape
7
9 sg_format [--cmplst={0|1}] [--count=COUNT] [--dcrt] [--dry-run]
10 [--early] [--ffmt=FFMT] [--fmtmaxlba-fmtpinfo=FPI] [--format] [--help]
11 [--ip-def] [--long] [--mode=MP] [--pfu=PFU] [--pie=PIE] [--pinfo]
12 [--poll=PT] [--preset=ID] [--quick] [--resize] [--rto_req] [--security]
13 [--six] [--size=LB_SZ] [--tape=FM] [--timeout=SECS] [--verbose] [--ver‐
14 ify] [--version] [--wait] DEVICE
15
17 Not all SCSI direct access devices need to be formatted and some have
18 vendor specific formatting procedures. SCSI disks with rotating media
19 are probably the largest group that do support a 'standard' format
20 operation. They are typically factory formatted to a block size of 512
21 bytes with the largest number of blocks that the manufacturer recom‐
22 mends. The manufacturer's recommendation typically leaves aside a cer‐
23 tain number of tracks, spread across the media, for reassignment of
24 blocks to logical block addresses during the life of the disk.
25
26 This utility issues one of three SCSI format commands: FORMAT UNIT,
27 FORMAT MEDIUM or FORMAT WITH PRESET. In the following description,
28 unqualified sections will usually be referring to the SCSI FORMAT UNIT
29 command. Both FORMAT UNIT and FORMAT WITH PRESET apply to disks (or
30 disk-like devices). The FORMAT MEDIUM command is for tapes.
31
32 This utility can format modern SCSI disks and potentially change their
33 block size (if permitted) and the block count (i.e. number of accessi‐
34 ble blocks on the media also known as "resizing"). Resizing a disk to
35 less than the manufacturer's recommended block count is sometimes
36 called "short stroking" (see NOTES section). Resizing the block count
37 while not changing the block size may not require a format operation.
38 The SBC-2 standard (see www.t10.org) has obsoleted the "format device"
39 mode page. Many of the low level details found in that mode page are
40 now left up to the discretion of the manufacturer. There is a Format
41 Status log page which reports on the previous successful format opera‐
42 tion(s).
43
44 When this utility is used without options (i.e. it is only given a
45 DEVICE argument) it prints out the existing block size and block count
46 derived from two sources. These two sources are a block descriptor in
47 the response to a MODE SENSE command and the response to a READ CAPAC‐
48 ITY command. The reason for this double check is to detect a "format
49 corrupt" state (see the NOTES section). This usage will not modify the
50 disk.
51
52 When this utility is used with either --format, --preset=ID or
53 --tape=FM, it will attempt to format the given DEVICE. In the absence
54 of the --quick option there is a 15 second pause during which time the
55 user is invited thrice (5 seconds apart) to abort sg_format. This
56 occurs just prior the SCSI FORMAT UNIT, FORMAT WITH PRESET or FORMAT
57 MEDIUM command being issued. See the NOTES section for more informa‐
58 tion.
59
60 Protection information (PI) is optional and is made up of one or more
61 protection intervals, each made up of 8 bytes associated with a logical
62 block. When PI is active each logical block will have 1, 2, 4, 8, etc
63 protection intervals (i.e. a power of two), interleaved with (and fol‐
64 lowing) the user data to which they refer. Four protection types are
65 defined with protection type 0 being no protection intervals. See the
66 PROTECTION INFORMATION section below for more information.
67
68 When the --tape=FM option is given then the SCSI FORMAT MEDIUM command
69 is sent to the DEVICE. FORMAT MEDIUM is defined in the SSC documents at
70 T10 and prepares a volume for use. That may include partitioning the
71 medium. See the section below on TAPE for more information.
72
73 The FORMAT WITH PRESET was added in draft SBC-4 revision 18. A preset
74 pattern, selected by the PRESET IDENTIFIER field (--id=FWPID), is writ‐
75 ten to the disk. See the FORMAT PRESETS VPD page (0xb8) for a list of
76 available Format preset identifiers and their associated data.
77
79 Arguments to long options are mandatory for short options as well. The
80 options are arranged in alphabetical order based on the long option
81 name.
82
83 -C, --cmplst={0|1}
84 sets the CMPLST ("complete list") bit in the FORMAT UNIT cdb to
85 0 or 1. If the value is 0 then the existing GLIST (grown list)
86 is taken into account. If the value is 1 then the existing
87 GLIST is ignored. CMPLST defaults to 1 apart from when the
88 --ffmt=FFMT option's value is non-zero in which case CMPLST
89 defaults to 0. See the LISTS section below. In most cases this
90 bit should be left at its default value.
91
92 -c, --count=COUNT
93 where COUNT is the number of blocks to be formatted or media to
94 be resized to. Can be used with either --format or --resize.
95 With --format this option need not be given in which case it is
96 assumed to be zero.
97 With --format the interpretation of COUNT is:
98 (COUNT > 0) : only format the first COUNT blocks and READ
99 CAPACITY will report COUNT blocks after format
100 (COUNT = 0) and block size unchanged : use existing block
101 count
102 (COUNT = 0) and block size changed : recommended maximum block
103 count for new block size
104 (COUNT = -1) : use recommended maximum block count
105 (COUNT < -1) : illegal
106 With --resize this option must be given and COUNT has this
107 interpretation:
108 (COUNT > 0) : after resize READ CAPACITY will report COUNT
109 blocks
110 (COUNT = 0) : after resize READ CAPACITY will report 0 blocks
111 (COUNT = -1) : after resize READ CAPACITY will report its max‐
112 imum number of blocks
113 (COUNT < -1) : illegal
114 In both cases if the given COUNT exceeds the maximum number of
115 blocks (for the block size) then the disk reports an error. See
116 NOTES section below.
117
118 -D, --dcrt
119 this option sets the DCRT bit in the FORMAT UNIT command's
120 parameter list header. It will "disable certification". Certifi‐
121 cation verifies that blocks are usable during the format
122 process. Using this option may speed the format but --ffmt=FFMT,
123 if available, would probably be better. The default action of
124 this utility (i.e. when this option is not given) is to clear
125 the DCRT bit thereby requesting "media certification" (also
126 unless another option needs it, the FOV bit will be cleared).
127 When the DCRT bit is set, the FOV bit must also be set hence
128 sg_format does that.
129 If this option is given twice then certification is enabled by
130 clearing the DCRT bit and setting the FOV bit. Both these bits
131 are found in the parameter list associated with the FORMAT UNIT
132 cdb.
133
134 -d, --dry-run
135 this option will parse the command line, do all the preparation
136 but bypass the actual FORMAT UNIT, FORMAT WITH PRESET or FORMAT
137 MEDIUM command. Also if the options would otherwise cause the
138 logical block size to change, then the MODE SELECT command that
139 would do that is also bypassed when the dry run option is given.
140
141 -e, --early
142 during a format operation, The default action of this utility is
143 to poll the disk every 60 seconds (or every 10 seconds if FFMT
144 is non-zero) to determine the progress of the format operation
145 until it is finished. When this option is given this utility
146 will exit "early", that is as soon as the format operation has
147 commenced. Then the user can monitor the progress of the ongoing
148 format operation with other utilities (e.g. sg_turs(8) or
149 sg_requests(8)). This option and --wait are mutually exclusive.
150
151 -t, --ffmt=FFMT
152 FFMT (fast format) is placed in a field of the same name in the
153 FORMAT UNIT cdb. The field was introduced in SBC-4 revision 10.
154 The default value is 0 which implies the former action which is
155 typically to overwrite all blocks on the DEVICE. That can take a
156 long time (e.g. with hard disks over 10 TB in size that can be
157 days). With FFMT set that time may be reduced to minutes or
158 less. So it is worth trying if it is available.
159 FFMT has values 1 and 2 for fast format with 3 being reserved
160 currently. These two values include this description: "The
161 device server initializes the medium ... without overwriting the
162 medium (i.e. resources for managing medium access are initial‐
163 ized and the medium is not written)". The difference between 1
164 and 2 concerns read operations on LBAs to which no data has been
165 written to, after the fast format. When FFMT is 1 the read oper‐
166 ation should return "unspecified logical block data" and com‐
167 plete without error. When FFMT is 2 the read operation may yield
168 check condition status with a sense key set to hardware error,
169 medium error or command aborted. See draft SBC-4 revision 16
170 section 4.34 for more details.
171
172 -b, --fmtmaxlba
173 This option is only active if it is given together with the
174 --preset=ID option. If so it sets the FMTMAXLBA field in the
175 FORMAT WITH PRESET command.
176
177 -f, --fmtpinfo=FPI
178 sets the FMTPINFO field in the FORMAT UNIT cdb to a value
179 between 0 and 3. The default value is 0. The FMTPINFO field
180 from SBC-3 revision 16 is a 2 bit field (bits 7 and 6 of byte 1
181 in the cdb). Prior to that revision it was a single bit field
182 (bit 7 of byte 1 in the cdb) and there was an accompanying bit
183 called RTO_REQ (bit 6 of byte 1 in the cdb). The deprecated
184 options "--pinfo" and "--rto-req" represent the older usage.
185 This option should be used in their place. See the PROTECTION
186 INFORMATION section below for more information.
187
188 -F, --format
189 issue one of the three SCSI "format" commands. In the absence of
190 the --preset=ID and --tape=FM options, the SCSI FORMAT UNIT com‐
191 mand is issued. These commands will destroy all the data held
192 on the media. This option is required to change the block size
193 of a disk. In the absence of the --quick option, the user is
194 given a 15 second count down to ponder the wisdom of doing this,
195 during which time control-C (amongst other Unix commands) can be
196 used to kill this process before it does any damage.
197 When used three times (or more) the preliminary MODE SENSE and
198 SELECT commands are bypassed, leaving only the initial INQUIRY
199 and FORMAT UNIT commands. This is for emergency use (e.g. when
200 the MODE SENSE/SELECT commands are not working) and cannot
201 change the logical block size.
202 See NOTES section for implementation details and EXAMPLES sec‐
203 tion for typical use.
204
205 -h, --help
206 print out the usage information then exit.
207
208 -I, --ip-def
209 sets the default Initialization Pattern. Some disks (SSDs) use
210 this to flag that a format should fully provision (i.e. asso‐
211 ciate a physical block with every logical block). The same disks
212 (SSDs) might thin provision if this option is not given. If this
213 option is given then the --security option cannot be given. Also
214 accepts --ip_def for this option.
215
216 -l, --long
217 the default action of this utility is to assume 32 bit logical
218 block addresses. With 512 byte block size this permits more than
219 2 terabytes (almost 2 ** 41 bytes) on a single disk. This option
220 selects commands and parameters that allow for 64 bit logical
221 block addresses. Specifically this option sets the "longlba"
222 flag in the MODE SENSE (10) command and uses READ CAPACITY (16)
223 rather than READ CAPACITY (10). If this option is not given and
224 READ CAPACITY (10) or MODE SELECT detects a disk the needs more
225 than 32 bits to represent its logical blocks then it is set
226 internally. This option does not set the LONGLIST bit in the
227 FORMAT UNIT command. The LONGLIST bit is set as required depend‐
228 ing other parameters (e.g. when '--pie=PIE' is greater than
229 zero).
230
231 -M, --mode=MP
232 MP is a mode page number (0 to 62 inclusive) that will be used
233 for reading and perhaps changing the device logical block size.
234 The default is 1 which is the Read-Write Error Recovery mode
235 page.
236 Preferably the chosen (or default) mode page should be saveable
237 (i.e. accept the SP bit set in the MODE SELECT command used
238 when the logical block size is being changed). Recent version of
239 this utility will retry a MODE SELECT if the SP=1 variant fails
240 with a sense key of ILLEGAL REQUEST. That retry will use the
241 same MODE SELECT command but with SP=0 .
242
243 -P, --pfu=PFU
244 sets the "Protection Field Usage" field in the parameter block
245 associated with a FORMAT UNIT command to PFU. The default value
246 is 0, the only other defined value currently is 1. See the PRO‐
247 TECTION INFORMATION section below for more information.
248
249 -q, --pie=PIE
250 sets the "Protection Interval Exponent" field in the parameter
251 block associated with a FORMAT UNIT command to PIE. The default
252 value is 0. PIE can only be non-zero with protection types 2
253 and 3. The value of 0 is typical for 512 byte blocks; with 4096
254 byte blocks a value of 3 may be appropriate (i.e. 8 protection
255 intervals interleaved with 4096 bytes of user data). A device
256 may not support any non-zero values. This field first appeared
257 in SBC-3 revision 18.
258
259 -p, --pinfo
260 this option is deprecated, use the --fmtpinfo=FPI option
261 instead. If used, then it sets bit 7 of byte 1 in the FORMAT
262 UNIT cdb and that is equivalent to setting --fmtpinfo=2. [So if
263 --pinfo is used (plus --fmtpinfo=FPI and --pfu=PFU are not given
264 or their arguments are 0) then protection type 1 is selected.]
265
266 -x, --poll=PT
267 where PT is the type of poll used. If PT is 0 then a TEST UNIT
268 READY command is used, otherwise a REQUEST SENSE command is
269 used. The default is currently 0 but this will change to 1 in
270 the near future. See the NOTES sections below.
271
272 -E, --preset=ID
273 this option instructs this utility to issue a SCSI FORMAT WITH
274 PRESET command. The PRESET IDENTIFIER field in that cdb is set
275 to ID. The IMMED field in that cdb is also set unless the --wait
276 option is also given, in which case it is cleared.
277
278 -Q, --quick
279 the default action (i.e. when the option is not given) is to
280 give the user 15 seconds to reconsider doing a format operation
281 on the DEVICE. When this option is given that step (i.e. the 15
282 second warning period) is skipped.
283
284 -r, --resize
285 rather than format the disk, it can be resized. This means
286 changing the number of blocks on the device reported by the READ
287 CAPACITY command. This option should be used with the
288 --count=COUNT option. The contents of all logical blocks on the
289 media remain unchanged when this option is used. This means that
290 any resize operation can be reversed. This option cannot be used
291 together with either --format or a --size=LB_SZ whose argument
292 is different to the existing block size.
293
294 -R, --rto_req
295 The option is deprecated, use the --fmtpinfo=FPI option instead.
296 If used, then it sets bit 6 of byte 1 in the FORMAT UNIT cdb.
297
298 -S, --security
299 sets the "Security Initialization" (SI) bit in the FORMAT UNIT
300 command's initialization pattern descriptor within the parameter
301 list. According to SBC-3 the default initialization pattern
302 "shall be written using a security erasure write technique". See
303 the NOTES section on the SCSI SANITIZE command. If this option
304 is given then the --ip_def option cannot be given.
305
306 -6, --six
307 Use 6 byte variants of MODE SENSE and MODE SELECT. The default
308 action is to use the 10 byte variants. Some MO drives need this
309 option set when doing a format.
310
311 -s, --size=LB_SZ
312 where LB_SZ is the logical block size (i.e. number of user bytes
313 in each block) to format the device to. The default value is
314 whatever is currently reported by the block descriptor in a MODE
315 SENSE command. If the block size given by this option is differ‐
316 ent from the current value then a MODE SELECT command is used to
317 change it prior to the FORMAT UNIT command being started (as
318 recommended in the SBC standards). Some SCSI disks have 512 byte
319 logical blocks by default and allow an alternate logical block
320 size of 4096 bytes. If the given size in unacceptable to the
321 disk, most likely an "Invalid field in parameter list" message
322 will appear in sense data (requires the use of '-v' to decode
323 sense data).
324 Note that formatting a disk to add or remove protection informa‐
325 tion is not regarded as a change to its logical block size so
326 this option should not be used.
327
328 -T, --tape=FM
329 will send a FORMAT MEDIUM command to the DEVICE with its FORMAT
330 field set to FM. This option is used to prepare a tape (i.e. the
331 "medium") in a tape drive for use. Values for FM include 0 to do
332 the "default" format; 1 to partition a volume and 2 to do a
333 default format then partition.
334
335 -m, --timeout=SECS
336 where SECS is the FORMAT UNIT, FORMAT WITH PRESET or FORMAT
337 MEDIUM command timeout in seconds. SECS will only be used if it
338 exceeds the internal timeout which is 20 seconds if the IMMED
339 bit is set and 72000 seconds (20 hours) or higher if the IMMED
340 bit is not set. If the disk size exceeds 4 TB then the timeout
341 value is increased to 144000 seconds (40 hours). And if it is
342 greater than 8 TB then the timeout value is increased to 288000
343 seconds (80 hours). If the timeout is exceeded then the operat‐
344 ing system will typically abort the command. Aborting a command
345 may escalate to a LUN reset (or worse). A timeout may also leave
346 the disk or tape format operation incomplete. And that may
347 result in the disk or tape being in a "format corrupt" state
348 requiring another format to remedy the situation. So for vari‐
349 ous reasons command timeouts are best avoided.
350
351 -v, --verbose
352 increase the level of verbosity, (i.e. debug output). "-vvv"
353 gives a lot more debug output.
354
355 -y, --verify
356 set the VERIFY bit in the FORMAT MEDIUM cdb. The default is that
357 the VERIFY bit is clear. This option is only appropriate for
358 tapes.
359
360 -V, --version
361 print the version string and then exit.
362
363 -w, --wait
364 the default format action is to set the "IMMED" bit in the FOR‐
365 MAT UNIT command's (short) parameter header. If this option
366 (i.e. --wait) is given then the "IMMED" bit is not set. If
367 --wait is given then the FORMAT UNIT, FORMAT WITH PRESET or FOR‐
368 MAT MEDIUM command waits until the format operation completes
369 before returning its response. This can be many hours on large
370 disks. See the --timeout=SECS option.
371 Alternatively this option may be useful when used together with
372 --ffmt=FFMT (and FFMT greater than 0) since the fast format may
373 only be a matter of seconds.
374
376 The SBC-3 draft (revision 20) defines PLIST, CLIST, DLIST and GLIST in
377 section 4.10 on "Medium defects". Briefly, the PLIST is the "primary"
378 list of manufacturer detected defects, the CLIST ("certification" list)
379 contains those detected during the format operation, the DLIST is a
380 list of defects that can be given to the format operation. The GLIST is
381 the grown list which starts in the format process as CLIST+DLIST and
382 can "grow" later due to automatic reallocation (see the ARRE and AWRE
383 bits in the Read-Write Error Recovery mode page (see sdparm(8))) and
384 use of the SCSI REASSIGN BLOCKS command (see sg_reassign(8)).
385
386 By the SBC-3 standard (following draft revision 36) the CLIST and DLIST
387 had been removed, leaving PLIST and GLIST. Only PLIST and GLIST are
388 found in the SBC-4 drafts.
389
390 The CMPLST bit (controlled by the --cmplst=0|1 option) determines
391 whether the existing GLIST, when the format operation is invoked, is
392 taken into account. The sg_format utility sets the FOV bit to zero
393 which causes DPRY=0, so the PLIST is taken into account, and DCRT=0, so
394 the CLIST is generated and used during the format process.
395
396 The sg_format utility does not permit a user to provide a defect list
397 (i.e. DLIST).
398
400 Protection Information (PI) is additional information held with logical
401 blocks so that an application and/or host bus adapter can check the
402 correctness of those logical blocks. PI is placed in one or more pro‐
403 tection intervals interleaved in each logical block. Each protection
404 interval follows the user data to which it refers. A protection inter‐
405 val contains 8 bytes made up of a 2 byte "logical block guard" (CRC), a
406 2 byte "logical block application guard", and a 4 byte "logical block
407 reference tag". Devices with 512 byte logical block size typically have
408 one protection interval appended, making its logical block data 520
409 bytes long. Devices with 4096 byte logical block size often have 8 pro‐
410 tection intervals spread across its logical block data for a total size
411 of 4160 bytes. Note that for all other purposes the logical block size
412 is considered to be 512 and 4096 bytes respectively.
413
414 The SBC-3 standard have added several "protection types" to the PI
415 introduced in the SBC-2 standard. SBC-3 defines 4 protection types
416 (types 0 to 3) with protection type 0 meaning no PI is maintained.
417 While a device may support one or more protection types, it can only be
418 formatted with 1 of the 4. To change a device's protection type, it
419 must be re-formatted. For more information see the Protection Informa‐
420 tion in section 4.21 of draft SBC-4 revision 16.
421
422 A device that supports PI information (i.e. supports one or more pro‐
423 tection types 1, 2 and 3) sets the "PROTECT" bit in its standard
424 INQUIRY response. It also sets the SPT field in the EXTENDED INQUIRY
425 VPD page response to indicate which protection types it supports. Given
426 PROTECT=1 then SPT=0 implies the device supports PI type 1 only, SPT=1
427 implies the device supports PI types 1 and 2, and various other
428 non-obvious mappings up to SPT=7 which implies protection types 1, 2
429 and 3 are supported. The current protection type of a disk can be found
430 in the "P_TYPE" and "PROT_EN" fields in the response of a READ CAPACITY
431 (16) command (e.g. with the 'sg_readcap --long' utility).
432
433 Given that a device supports a particular protection type, a user can
434 then choose to format that disk with that protection type by setting
435 the "FMTPINFO" and "Protection Field Usage" fields in the FORMAT UNIT
436 command. Those fields correspond to the --fmtpinfo=FPI and the
437 --pfu=PFU options in this utility. The list below shows the four pro‐
438 tection types followed by the options of this utility needed to select
439 them:
440 0 : --fmtpinfo=0 --pfu=0
441 1 : --fmtpinfo=2 --pfu=0
442 2 : --fmtpinfo=3 --pfu=0
443 3 : --fmtpinfo=3 --pfu=1
444 The default value of FPI (in --fmtpinfo=FPI) is 0 and the default value
445 of PFU (in --pfu=PFU) is 0. So if neither --fmtpinfo=FPI nor --pfu=PFU
446 are given then protection type 0 (i.e. no protection information) is
447 chosen.
448
450 After a format that changes the logical block size or the number of
451 logical blocks on a disk, the operating system may need to be told to
452 re-initialize its setting for that disk. In Linux that can be done
453 with:
454 echo 1 > /sys/block/sd{letter(s)}/device/rescan
455 where "letter(s)" will be between 'a' and 'zzz'. The lsscsi utility in
456 Linux can be used to check the various namings of a disk.
457
458 The SBC-2 standard states that the REQUEST SENSE command should be used
459 for obtaining progress indication when the format command is underway.
460 However, tests on a selection of disks shows that TEST UNIT READY com‐
461 mands yield progress indications (but not REQUEST SENSE commands). So
462 the current version of this utility defaults to using TEST UNIT READY
463 commands to poll the disk to find out the progress of the format. The
464 --poll=PT option has been added to control this.
465
466 When the --format, --preset=ID or --tape=FM option is given without the
467 --wait option then the corresponding SCSI command is issued with the
468 IMMED bit set which causes the SCSI command to return after it has
469 started the format operation. The --early option will cause sg_format
470 to exit at that point. Otherwise the DEVICE is polled every 60 seconds
471 or every 10 seconds if FFMT is non-zero. The poll is with TEST UNIT
472 READY or REQUEST SENSE commands until one reports an "all clear" (i.e.
473 the format operation has completed). Normally these polling commands
474 will result in a progress indicator (expressed as a percentage) being
475 output to the screen. If the user gets bored watching the progress
476 report then sg_format process can be terminated (e.g. with control-C)
477 without affecting the format operation which continues. However a tar‐
478 get or device reset (or a power cycle) will probably cause the format
479 to cease and the DEVICE to become "format corrupt".
480
481 When the --format (--preset=ID or --tape) and --wait options are both
482 given then this utility may take a long time to return. In this case
483 care should be taken not to send any other SCSI commands to the disk as
484 it may not respond leaving those commands queued behind the active for‐
485 mat command. This may cause a timeout in the OS driver (in a lot
486 shorter period than 20 hours applicable to some format operations).
487 This may result in the OS resetting the disk leaving the format opera‐
488 tion incomplete. This may leave the disk in a "format corrupt" state
489 requiring another format to remedy the situation. Modern SCSI devices
490 should yield a "not ready" sense key with an additional sense indicat‐
491 ing a format is in progress. With older devices the user should take
492 precautions that nothing attempts to access a device while it is being
493 formatted. Unmounting in mounted file systems on a DEVICE prior to
494 calling this utility is strongly advised.
495
496 When the block size (i.e. the number of bytes in each block) is changed
497 on a disk two SCSI commands must be sent: a MODE SELECT to change the
498 block size followed by a FORMAT command. If the MODE SELECT command
499 succeeds and the FORMAT fails then the disk may be in a state that the
500 standard calls "format corrupt". A block descriptor in a subsequent
501 MODE SENSE will report the requested new block size while a READ CAPAC‐
502 ITY command will report the existing (i.e. previous) block size. Alter‐
503 natively the READ CAPACITY command may fail, reporting the device is
504 not ready, potentially requiring a format. The solution to this situa‐
505 tion is to do a format again (and this time the new block size does not
506 have to be given) or change the block size back to the original size.
507
508 The SBC-2 standard states that the block count can be set back to the
509 manufacturer's maximum recommended value in a format or resize opera‐
510 tion. This can be done by placing an address of 0xffffffff (or the 64
511 bit equivalent) in the appropriate block descriptor field to a MODE
512 SELECT command. In signed (two's complement) arithmetic that value cor‐
513 responds to '-1'. So a --count=-1 causes the block count to be set back
514 to the manufacturer's maximum recommended value. To see exactly which
515 SCSI commands are being executed and parameters passed add the "-vvv"
516 option to the sg_format command line.
517
518 The FMTDATA field shown in the FORMAT UNIT cdb does not have a corre‐
519 sponding option in this utility. When set in the cdb it indicates an
520 additional parameter list will be sent to the DEVICE along with the
521 cdb. It is set as required, basically when any field in the parameter
522 list header is set.
523
524 Short stroking is a technique to trade off capacity for performance on
525 hard disks. "Hard" disk is often used to mean a storage device with
526 spinning platters which contain the user data. Solid State Disk (SSD)
527 is the newer form of storage device that contains no moving parts. Hard
528 disk performance is usually highest on the outer tracks (usually the
529 lower logical block addresses) so by resizing or reformatting a disk to
530 a smaller capacity, average performance will usually be increased.
531
532 Other utilities may be useful in finding information associated with
533 formatting. These include sg_inq(8) to fetch standard INQUIRY informa‐
534 tion (e.g. the PROTECT bit) and to fetch the EXTENDED INQUIRY VPD page
535 (e.g. RTO and GRD_CHK bits). The sdparm(8) utility can be used to
536 access and potentially change the now obsolete format mode page.
537
538 scsiformat is another utility available for formatting SCSI disks with
539 Linux. It dates from 1997 (most recent update) and may be useful for
540 disks whose firmware is of that vintage.
541
542 The COUNT numeric argument may include a multiplicative suffix or be
543 given in hexadecimal. See the "NUMERIC ARGUMENTS" section in the
544 sg3_utils(8) man page.
545
546 The SCSI SANITIZE command was introduced in SBC-3 revision 27. It is
547 closely related to the ATA sanitize disk feature set and can be used to
548 remove all existing data from a disk. Sanitize is more likely to be
549 implemented on modern disks (including SSDs) than FORMAT UNIT's secu‐
550 rity initialization feature (see the --security option) and in some
551 cases much faster.
552
553 SSDs that support thin provisioning will typically unmap all logical
554 blocks during a format. The reason is to improve the SSD's endurance.
555 Also thin provisioned formats typically complete faster than fully pro‐
556 visioned ones on the same disk (see the --ip_def option). In either
557 case format operations on SSDs tend to be a lot faster than they are on
558 hard disks with spinning media.
559
561 Tape system use a variant of the FORMAT UNIT command used on disks.
562 Tape systems use the FORMAT MEDIUM command which is simpler with only
563 three fields in the cdb typically used. Apart from sharing the same
564 opcode the cdbs of FORMAT UNIT and FORMAT MEDIUM are quite different.
565 FORMAT MEDIUM's fields are VERIFY, IMMED and FORMAT (with TRANSFER
566 LENGTH always set to 0). The VERIFY bit field is set with the --verify
567 option. The IMMED bit is manipulated by the --wait option in the same
568 way it is for disks; one difference is that if the --poll=PT option is
569 not given then it defaults to PT of 1 which means the poll is done with
570 REQUEST SENSE commands.
571
572 The argument given to the --tape=FM option is used to set the FORMAT
573 field. FM can take values from "-1" to "15" where "-1" (the default)
574 means don't do a tape format; value "8" to "15" are for vendor specific
575 formats. The --early option may also be used to set the IMMED bit and
576 then exit this utility (rather than poll periodically until it is fin‐
577 ished). In this case the tape drive will still be busy doing the format
578 for some time but, according to T10, should still respond in full to
579 the INQUIRY and REPORT LUNS commands. Other commands (including REQUEST
580 SENSE) should yield a "not ready" sense key with an additional sense
581 code of "Logical unit not ready, format in progress". Additionally
582 REQUEST SENSE should contain a progress indication in its sense data.
583
584 When FM is 1 or 2 then the settings in the Medium partition mode page
585 control the partitioning. That mode page can be viewed and modified
586 with the sdparm utility.
587
588 Prior to invoking this utility the tape may need to be positioned to
589 the beginning of partition 0. In Linux that can typically be done with
590 the mt utility (e.g. 'mt -f /dev/st0 rewind').
591
593 These examples use Linux device names. For suitable device names in
594 other supported Operating Systems see the sg3_utils(8) man page.
595
596 In the first example below simply find out the existing block count and
597 size derived from two sources: a block descriptor in a MODE SELECT com‐
598 mand response and from the response of a READ CAPACITY commands. No
599 changes are made:
600
601 # sg_format /dev/sdm
602
603 Now a simple format, leaving the block count and size as they were pre‐
604 viously. The FORMAT UNIT command is executed in IMMED mode and the
605 device is polled every 60 seconds to print out a progress indication:
606
607 # sg_format --format /dev/sdm
608
609 Now the same format, but waiting (passively) until the format operation
610 is complete:
611
612 # sg_format --format --wait /dev/sdm
613
614 Next is a format in which the block size is changed to 520 bytes and
615 the block count is set to the manufacturer's maximum value (for that
616 block size). Note, not all disks support changing the block size:
617
618 # sg_format --format --size=520 /dev/sdm
619
620 Now a resize operation so that only the first 0x10000 (65536) blocks on
621 a disk are accessible. The remaining blocks remain unaltered.
622
623 # sg_format --resize --count=0x10000 /dev/sdm
624
625 Now resize the disk back to its normal (maximum) block count:
626
627 # sg_format --resize --count=-1 /dev/sdm
628
629 One reason to format a SCSI disk is to add protection information.
630 First check which protection types are supported by a disk (by checking
631 the SPT field in the Extended inquiry VPD page together with the Pro‐
632 tect bit in the standard inquiry response):
633
634 # sg_vpd -p ei -l /dev/sdb
635 extended INQUIRY data VPD page:
636 ACTIVATE_MICROCODE=0
637 SPT=1 [protection types 1 and 2 supported]
638 ....
639
640 Format with type 1 protection:
641
642 # sg_format --format --fmtpinfo=2 /dev/sdm
643
644 After a successful format with type 1 protection, READ CAPACITY(16)
645 should show something like this:
646
647 # sg_readcap -l /dev/sdm
648 Read Capacity results:
649 Protection: prot_en=1, p_type=0, p_i_exponent=0 [type 1 protec‐
650 tion]
651 Logical block provisioning: lbpme=0, lbprz=0
652 ....
653
654 To format with type 3 protection:
655
656 # sg_format --format --fmtpinfo=3 --pfu=1 /dev/sdm
657
658 For the disk shown above this will probably fail because the Extended
659 inquiry VPD page showed only types 1 and 2 protection are supported.
660
661 Here are examples of using fast format (FFMT field in FORMAT UNIT cdb)
662 to quickly switch between 512 and 4096 byte logical block size. Assume
663 disk starts with 4096 byte logical block size and all important data
664 has been backed up.
665
666 # sg_format --format --ffmt=1 --size=512 /dev/sdd
667
668 Now /dev/sdd should have 512 byte logical block size. And to switch it
669 back:
670
671 # sg_format --format --ffmt=1 --size=4096 /dev/sdd
672
673 Since fast formats can be very quick (a matter of seconds) using the
674 --wait option may be appropriate.
675
676 And tu use Format with preset this invocation might be used:
677
678 # sg_format --preset=1 --fmtmaxlba /dev/sdd
679
680 The FORMAT PRESETS VPD page (0xb8) should be consulted to check that
681 Preset identifier 0x1 is there and has the expected format (i.e.
682 "default host aware zoned block device model with 512 bytes of user
683 data in each logical block").
684
686 The exit status of sg_format is 0 when it is successful. Otherwise see
687 the sg3_utils(8) man page. Unless the --wait option is given, the exit
688 status may not reflect the success of otherwise of the format. Using
689 sg_turs(8) and sg_readcap(8) after the format operation may be wise.
690
692 Written by Grant Grundler, James Bottomley and Douglas Gilbert.
693
695 Report bugs to <dgilbert at interlog dot com>.
696
698 Copyright © 2005-2020 Grant Grundler, James Bottomley and Douglas
699 Gilbert
700 This software is distributed under the GPL version 2. There is NO war‐
701 ranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
702 POSE.
703
705 sg_turs(8), sg_requests(8), sg_inq(8), sg_modes(8), sg_vpd(8), sg_reas‐
706 sign(8), sg_readcap(8), sg3_utils(8), sg_sanitize(8) [all in
707 sg3_utils], lsscsi(8), mt(mt-st), sdparm(8), scsiformat (old),
708 hdparm(8)
709
710
711
712sg3_utils-1.45 January 2020 SG_FORMAT(8)