1SG_FORMAT(8)                       SG3_UTILS                      SG_FORMAT(8)
2
3
4

NAME

6       sg_format  -  format  or  resize  a SCSI disk (perhaps change its block
7       size)
8

SYNOPSIS

10       sg_format [--cmplst={0|1}] [--count=COUNT] [--dcrt]  [--early]  [--fmt‐
11       pinfo=FPI]   [--format]   [--help]   [--long]  [--pfu=PFU]  [--pie=PIE]
12       [--pinfo]  [--poll=PT]  [--resize]  [--rto_req]  [--security]   [--six]
13       [--size=SIZE] [--verbose] [--version] [--wait] DEVICE
14

DESCRIPTION

16       Not  all  SCSI direct access devices need to be formatted and some have
17       vendor specific formatting procedures. SCSI disks with  rotating  media
18       are  probably  the  largest  group  that do support a 'standard' format
19       operation. They are typically factory formatted to a block size of  512
20       bytes  with  the  largest number of blocks that the manufacturer recom‐
21       mends. The manufacturer's recommendation typically leaves aside a  cer‐
22       tain  number  of  tracks,  spread across the media, for reassignment of
23       blocks to logical block addresses during the life of the disk.
24
25       This utility can format modern SCSI disks and potentially change  their
26       block  size (if permitted) and the block count (i.e. number of accessi‐
27       ble blocks on the media also known as "resizing"). Resizing a  disk  to
28       less  than  the  manufacturer's  recommended  block  count is sometimes
29       called "short stroking" (see NOTES section). Resizing the  block  count
30       while  not  changing the block size may not require a format operation.
31       The SBC-2 standard (see www.t10.org) has obsoleted the "format  device"
32       mode  page.  Many  of the low level details found in that mode page are
33       now left up to the discretion of the manufacturer.
34
35       When this utility is used without options (i.e.  it  is  only  given  a
36       DEVICE  argument) it prints out the existing block size and block count
37       derived from two sources. These two sources are a block  descriptor  in
38       the  response to a MODE SENSE command and the response to a READ CAPAC‐
39       ITY command. The reason for this double check is to  detect  a  "format
40       corrupt"  state  (see  NOTES  section).  This usage will not modify the
41       disk.
42
43       When this utility is used with the "--format" (or "-F") option it  will
44       attempt  to  format the given DEVICE. There is a 10 second pause during
45       which time the user is invited twice (5 seconds apart) to abort sg_for‐
46       mat.  This occurs just prior the SCSI FORMAT UNIT command being issued.
47       See the NOTES section for more information.
48
49       Protection information is optional and is made up of 8 additional bytes
50       associated  with  each logical block. Four protection types are defined
51       with protection type 0 being no additional protection  bytes.  See  the
52       PROTECTION TYPES section below for more information.
53

OPTIONS

55       Arguments to long options are mandatory for short options as well.  The
56       options are arranged in alphabetical order based  on  the  long  option
57       name.
58
59       -C, --cmplst={0|1}
60              sets  the CMPLST ("complete list") bit in the FORMAT UNIT cdb to
61              0 or 1.  The default is 1  in  which  case  the  existing  GLIST
62              (grown  list)  is  ignored.  If the value is 0 then the existing
63              GLIST is taken into account. See the  LISTS  section  below.  In
64              most cases this bit should be left set; some MO disk drives need
65              this bit cleared.
66
67       -c, --count=COUNT
68              where COUNT is the number of blocks to be formatted or media  to
69              be  resized  to.  Can  be used with either --format or --resize.
70              With --format this option need not be given in which case it  is
71              assumed  to  be  zero. With --format the interpretation of COUNT
72              is:
73                (COUNT > 0) : only format the first COUNT blocks and READ
74                              CAPACITY will report COUNT blocks after format
75                (COUNT = 0) and block size  unchanged  :  use  existing  block
76              count
77                (COUNT = 0) and block size changed : recommended maximum block
78                                                     count for new block size
79                (COUNT = -1) : use recommended maximum block count
80                (COUNT < -1) : illegal
81              With  --resize  this  option  must  be  given and COUNT has this
82              interpretation:
83                (COUNT > 0) : after resize READ CAPACITY will report COUNT
84                              blocks
85                (COUNT = 0) : after resize READ CAPACITY will report 0 blocks
86                (COUNT = -1) : after resize READ CAPACITY will report its
87                               maximum number of blocks
88                (COUNT < -1) : illegal
89              In both cases if the given COUNT exceeds the maximum  number  of
90              blocks (for the block size) then the disk reports an error.  See
91              NOTES section below.
92
93       -D, --dcrt
94              this option sets the DCRT  bit  in  the  FORMAT  UNIT  command's
95              parameter list header. It will "disable certification". Certifi‐
96              cation  verifies  that  blocks  are  usable  during  the  format
97              process.  Using  this  option may speed the format.  The default
98              action of this utility (i.e. when this option is not  given)  is
99              to  clear the DCRT bit thereby requesting "media certification".
100              When the DCRT bit is set, the FOV bit must  also  be  set  hence
101              sg_format does that.
102
103       -e, --early
104              during a format operation, The default action of this utility is
105              to poll the disk every 60 seconds to determine the  progress  of
106              the  format  operation until it is finished. When this option is
107              given this utility will exit "early", that is  as  soon  as  the
108              format  operation  has  commenced. Then the user can monitor the
109              progress of the ongoing format operation  with  other  utilities
110              (e.g.  sg_turs(8) or sg_requests(8)). This option and --wait are
111              mutually exclusive.
112
113       -f, --fmtpinfo=FPI
114              sets the FMTPINFO field in  the  FORMAT  UNIT  cdb  to  a  value
115              between  0  and  3.   The default value is 0. The FMTPINFO field
116              from SBC-3 revision 16 is a 2 bit field (bits 7 and 6 of byte  1
117              in  the  cdb). Prior to that it was a single bit field (bit 7 of
118              byte 1 in the cdb) and there  was  an  accompanying  bit  called
119              RTO_REQ  (bit  6  of  byte 1 in the cdb). The deprecated options
120              "--pinfo" and "--rto-req" represent the older usage. This option
121              should  be used in their place. See the PROTECTION TYPES section
122              below for more information.
123
124       -F, --format
125              issue a SCSI FORMAT UNIT command.  This  will  destroy  all  the
126              data  held  on the media.  This option is required to change the
127              block size of a disk. The user is given a 10 second  count  down
128              to  ponder the wisdom of doing this, during which time control-C
129              (amongst other Unix commands) can be used to kill  this  process
130              before  it does any damage. See NOTES section for implementation
131              details and EXAMPLES section for typical use.
132
133       -h, --help
134              print out the usage information then exit.
135
136       -l, --long
137              the default action of this utility is to assume 32  bit  logical
138              block addresses. With 512 byte block size this permits more than
139              2 terabytes (almost 2 ** 41 bytes) on a single disk. This option
140              selects  commands  and  parameters that allow for 64 bit logical
141              block addresses.  Specifically this option  sets  the  "longlba"
142              flag  in the MODE SENSE (10) command and uses READ CAPACITY (16)
143              rather than READ CAPACITY (10). If this option is not given  and
144              READ  CAPACITY (10) or MODE SELECT detects a disk the needs more
145              than 32 bits to represent its logical  blocks  then  it  is  set
146              internally.  This  option  does  not set the LONGLIST bit in the
147              FORMAT UNIT command. The LONGLIST bit is set as required depend‐
148              ing  other  parameters  (e.g.  when  '--pie=PIE' is greater than
149              zero).
150
151       -P, --pfu=PFU
152              sets the "Protection Field Usage" field in the  parameter  block
153              associated  with a FORMAT UNIT command to PFU. The default value
154              is 0, the only other defined value currently is 1. See the  PRO‐
155              TECTION TYPES section below for more information.
156
157       -q, --pie=PIE
158              sets  the  "Protection Interval Exponent" field in the parameter
159              block associated with a FORMAT UNIT command to PIE. The  default
160              value is 0.  This field first appeared in SBC-3 revision 18.
161
162       -p, --pinfo
163              this   option  is  deprecated,  use  the  --fmtpinfo=FPI  option
164              instead.  If used, then it sets bit 7 of byte 1  in  the  FORMAT
165              UNIT  cdb and that is equivalent to setting --fmtpinfo=2. [So if
166              --pinfo is used (plus --fmtpinfo=FPI and --pfu=PFU are not given
167              or their arguments are 0) then protection type 1 is selected.]
168
169       -x, --poll=PT
170              where  PT  is the type of poll used. If PT is 0 then a TEST UNIT
171              READY command is used, otherwise  a  REQUEST  SENSE  command  is
172              used.  The  default  is currently 0 but this will change to 1 in
173              the near future. See the NOTES sections below.
174
175       -r, --resize
176              rather than format the disk,  it  can  be  resized.  This  means
177              changing the number of blocks on the device reported by the READ
178              CAPACITY  command.   This  option  should  be  used   with   the
179              --count=COUNT option.  The contents of all logical blocks on the
180              media remain unchanged when this option is used. This means that
181              any resize operation can be reversed. This option cannot be used
182              together with either --format or a --size=SIZE whose argument is
183              different to the existing block size.
184
185       -R, --rto_req
186              The option is deprecated, use the --fmtpinfo=FPI option instead.
187              If used, then it sets bit 6 of byte 1 in the FORMAT UNIT cdb.
188
189       -S, --security
190              sets the "Security Initialization" (SI) bit in the  FORMAT  UNIT
191              command's initialization pattern descriptor within the parameter
192              list. According to  SBC-3  the  default  initialization  pattern
193              "shall be written using a security erasure write technique". See
194              the NOTES section on the SCSI SANITIZE command.
195
196       -6, --six
197              Use 6 byte variants of MODE SENSE and MODE SELECT.  The  default
198              action  is to use the 10 byte variants. Some MO drives need this
199              option set when doing a format.
200
201       -s, --size=SIZE
202              where SIZE is the block size  (i.e.  number  of  bytes  in  each
203              block) to format the device to. The default value is whatever is
204              currently reported by the block descriptor in a MODE SENSE  com‐
205              mand.  If  the block size given by this option is different from
206              the current value then a MODE SELECT command is used  to  change
207              it  prior  to  the  FORMAT UNIT command being started (as recom‐
208              mended in the draft standard). Many SCSI  disks  have  512  byte
209              sectors  by  default  and allow up to 16 bytes extra in a sector
210              (i.e. 528 byte sectors).  If the given size in unacceptable with
211              the  disk, most likely an "Invalid field in parameter list" mes‐
212              sage will appear in sense data (requires  the  use  of  '-v'  to
213              decode sense data).
214
215       -v, --verbose
216              increase  the  level  of  verbosity, (i.e. debug output). "-vvv"
217              gives a lot more debug output.
218
219       -V, --version
220              print the version string and then exit.
221
222       -w, --wait
223              the default format action is to set the "IMMED" bit in the  FOR‐
224              MAT  UNIT  command's  (short)  parameter  header. If this option
225              (i.e. --wait) is given then the  "IMMED"  bit  is  not  set.  If
226              --wait  is  given the FORMAT UNIT command waits until the format
227              operation completes before returning its response. This  can  be
228              many  hours  on large disks. This utility sets a 15 hour timeout
229              on such a FORMAT UNIT command!
230

LISTS

232       The SBC-3 draft (revision 29) defines PLIST, CLIST, DLIST and GLIST  in
233       section  4.13  on "Medium defects". Briefly, the PLIST is the "primary"
234       list of manufacturer detected defects, the CLIST ("certification" list)
235       contains  those  detected  during  the format operation, the DLIST is a
236       list of defects that can be given to the format operation. The GLIST is
237       the  grown  list  which starts in the format process as CLIST+DLIST and
238       can "grow" later due to automatic reallocation (see the ARRE  and  AWRE
239       bits  in  the  read-write error recovery mode page (see sdparm(8))) and
240       use of the SCSI REASSIGN BLOCKS command (see sg_reassign(8)).
241
242       The CMPLST bit  (controlled  by  the  --cmplst=0|1  option)  determines
243       whether  the  existing  GLIST, when the format operation is invoked, is
244       taken into account. The sg_format utility sets  the  FOV  bit  to  zero
245       which causes DPRY=0, so the PLIST is taken into account, and DCRT=0, so
246       the CLIST is generated and used during the format process.
247
248       The sg_format utility does not permit a user to provide a  defect  list
249       (i.e. DLIST).
250

PROTECTION TYPES

252       SBC-3  drafts  have added several "protection types" to the "protection
253       information" introduced in the  SBC-2  standard.  See  the  "protection
254       information"  section  (section 4.21 in draft SBC-3 rev 29). 8 bytes of
255       protection information are added to each logical block (a 2 byte "logi‐
256       cal block guard" (CRC), a 2 byte "logical block application guard", and
257       a 4 byte "logical block reference tag").  SBC-3  defines  4  protection
258       types  (types  0  to  3)  with  protection type 0 meaning no protection
259       information is maintained.
260
261       A device that supports protection information  (i.e.  supports  one  or
262       more  protection  types  of  1 or higher) sets the "PROTECT" bit in its
263       standard INQUIRY response. It also sets the SPT field in  the  EXTENDED
264       INQUIRY  VPD  page  response to indicate which protection types it sup‐
265       ports. The current protection type of  a  disk  can  be  found  in  the
266       "P_TYPE"  and  "PROT_EN" fields in the response of a READ CAPACITY (16)
267       command (e.g. with the 'sg_readcap --long' utility).
268
269       Given that a device supports a particular protection type, a  user  can
270       then  choose  to  format that disk with that protection type by setting
271       the "FMTPINFO" and "Protection Field Usage" fields in the  FORMAT  UNIT
272       command.   Those  fields  correspond  to  the  --fmtpinfo=FPI  and  the
273       --pfu=PFU options in this utility. The list below shows the  four  pro‐
274       tection  types followed by the options of this utility needed to select
275       them:
276         0 : --fmtpinfo=0 --pfu=0
277         1 : --fmtpinfo=2 --pfu=0
278         2 : --fmtpinfo=3 --pfu=0
279         3 : --fmtpinfo=3 --pfu=1
280       The default value of FPI (in --fmtpinfo=FPI) is 0 and the default value
281       of  PFU (in --pfu=PFU) is 0. So if neither --fmtpinfo=FPI nor --pfu=PFU
282       are given then protection type 0 (i.e. no  protection  information)  is
283       chosen.
284

NOTES

286       The SBC-2 standard states that the REQUEST SENSE command should be used
287       for obtaining progress indication when the format command is  underway.
288       However,  tests on a selection of disks shows that TEST UNIT READY com‐
289       mands yield progress indications (but not REQUEST SENSE  commands).  So
290       the  current  version of this utility defaults to using TEST UNIT READY
291       commands to poll the disk to find out the progress of the  format.  The
292       --poll=PT option has been added to control this.
293
294       When  the  --format  option is given without the --wait option then the
295       SCSI FORMAT UNIT command is issued with the IMMED bit set which  causes
296       the  SCSI  command to return after it has started the format operation.
297       The --early option will cause sg_format to exit at that point.   Other‐
298       wise  the  DEVICE  is  polled  every 60 seconds with TEST UNIT READY or
299       REQUEST SENSE commands until it reports an "all clear" (i.e. the format
300       operation  has  completed). Normally these polling commands will result
301       in a progress indicator (expressed as a percentage) being output to the
302       screen.   If  the  user  gets  bored  watching the progress report then
303       sg_format process can  be  terminated  (e.g.  with  control-C)  without
304       affecting  the  format  operation  which continues. However a target or
305       device reset (or a power cycle)  will  probably  cause  the  device  to
306       become "format corrupt".
307
308       When  the  --format and --wait options are both given then this utility
309       may take a long time to return. In this case care should be  taken  not
310       to send any other SCSI commands to the disk as it may not respond leav‐
311       ing those commands queued behind the active format  command.  This  may
312       cause a timeout in the OS driver (in a lot shorter period than 15 hours
313       applicable to some format operations). This may result in the OS reset‐
314       ting  the  disk leaving the format operation incomplete. This may leave
315       the disk in a "format corrupt" state requiring another format to remedy
316       the situation.
317
318       When the block size (i.e. the number of bytes in each block) is changed
319       on a disk two SCSI commands must be sent: a MODE SELECT to  change  the
320       block  size  followed  by  a FORMAT command. If the MODE SELECT command
321       succeeds and the FORMAT fails then the disk may be in a state that  the
322       draft  standard  calls "format corrupt". A block descriptor in a subse‐
323       quent MODE SENSE will report the requested new block size while a  READ
324       CAPACITY  command will report the existing (i.e. different) block size.
325       Alternatively the READ CAPACITY command may fail, reporting the  device
326       is not ready, potentially requiring a format. The solution to this sit‐
327       uation is to do a format again (and this time the new block  size  does
328       not  have  to  be  given) or change the block size back to the original
329       size.
330
331       The SBC-2 standard states that the block count can be set back  to  the
332       manufacturer's  maximum  recommended value in a format or resize opera‐
333       tion.  This can be done by placing an address of 0xffffffff (or the  64
334       bit  equivalent)  in  the  appropriate block descriptor field to a MODE
335       SELECT command. In signed (two's complement) arithmetic that value cor‐
336       responds  to  the  manufacturer's  maximum  recommended  value.  To see
337       exactly which SCSI commands are being executed  and  parameters  passed
338       add the "-vvv" option to the sg_format command line.
339
340       Short  stroking  is  a technique to trade off capacity for performance.
341       Rotating disk performance is usually highest on the outer tracks  (i.e.
342       lower logical block addresses) so by resizing or reformatting a disk to
343       a smaller capacity, average performance will usually be increased.
344
345       Other utilities may be useful in finding  information  associated  with
346       formatting.  These include sg_inq(8) to fetch standard INQUIRY informa‐
347       tion (e.g. the PROTECT bit) and to fetch the EXTENDED INQUIRY VPD  page
348       (e.g.  RTO  and  GRD_CHK  bits).  The  sdparm(8) utility can be used to
349       access and potentially change the now obsolete format mode page.
350
351       scsiformat is another utility available for formatting SCSI disks  with
352       Linux.  It  dates  from 1997 (most recent update) and may be useful for
353       disks whose firmware is of that vintage.
354
355       The COUNT numeric argument may include a multiplicative  suffix  or  be
356       given  in  hexadecimal.  See  the  "NUMERIC  ARGUMENTS"  section in the
357       sg3_utils(8) man page.
358
359       The SCSI SANITIZE command was introduced in SBC-3 revision  27.  It  is
360       closely related to the ATA sanitize disk feature set and can be used to
361       remove all existing data from a disk. Sanitize is  more  likely  to  be
362       implemented  on  modern disks (including SSDs) than FORMAT UNIT's secu‐
363       rity initialization feature (see the --security  option)  and  in  some
364       cases much faster.
365

EXAMPLES

367       These  examples  use  Linux  device names. For suitable device names in
368       other supported Operating Systems see the sg3_utils(8) man page.
369
370       In the first example below simply find out the existing block count and
371       size derived from two sources: a block descriptor in a MODE SELECT com‐
372       mand response and from the response of a  READ  CAPACITY  commands.  No
373       changes are made:
374
375          # sg_format /dev/sdm
376
377       Now a simple format, leaving the block count and size as they were pre‐
378       viously.  The FORMAT UNIT command is executed in  IMMED  mode  and  the
379       device is polled every 60 seconds to print out a progress indication:
380
381          # sg_format --format /dev/sdm
382
383       Now the same format, but waiting (passively) until the format operation
384       is complete:
385
386          # sg_format --format --wait /dev/sdm
387
388       Next is a format in which the block size is changed to  520  bytes  and
389       the  block  count  is set to the manufacturer's maximum value (for that
390       block size). Note, not all disks support changing the block size:
391
392          # sg_format --format --size=520 /dev/sdm
393
394       Now a resize operation so that only the first 0x10000 (65536) blocks on
395       a disk are accessible. The remaining blocks remain unaltered.
396
397          # sg_format --resize --count=0x10000 /dev/sdm
398
399       Now resize the disk back to its normal (maximum) block count:
400
401          # sg_format --resize --count=-1 /dev/sdm
402
403       One  reason  to  format  a  SCSI disk is to add protection information.
404       First check which protection types are supported by a disk (by checking
405       the  SPT  field in the Extended inquiry VPD page together with the Pro‐
406       tect bit in the standard inquiry response):
407
408          # sg_vpd -p ei -l /dev/sdb
409          extended INQUIRY data VPD page:
410            ACTIVATE_MICROCODE=0
411            SPT=1 [protection types 1 and 2 supported]
412            ....
413
414       Format with type 1 protection:
415
416          # sg_format --format --fmtpinfo=2 /dev/sdm
417
418       After a successful format with type  1  protection,  READ  CAPACITY(16)
419       should show something like this:
420
421          # sg_readcap -l /dev/sdm
422          Read Capacity results:
423             Protection:  prot_en=1,  p_type=0, p_i_exponent=0 [type 1 protec‐
424       tion]
425             Logical block provisioning: lbpme=0, lbprz=0
426             ....
427
428       To format with type 3 protection:
429
430          # sg_format --format --fmtpinfo=3 --pfu=1 /dev/sdm
431
432       For the disk shown above this will probably fail because  the  Extended
433       inquiry VPD page showed only types 1 and 2 protection are supported.
434

EXIT STATUS

436       The  exit status of sg_format is 0 when it is successful. Otherwise see
437       the sg3_utils(8) man page. Unless the --wait option is given, the  exit
438       status  may  not reflect the success of otherwise of the format.  Using
439       sg_turs(8) and sg_readcap(8) after the format operation may be wise.
440

AUTHORS

442       Written by Grant Grundler, James Bottomley and Douglas Gilbert.
443

REPORTING BUGS

445       Report bugs to <dgilbert at interlog dot com>.
446
448       Copyright © 2005-2013  Grant  Grundler,  James  Bottomley  and  Douglas
449       Gilbert
450       This  software is distributed under the GPL version 2. There is NO war‐
451       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
452       POSE.
453

SEE ALSO

455       sg_turs(8), sg_requests(8), sg_inq(8), sg_modes(8), sg_vpd(8), sg_reas‐
456       sign(8),   sg_readcap(8),   sg3_utils(8),   sg_sanitize(8)   [all    in
457       sg3_utils], sdparm(8), scsiformat (old), hdparm(8)
458
459
460
461sg3_utils-1.37                     June 2013                      SG_FORMAT(8)
Impressum