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

NAME

6       sg_format - format, format with preset, resize SCSI disk; format tape
7

SYNOPSIS

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

DESCRIPTION

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  op‐
20       eration.  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,  un‐
28       qualified  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 DE‐
45       VICE 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  oc‐
56       curs  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

OPTIONS

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 de‐
89              faults to 0. See the LISTS section below. In most cases this bit
90              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  CA‐
99              PACITY 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 in‐
107              terpretation:
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  pa‐
120              rameter list header. It will "disable certification". Certifica‐
121              tion verifies that blocks are usable during the format  process.
122              Using  this  option  may  speed  the  format but --ffmt=FFMT, if
123              available, would probably be better. The default action of  this
124              utility  (i.e.  when  this  option is not given) is to clear the
125              DCRT bit thereby requesting "media certification"  (also  unless
126              another  option needs it, the FOV bit will be cleared). When the
127              DCRT bit is set, the FOV bit must also be  set  hence  sg_format
128              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 sg_re‐
149              quests(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  de‐
161              vice  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  be‐
179              tween  0 and 3.  The default value is 0. The FMTPINFO field from
180              SBC-3 revision 16 is a 2 bit field (bits 7 and 6 of  byte  1  in
181              the  cdb). Prior to that revision it was a single bit field (bit
182              7 of byte 1 in the cdb) and there was an accompanying bit called
183              RTO_REQ  (bit  6  of  byte 1 in the cdb). The deprecated options
184              "--pinfo" and "--rto-req" represent the older usage. This option
185              should  be  used  in their place. See the PROTECTION INFORMATION
186              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 in‐
226              ternally. This option does not set the LONGLIST bit in the  FOR‐
227              MAT  UNIT command. The LONGLIST bit is set as required depending
228              other parameters (e.g. when '--pie=PIE' is greater than zero).
229
230       -M, --mode=MP
231              MP is a mode page number (0 to 62 inclusive) that will  be  used
232              for  reading and perhaps changing the device logical block size.
233              The default is 1 which is the  Read-Write  Error  Recovery  mode
234              page.
235              Preferably  the chosen (or default) mode page should be saveable
236              (i.e.  accept the SP bit set in the  MODE  SELECT  command  used
237              when the logical block size is being changed). Recent version of
238              this utility will retry a MODE SELECT if the SP=1 variant  fails
239              with  a  sense  key of ILLEGAL REQUEST.  That retry will use the
240              same MODE SELECT command but with SP=0 .
241
242       -P, --pfu=PFU
243              sets the "Protection Field Usage" field in the  parameter  block
244              associated  with a FORMAT UNIT command to PFU. The default value
245              is 0, the only other defined value currently is 1. See the  PRO‐
246              TECTION INFORMATION section below for more information.
247
248       -q, --pie=PIE
249              sets  the  "Protection Interval Exponent" field in the parameter
250              block associated with a FORMAT UNIT command to PIE. The  default
251              value  is  0.   PIE can only be non-zero with protection types 2
252              and 3.  The value of 0 is typical for 512 byte blocks; with 4096
253              byte  blocks  a value of 3 may be appropriate (i.e. 8 protection
254              intervals interleaved with 4096 bytes of user  data).  A  device
255              may  not  support any non-zero values. This field first appeared
256              in SBC-3 revision 18.
257
258       -p, --pinfo
259              this option is deprecated, use  the  --fmtpinfo=FPI  option  in‐
260              stead.  If used, then it sets bit 7 of byte 1 in the FORMAT UNIT
261              cdb and that is  equivalent  to  setting  --fmtpinfo=2.  [So  if
262              --pinfo is used (plus --fmtpinfo=FPI and --pfu=PFU are not given
263              or their arguments are 0) then protection type 1 is selected.]
264
265       -x, --poll=PT
266              where PT is the type of poll used. If PT is 0 then a  TEST  UNIT
267              READY  command  is  used,  otherwise  a REQUEST SENSE command is
268              used. The default is currently 0 but this will change  to  1  in
269              the near future. See the NOTES sections below.
270
271       -E, --preset=ID
272              this  option  instructs this utility to issue a SCSI FORMAT WITH
273              PRESET command. The PRESET IDENTIFIER field in that cdb  is  set
274              to ID. The IMMED field in that cdb is also set unless the --wait
275              option is also given, in which case it is cleared.
276
277       -Q, --quick
278              the default action (i.e. when the option is  not  given)  is  to
279              give  the user 15 seconds to reconsider doing a format operation
280              on the DEVICE.  When this option is given that step (i.e. the 15
281              second warning period) is skipped.
282
283       -r, --resize
284              rather  than  format  the  disk,  it  can be resized. This means
285              changing the number of blocks on the device reported by the READ
286              CAPACITY   command.    This  option  should  be  used  with  the
287              --count=COUNT option.  The contents of all logical blocks on the
288              media remain unchanged when this option is used. This means that
289              any resize operation can be reversed. This option cannot be used
290              together  with  either --format or a --size=LB_SZ whose argument
291              is different to the existing block size.
292
293       -R, --rto_req
294              The option is deprecated, use the --fmtpinfo=FPI option instead.
295              If used, then it sets bit 6 of byte 1 in the FORMAT UNIT cdb.
296
297       -S, --security
298              sets  the  "Security Initialization" (SI) bit in the FORMAT UNIT
299              command's initialization pattern descriptor within the parameter
300              list.  According  to  SBC-3  the  default initialization pattern
301              "shall be written using a security erasure write technique". See
302              the  NOTES  section on the SCSI SANITIZE command. If this option
303              is given then the --ip_def option cannot be given.
304
305       -6, --six
306              Use 6 byte variants of MODE SENSE and MODE SELECT.  The  default
307              action  is to use the 10 byte variants. Some MO drives need this
308              option set when doing a format.
309
310       -s, --size=LB_SZ
311              where LB_SZ is the logical block size (i.e. number of user bytes
312              in  each  block)  to  format the device to. The default value is
313              whatever is currently reported by the block descriptor in a MODE
314              SENSE command. If the block size given by this option is differ‐
315              ent from the current value then a MODE SELECT command is used to
316              change  it  prior  to  the FORMAT UNIT command being started (as
317              recommended in the SBC standards). Some SCSI disks have 512 byte
318              logical  blocks  by default and allow an alternate logical block
319              size of 4096 bytes. If the given size  in  unacceptable  to  the
320              disk,  most  likely an "Invalid field in parameter list" message
321              will appear in sense data (requires the use of  '-v'  to  decode
322              sense data).
323              Note that formatting a disk to add or remove protection informa‐
324              tion is not regarded as a change to its logical  block  size  so
325              this option should not be used.
326
327       -T, --tape=FM
328              will  send a FORMAT MEDIUM command to the DEVICE with its FORMAT
329              field set to FM. This option is used to prepare a tape (i.e. the
330              "medium") in a tape drive for use. Values for FM include 0 to do
331              the "default" format; 1 to partition a volume and 2 to do a  de‐
332              fault format then partition.
333
334       -m, --timeout=SECS
335              where  SECS  is  the  FORMAT  UNIT, FORMAT WITH PRESET or FORMAT
336              MEDIUM command timeout in seconds. SECS will only be used if  it
337              exceeds  the  internal  timeout which is 20 seconds if the IMMED
338              bit is set and 72000 seconds (20 hours) or higher if  the  IMMED
339              bit  is  not set. If the disk size exceeds 4 TB then the timeout
340              value is increased to 144000 seconds (40 hours).  And if  it  is
341              greater  than 8 TB then the timeout value is increased to 288000
342              seconds (80 hours). If the timeout is exceeded then the  operat‐
343              ing  system will typically abort the command. Aborting a command
344              may escalate to a LUN reset (or worse). A timeout may also leave
345              the  disk  or tape format operation incomplete. And that may re‐
346              sult in the disk or tape being in a "format corrupt"  state  re‐
347              quiring  another format to remedy the situation.  So for various
348              reasons command timeouts are best avoided.
349
350       -v, --verbose
351              increase the level of verbosity,  (i.e.  debug  output).  "-vvv"
352              gives a lot more debug output.
353
354       -y, --verify
355              set the VERIFY bit in the FORMAT MEDIUM cdb. The default is that
356              the VERIFY bit is clear. This option  is  only  appropriate  for
357              tapes.
358
359       -V, --version
360              print the version string and then exit.
361
362       -w, --wait
363              the  default format action is to set the "IMMED" bit in the FOR‐
364              MAT UNIT command's (short)  parameter  header.  If  this  option
365              (i.e.  --wait)  is  given  then  the  "IMMED" bit is not set. If
366              --wait is given then the FORMAT UNIT, FORMAT WITH PRESET or FOR‐
367              MAT  MEDIUM  command  waits until the format operation completes
368              before returning its response. This can be many hours  on  large
369              disks. See the --timeout=SECS option.
370              Alternatively  this option may be useful when used together with
371              --ffmt=FFMT (and FFMT greater than 0) since the fast format  may
372              only be a matter of seconds.
373

LISTS

375       The  SBC-3 draft (revision 20) defines PLIST, CLIST, DLIST and GLIST in
376       section 4.10 on "Medium defects". Briefly, the PLIST is  the  "primary"
377       list of manufacturer detected defects, the CLIST ("certification" list)
378       contains those detected during the format operation,  the  DLIST  is  a
379       list of defects that can be given to the format operation. The GLIST is
380       the grown list which starts in the format process  as  CLIST+DLIST  and
381       can  "grow"  later due to automatic reallocation (see the ARRE and AWRE
382       bits in the Read-Write Error Recovery mode page  (see  sdparm(8)))  and
383       use of the SCSI REASSIGN BLOCKS command (see sg_reassign(8)).
384
385       By the SBC-3 standard (following draft revision 36) the CLIST and DLIST
386       had been removed, leaving PLIST and GLIST. Only  PLIST  and  GLIST  are
387       found in the SBC-4 drafts.
388
389       The  CMPLST  bit  (controlled  by  the  --cmplst=0|1 option) determines
390       whether the existing GLIST, when the format operation  is  invoked,  is
391       taken  into  account.  The  sg_format  utility sets the FOV bit to zero
392       which causes DPRY=0, so the PLIST is taken into account, and DCRT=0, so
393       the CLIST is generated and used during the format process.
394
395       The  sg_format  utility does not permit a user to provide a defect list
396       (i.e. DLIST).
397

PROTECTION INFORMATION

399       Protection Information (PI) is additional information held with logical
400       blocks  so  that  an  application and/or host bus adapter can check the
401       correctness of those logical blocks. PI is placed in one or  more  pro‐
402       tection  intervals  interleaved  in each logical block. Each protection
403       interval follows the user data to which it refers. A protection  inter‐
404       val contains 8 bytes made up of a 2 byte "logical block guard" (CRC), a
405       2 byte "logical block application guard", and a 4 byte  "logical  block
406       reference tag". Devices with 512 byte logical block size typically have
407       one protection interval appended, making its  logical  block  data  520
408       bytes long. Devices with 4096 byte logical block size often have 8 pro‐
409       tection intervals spread across its logical block data for a total size
410       of  4160 bytes. Note that for all other purposes the logical block size
411       is considered to be 512 and 4096 bytes respectively.
412
413       The SBC-3 standard have added several "protection types" to the PI  in‐
414       troduced in the SBC-2 standard. SBC-3 defines 4 protection types (types
415       0 to 3) with protection type 0 meaning no PI is maintained. While a de‐
416       vice may support one or more protection types, it can only be formatted
417       with 1 of the 4. To change a  device's  protection  type,  it  must  be
418       re-formatted.   For  more information see the Protection Information in
419       section 4.21 of draft SBC-4 revision 16.
420
421       A device that supports PI information (i.e. supports one or  more  pro‐
422       tection  types  1,  2 and 3) sets the "PROTECT" bit in its standard IN‐
423       QUIRY response. It also sets the SPT field in the EXTENDED INQUIRY  VPD
424       page  response  to  indicate  which protection types it supports. Given
425       PROTECT=1 then SPT=0 implies the device supports PI type 1 only,  SPT=1
426       implies the device supports PI types 1 and 2, and various other non-ob‐
427       vious mappings up to SPT=7 which implies protection types 1,  2  and  3
428       are  supported.  The  current protection type of a disk can be found in
429       the "P_TYPE" and "PROT_EN" fields in the response of  a  READ  CAPACITY
430       (16) command (e.g. with the 'sg_readcap --long' utility).
431
432       Given  that  a device supports a particular protection type, a user can
433       then choose to format that disk with that protection  type  by  setting
434       the  "FMTPINFO"  and "Protection Field Usage" fields in the FORMAT UNIT
435       command.  Those  fields  correspond  to  the  --fmtpinfo=FPI  and   the
436       --pfu=PFU  options  in this utility. The list below shows the four pro‐
437       tection types followed by the options of this utility needed to  select
438       them:
439         0 : --fmtpinfo=0 --pfu=0
440         1 : --fmtpinfo=2 --pfu=0
441         2 : --fmtpinfo=3 --pfu=0
442         3 : --fmtpinfo=3 --pfu=1
443       The default value of FPI (in --fmtpinfo=FPI) is 0 and the default value
444       of PFU (in --pfu=PFU) is 0. So if neither --fmtpinfo=FPI nor  --pfu=PFU
445       are  given  then  protection type 0 (i.e. no protection information) is
446       chosen.
447

NOTES

449       After a format that changes the logical block size  or  the  number  of
450       logical  blocks  on a disk, the operating system may need to be told to
451       re-initialize its setting for that disk. In  Linux  that  can  be  done
452       with:
453           echo 1 > /sys/block/sd{letter(s)}/device/rescan
454       where  "letter(s)" will be between 'a' and 'zzz'. The lsscsi utility in
455       Linux can be used to check the various namings of a disk.
456
457       The SBC-2 standard states that the REQUEST SENSE command should be used
458       for  obtaining progress indication when the format command is underway.
459       However, tests on a selection of disks shows that TEST UNIT READY  com‐
460       mands  yield  progress indications (but not REQUEST SENSE commands). So
461       the current version of this utility defaults to using TEST  UNIT  READY
462       commands  to  poll the disk to find out the progress of the format. The
463       --poll=PT option has been added to control this.
464
465       When the --format, --preset=ID or --tape=FM option is given without the
466       --wait  option  then  the corresponding SCSI command is issued with the
467       IMMED bit set which causes the SCSI command  to  return  after  it  has
468       started  the  format operation. The --early option will cause sg_format
469       to exit at that point. Otherwise the DEVICE is polled every 60  seconds
470       or  every  10  seconds  if FFMT is non-zero. The poll is with TEST UNIT
471       READY or REQUEST SENSE commands until one reports an "all clear"  (i.e.
472       the  format  operation  has completed). Normally these polling commands
473       will result in a progress indicator (expressed as a  percentage)  being
474       output  to the screen. If the user gets bored watching the progress re‐
475       port then sg_format process can be  terminated  (e.g.  with  control-C)
476       without  affecting the format operation which continues. However a tar‐
477       get or device reset (or a power cycle) will probably cause  the  format
478       to cease and the DEVICE to become "format corrupt".
479
480       When  the  --format (--preset=ID or --tape) and --wait options are both
481       given then this utility may take a long time to return.  In  this  case
482       care should be taken not to send any other SCSI commands to the disk as
483       it may not respond leaving those commands queued behind the active for‐
484       mat  command.  This  may  cause  a  timeout  in the OS driver (in a lot
485       shorter period than 20 hours applicable  to  some  format  operations).
486       This  may result in the OS resetting the disk leaving the format opera‐
487       tion incomplete. This may leave the disk in a  "format  corrupt"  state
488       requiring  another  format to remedy the situation. Modern SCSI devices
489       should yield a "not ready" sense key with an additional sense  indicat‐
490       ing  a  format  is in progress. With older devices the user should take
491       precautions that nothing attempts to access a device while it is  being
492       formatted.  Unmounting  in  mounted  file  systems on a DEVICE prior to
493       calling this utility is strongly advised.
494
495       When the block size (i.e. the number of bytes in each block) is changed
496       on  a  disk two SCSI commands must be sent: a MODE SELECT to change the
497       block size followed by a FORMAT command. If  the  MODE  SELECT  command
498       succeeds  and the FORMAT fails then the disk may be in a state that the
499       standard calls "format corrupt". A block  descriptor  in  a  subsequent
500       MODE SENSE will report the requested new block size while a READ CAPAC‐
501       ITY command will report the existing (i.e. previous) block size. Alter‐
502       natively  the  READ  CAPACITY command may fail, reporting the device is
503       not ready, potentially requiring a format. The solution to this  situa‐
504       tion is to do a format again (and this time the new block size does not
505       have to be given) or change the block size back to the original size.
506
507       The SBC-2 standard states that the block count can be set back  to  the
508       manufacturer's  maximum  recommended value in a format or resize opera‐
509       tion.  This can be done by placing an address of 0xffffffff (or the  64
510       bit equivalent) in the appropriate block descriptor field to a MODE SE‐
511       LECT command. In signed (two's complement) arithmetic that value corre‐
512       sponds  to  '-1'. So a --count=-1 causes the block count to be set back
513       to the manufacturer's maximum recommended value. To see  exactly  which
514       SCSI  commands  are being executed and parameters passed add the "-vvv"
515       option to the sg_format command line.
516
517       The FMTDATA field shown in the FORMAT UNIT cdb does not have  a  corre‐
518       sponding  option  in  this utility. When set in the cdb it indicates an
519       additional parameter list will be sent to the  DEVICE  along  with  the
520       cdb.  It  is set as required, basically when any field in the parameter
521       list header is set.
522
523       Short stroking is a technique to trade off capacity for performance  on
524       hard  disks.  "Hard"  disk  is often used to mean a storage device with
525       spinning platters which contain the user data. Solid State  Disk  (SSD)
526       is the newer form of storage device that contains no moving parts. Hard
527       disk performance is usually highest on the outer  tracks  (usually  the
528       lower logical block addresses) so by resizing or reformatting a disk to
529       a smaller capacity, average performance will usually be increased.
530
531       Other utilities may be useful in finding  information  associated  with
532       formatting.  These include sg_inq(8) to fetch standard INQUIRY informa‐
533       tion (e.g. the PROTECT bit) and to fetch the EXTENDED INQUIRY VPD  page
534       (e.g.  RTO  and GRD_CHK bits). The sdparm(8) utility can be used to ac‐
535       cess and potentially change the now obsolete format mode page.
536
537       scsiformat is another utility available for formatting SCSI disks  with
538       Linux.  It  dates  from 1997 (most recent update) and may be useful for
539       disks whose firmware is of that vintage.
540
541       The COUNT numeric argument may include a multiplicative  suffix  or  be
542       given  in  hexadecimal.  See  the  "NUMERIC  ARGUMENTS"  section in the
543       sg3_utils(8) man page.
544
545       The SCSI SANITIZE command was introduced in SBC-3 revision  27.  It  is
546       closely related to the ATA sanitize disk feature set and can be used to
547       remove all existing data from a disk. Sanitize is more likely to be im‐
548       plemented  on modern disks (including SSDs) than FORMAT UNIT's security
549       initialization feature (see the --security option) and  in  some  cases
550       much faster.
551
552       SSDs  that  support  thin provisioning will typically unmap all logical
553       blocks during a format. The reason is to improve the  SSD's  endurance.
554       Also thin provisioned formats typically complete faster than fully pro‐
555       visioned ones on the same disk (see the  --ip_def  option).  In  either
556       case format operations on SSDs tend to be a lot faster than they are on
557       hard disks with spinning media.
558

TAPE

560       Tape system use a variant of the FORMAT UNIT  command  used  on  disks.
561       Tape  systems  use the FORMAT MEDIUM command which is simpler with only
562       three fields in the cdb typically used. Apart from sharing the same op‐
563       code  the  cdbs  of  FORMAT UNIT and FORMAT MEDIUM are quite different.
564       FORMAT MEDIUM's fields are VERIFY,  IMMED  and  FORMAT  (with  TRANSFER
565       LENGTH always set to 0).  The VERIFY bit field is set with the --verify
566       option. The IMMED bit is manipulated by the --wait option in  the  same
567       way  it is for disks; one difference is that if the --poll=PT option is
568       not given then it defaults to PT of 1 which means the poll is done with
569       REQUEST SENSE commands.
570
571       The  argument  given  to the --tape=FM option is used to set the FORMAT
572       field. FM can take values from "-1" to "15" where  "-1"  (the  default)
573       means don't do a tape format; value "8" to "15" are for vendor specific
574       formats. The --early option may also be used to set the IMMED  bit  and
575       then  exit this utility (rather than poll periodically until it is fin‐
576       ished). In this case the tape drive will still be busy doing the format
577       for  some  time  but, according to T10, should still respond in full to
578       the INQUIRY and REPORT LUNS commands. Other commands (including REQUEST
579       SENSE)  should  yield  a "not ready" sense key with an additional sense
580       code of "Logical unit not ready, format in progress". Additionally  RE‐
581       QUEST SENSE should contain a progress indication in its sense data.
582
583       When  FM  is 1 or 2 then the settings in the Medium partition mode page
584       control the partitioning. That mode page can  be  viewed  and  modified
585       with the sdparm utility.
586
587       Prior  to  invoking  this utility the tape may need to be positioned to
588       the beginning of partition 0. In Linux that can typically be done  with
589       the mt utility (e.g. 'mt -f /dev/st0 rewind').
590

EXAMPLES

592       These  examples  use  Linux  device names. For suitable device names in
593       other supported Operating Systems see the sg3_utils(8) man page.
594
595       In the first example below simply find out the existing block count and
596       size derived from two sources: a block descriptor in a MODE SELECT com‐
597       mand response and from the response of a  READ  CAPACITY  commands.  No
598       changes are made:
599
600          # sg_format /dev/sdm
601
602       Now a simple format, leaving the block count and size as they were pre‐
603       viously.  The FORMAT UNIT command is executed in IMMED mode and the de‐
604       vice is polled every 60 seconds to print out a progress indication:
605
606          # sg_format --format /dev/sdm
607
608       Now the same format, but waiting (passively) until the format operation
609       is complete:
610
611          # sg_format --format --wait /dev/sdm
612
613       Next is a format in which the block size is changed to  520  bytes  and
614       the  block  count  is set to the manufacturer's maximum value (for that
615       block size). Note, not all disks support changing the block size:
616
617          # sg_format --format --size=520 /dev/sdm
618
619       Now a resize operation so that only the first 0x10000 (65536) blocks on
620       a disk are accessible. The remaining blocks remain unaltered.
621
622          # sg_format --resize --count=0x10000 /dev/sdm
623
624       Now resize the disk back to its normal (maximum) block count:
625
626          # sg_format --resize --count=-1 /dev/sdm
627
628       One  reason  to  format  a  SCSI disk is to add protection information.
629       First check which protection types are supported by a disk (by checking
630       the  SPT  field in the Extended inquiry VPD page together with the Pro‐
631       tect bit in the standard inquiry response):
632
633          # sg_vpd -p ei -l /dev/sdb
634          extended INQUIRY data VPD page:
635            ACTIVATE_MICROCODE=0
636            SPT=1 [protection types 1 and 2 supported]
637            ....
638
639       Format with type 1 protection:
640
641          # sg_format --format --fmtpinfo=2 /dev/sdm
642
643       After a successful format with type  1  protection,  READ  CAPACITY(16)
644       should show something like this:
645
646          # sg_readcap -l /dev/sdm
647          Read Capacity results:
648             Protection:  prot_en=1,  p_type=0, p_i_exponent=0 [type 1 protec‐
649       tion]
650             Logical block provisioning: lbpme=0, lbprz=0
651             ....
652
653       To format with type 3 protection:
654
655          # sg_format --format --fmtpinfo=3 --pfu=1 /dev/sdm
656
657       For the disk shown above this will probably fail because  the  Extended
658       inquiry VPD page showed only types 1 and 2 protection are supported.
659
660       Here  are examples of using fast format (FFMT field in FORMAT UNIT cdb)
661       to quickly switch between 512 and 4096 byte logical block size.  Assume
662       disk  starts  with  4096 byte logical block size and all important data
663       has been backed up.
664
665          # sg_format --format --ffmt=1 --size=512 /dev/sdd
666
667       Now /dev/sdd should have 512 byte logical block size. And to switch  it
668       back:
669
670          # sg_format --format --ffmt=1 --size=4096 /dev/sdd
671
672       Since  fast  formats  can be very quick (a matter of seconds) using the
673       --wait option may be appropriate.
674
675       And to use the Format with preset  command  this  invocation  could  be
676       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.  "de‐
682       fault  host  aware zoned block device model with 512 bytes of user data
683       in each logical block").  That VPD page can be viewed with  the  sg_vpd
684       utility.
685

EXIT STATUS

687       The  exit status of sg_format is 0 when it is successful. Otherwise see
688       the sg3_utils(8) man page. Unless the --wait option is given, the  exit
689       status  may  not reflect the success of otherwise of the format.  Using
690       sg_turs(8) and sg_readcap(8) after the format operation may be wise.
691
692       The Unix convention is that "no news is good news" but that  can  be  a
693       bit unnerving after an operation like format, especially if it finishes
694       quickly (i.e. before the first  progress  poll  is  sent).  Giving  the
695       --verbose  option once should supply enough additional output to settle
696       those nerves.
697

AUTHORS

699       Written by Grant Grundler, James Bottomley and Douglas Gilbert.
700

REPORTING BUGS

702       Report bugs to <dgilbert at interlog dot com>.
703
705       Copyright © 2005-2020  Grant  Grundler,  James  Bottomley  and  Douglas
706       Gilbert
707       This  software is distributed under the GPL version 2. There is NO war‐
708       ranty; not even for MERCHANTABILITY or FITNESS FOR  A  PARTICULAR  PUR‐
709       POSE.
710

SEE ALSO

712       sg_turs(8), sg_requests(8), sg_inq(8), sg_modes(8), sg_vpd(8), sg_reas‐
713       sign(8),   sg_readcap(8),   sg3_utils(8),   sg_sanitize(8)   [all    in
714       sg3_utils],  lsscsi(8),  mt(mt-st),  sdparm(8),  scsiformat  (old), hd‐
715       parm(8)
716
717
718
719sg3_utils-1.45                   January 2020                     SG_FORMAT(8)
Impressum