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

NAME

6       sg_format - format, resize a SCSI disk or format a tape
7

SYNOPSIS

9       sg_format   [--cmplst={0|1}]   [--count=COUNT]   [--dcrt]   [--dry-run]
10       [--early] [--ffmt=FFMT] [--fmtpinfo=FPI] [--format] [--help] [--ip-def]
11       [--long]  [--mode=MP]  [--pfu=PFU]  [--pie=PIE]  [--pinfo]  [--poll=PT]
12       [--quick] [--resize] [--rto_req]  [--security]  [--six]  [--size=LB_SZ]
13       [--tape=FM]   [--timeout=SECS]   [--verbose]   [--verify]   [--version]
14       [--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
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 can format modern SCSI disks and potentially change their
27       block size (if permitted) and the block count (i.e. number of  accessi‐
28       ble  blocks  on the media also known as "resizing"). Resizing a disk to
29       less than the  manufacturer's  recommended  block  count  is  sometimes
30       called  "short  stroking" (see NOTES section). Resizing the block count
31       while not changing the block size may not require a  format  operation.
32       The  SBC-2 standard (see www.t10.org) has obsoleted the "format device"
33       mode page. Many of the low level details found in that  mode  page  are
34       now  left  up  to the discretion of the manufacturer. There is a Format
35       Status log page which reports on the previous successful format  opera‐
36       tion(s).
37
38       When  this  utility  is  used  without options (i.e. it is only given a
39       DEVICE argument) it prints out the existing block size and block  count
40       derived  from  two sources. These two sources are a block descriptor in
41       the response to a MODE SENSE command and the response to a READ  CAPAC‐
42       ITY  command.   The reason for this double check is to detect a "format
43       corrupt" state (see the NOTES section). This usage will not modify  the
44       disk.
45
46       When  this utility is used with the "--format" (or "-F") option it will
47       attempt to format the given DEVICE.  In  the  absence  of  the  --quick
48       option there is a 15 second pause during which time the user is invited
49       thrice (5 seconds apart) to abort sg_format. This occurs just prior the
50       SCSI  FORMAT  UNIT command being issued. See the NOTES section for more
51       information.
52
53       Protection information (PI) is optional and is made up of one  or  more
54       protection intervals, each made up of 8 bytes associated with a logical
55       block. When PI is active each logical block will have 1, 2, 4,  8,  etc
56       protection  intervals (i.e. a power of two), interleaved with (and fol‐
57       lowing) the user data to which they refer. Four  protection  types  are
58       defined  with  protection type 0 being no protection intervals. See the
59       PROTECTION INFORMATION section below for more information.
60
61       When the --tape=FM option is given then the SCSI FORMAT MEDIUM  command
62       is sent to the DEVICE. FORMAT MEDIUM is defined in the SSC documents at
63       T10 and prepares a volume for use. That may  include  partitioning  the
64       medium. See the section below on TAPE for more information.
65

OPTIONS

67       Arguments to long options are mandatory for short options as well.  The
68       options are arranged in alphabetical order based  on  the  long  option
69       name.
70
71       -C, --cmplst={0|1}
72              sets  the CMPLST ("complete list") bit in the FORMAT UNIT cdb to
73              0 or 1.  If the value is 0 then the existing GLIST (grown  list)
74              is  taken  into  account.   If  the value is 1 then the existing
75              GLIST is ignored. CMPLST defaults  to  1  apart  from  when  the
76              --ffmt=FFMT  option's  value  is  non-zero  in which case CMPLST
77              defaults to 0. See the LISTS section below. In most  cases  this
78              bit should be left at its default value.
79
80       -c, --count=COUNT
81              where  COUNT is the number of blocks to be formatted or media to
82              be resized to. Can be used with  either  --format  or  --resize.
83              With  --format this option need not be given in which case it is
84              assumed to be zero.
85              With --format the interpretation of COUNT is:
86                (COUNT > 0) : only format the  first  COUNT  blocks  and  READ
87              CAPACITY will report COUNT blocks after format
88                (COUNT  =  0)  and  block  size unchanged : use existing block
89              count
90                (COUNT = 0) and block size changed : recommended maximum block
91              count for new block size
92                (COUNT = -1) : use recommended maximum block count
93                (COUNT < -1) : illegal
94              With  --resize  this  option  must  be  given and COUNT has this
95              interpretation:
96                (COUNT > 0) : after resize READ  CAPACITY  will  report  COUNT
97              blocks
98                (COUNT = 0) : after resize READ CAPACITY will report 0 blocks
99                (COUNT = -1) : after resize READ CAPACITY will report its max‐
100              imum number of blocks
101                (COUNT < -1) : illegal
102              In both cases if the given COUNT exceeds the maximum  number  of
103              blocks (for the block size) then the disk reports an error.  See
104              NOTES section below.
105
106       -D, --dcrt
107              this option sets the DCRT  bit  in  the  FORMAT  UNIT  command's
108              parameter list header. It will "disable certification". Certifi‐
109              cation  verifies  that  blocks  are  usable  during  the  format
110              process.  Using  this  option may speed the format.  The default
111              action of this utility (i.e. when this option is not  given)  is
112              to  clear the DCRT bit thereby requesting "media certification".
113              When the DCRT bit is set, the FOV bit must  also  be  set  hence
114              sg_format does that.
115
116       -d, --dry-run
117              this  option will parse the command line, do all the preparation
118              but bypass the actual FORMAT UNIT  or  FORMAT  MEDIUM  commands.
119              Also  if  the  options  would  cause  the  logical block size to
120              change, then the MODE SELECT command that would do that is  also
121              bypassed when the dry run option is given.
122
123       -e, --early
124              during a format operation, The default action of this utility is
125              to poll the disk every 60 seconds (or every 10 seconds  if  FFMT
126              is  non-zero)  to determine the progress of the format operation
127              until it is finished. When this option  is  given  this  utility
128              will  exit  "early", that is as soon as the format operation has
129              commenced. Then the user can monitor the progress of the ongoing
130              format  operation  with  other  utilities  (e.g.  sg_turs(8)  or
131              sg_requests(8)).  This option and --wait are mutually exclusive.
132
133       -t, --ffmt=FFMT
134              FFMT (fast format) is placed in a field of the same name in  the
135              FORMAT  UNIT cdb. The field was introduced in SBC-4 revision 10.
136              The default value is 0 which implies the former action which  is
137              typically to overwrite all blocks on the DEVICE. That can take a
138              long time (e.g. with hard disks over 10 TB in size that  can  be
139              days).  With FFMT set that time may be reduced to minutes. So it
140              is worth trying if it is available.
141              FFMT has values 1 and 2 for fast format with  3  being  reserved
142              currently.  These  two  values  include  this  description: "The
143              device server initializes the medium ... without overwriting the
144              medium  (i.e.  resources for managing medium access are initial‐
145              ized and the medium is not written)".  The difference between  1
146              and 2 concerns read operations on LBAs to which no data has been
147              written to, after the fast format. When FFMT is 1 the read oper‐
148              ation  should  return  "unspecified logical block data" and com‐
149              plete without error. When FFMT is 2 the read operation may yield
150              check  condition  status with a sense key set to hardware error,
151              medium error or command aborted. See SBC-4 revision  15  section
152              4.35 for more details.
153
154       -f, --fmtpinfo=FPI
155              sets  the  FMTPINFO  field  in  the  FORMAT  UNIT cdb to a value
156              between 0 and 3.  The default value is  0.  The  FMTPINFO  field
157              from  SBC-3 revision 16 is a 2 bit field (bits 7 and 6 of byte 1
158              in the cdb). Prior to that revision it was a  single  bit  field
159              (bit  7  of byte 1 in the cdb) and there was an accompanying bit
160              called RTO_REQ (bit 6 of byte 1  in  the  cdb).  The  deprecated
161              options  "--pinfo"  and  "--rto-req"  represent the older usage.
162              This option should be used in their place.  See  the  PROTECTION
163              INFORMATION section below for more information.
164
165       -F, --format
166              issue  a  SCSI  FORMAT  UNIT command.  This will destroy all the
167              data held on the media.  This option is required to  change  the
168              block  size of a disk. In the absence of the --quick option, the
169              user is given a 15 second count down to  ponder  the  wisdom  of
170              doing this, during which time control-C (amongst other Unix com‐
171              mands) can be used to kill this process before it does any  dam‐
172              age.
173              When  used  three times (or more) the preliminary MODE SENSE and
174              SELECT commands are bypassed, leaving only the  initial  INQUIRY
175              and  FORMAT  UNIT commands. This is for emergency use (e.g. when
176              the MODE SENSE/SELECT  commands  are  not  working)  and  cannot
177              change the logical block size.
178              See  NOTES  section for implementation details and EXAMPLES sec‐
179              tion for typical use.
180
181       -h, --help
182              print out the usage information then exit.
183
184       -I, --ip-def
185              sets the default Initialization Pattern. Some disks  (SSDs)  use
186              this  to  flag  that a format should fully provision (i.e. asso‐
187              ciate a physical block with every logical block). The same disks
188              (SSDs) might thin provision if this option is not given. If this
189              option is given then the --security option cannot be given. Also
190              accepts --ip_def for this option.
191
192       -l, --long
193              the  default  action of this utility is to assume 32 bit logical
194              block addresses. With 512 byte block size this permits more than
195              2 terabytes (almost 2 ** 41 bytes) on a single disk. This option
196              selects commands and parameters that allow for  64  bit  logical
197              block  addresses.   Specifically  this option sets the "longlba"
198              flag in the MODE SENSE (10) command and uses READ CAPACITY  (16)
199              rather  than READ CAPACITY (10). If this option is not given and
200              READ CAPACITY (10) or MODE SELECT detects a disk the needs  more
201              than  32  bits  to  represent  its logical blocks then it is set
202              internally. This option does not set the  LONGLIST  bit  in  the
203              FORMAT UNIT command. The LONGLIST bit is set as required depend‐
204              ing other parameters (e.g.  when  '--pie=PIE'  is  greater  than
205              zero).
206
207       -M, --mode=MP
208              MP  is  a mode page number (0 to 62 inclusive) that will be used
209              for reading and perhaps changing the device logical block  size.
210              The  default  is  1  which is the Read-Write Error Recovery mode
211              page.
212              Preferably the chosen (or default) mode page should be  saveable
213              (i.e.   accept  the  SP  bit set in the MODE SELECT command used
214              when the logical block size is being changed). Recent version of
215              this  utility will retry a MODE SELECT if the SP=1 variant fails
216              with a sense key of ILLEGAL REQUEST.  That retry  will  use  the
217              same MODE SELECT command but with SP=0 .
218
219       -P, --pfu=PFU
220              sets  the  "Protection Field Usage" field in the parameter block
221              associated with a FORMAT UNIT command to PFU. The default  value
222              is  0, the only other defined value currently is 1. See the PRO‐
223              TECTION INFORMATION section below for more information.
224
225       -q, --pie=PIE
226              sets the "Protection Interval Exponent" field in  the  parameter
227              block  associated with a FORMAT UNIT command to PIE. The default
228              value is 0.  PIE can only be non-zero with  protection  types  2
229              and 3.  The value of 0 is typical for 512 byte blocks; with 4096
230              byte blocks a value of 3 may be appropriate (i.e.  8  protection
231              intervals  interleaved  with  4096 bytes of user data). A device
232              may not support any non-zero values. This field  first  appeared
233              in SBC-3 revision 18.
234
235       -p, --pinfo
236              this   option  is  deprecated,  use  the  --fmtpinfo=FPI  option
237              instead.  If used, then it sets bit 7 of byte 1  in  the  FORMAT
238              UNIT  cdb and that is equivalent to setting --fmtpinfo=2. [So if
239              --pinfo is used (plus --fmtpinfo=FPI and --pfu=PFU are not given
240              or their arguments are 0) then protection type 1 is selected.]
241
242       -x, --poll=PT
243              where  PT  is the type of poll used. If PT is 0 then a TEST UNIT
244              READY command is used, otherwise  a  REQUEST  SENSE  command  is
245              used.  The  default  is currently 0 but this will change to 1 in
246              the near future. See the NOTES sections below.
247
248       -Q, --quick
249              the default action (i.e. when the option is  not  given)  is  to
250              give  the user 15 seconds to reconsider doing a format operation
251              on the DEVICE.  When this option is given that step (i.e. the 15
252              second warning period) is skipped.
253
254       -r, --resize
255              rather  than  format  the  disk,  it  can be resized. This means
256              changing the number of blocks on the device reported by the READ
257              CAPACITY   command.    This  option  should  be  used  with  the
258              --count=COUNT option.  The contents of all logical blocks on the
259              media remain unchanged when this option is used. This means that
260              any resize operation can be reversed. This option cannot be used
261              together  with  either --format or a --size=LB_SZ whose argument
262              is different to the existing block size.
263
264       -R, --rto_req
265              The option is deprecated, use the --fmtpinfo=FPI option instead.
266              If used, then it sets bit 6 of byte 1 in the FORMAT UNIT cdb.
267
268       -S, --security
269              sets  the  "Security Initialization" (SI) bit in the FORMAT UNIT
270              command's initialization pattern descriptor within the parameter
271              list.  According  to  SBC-3  the  default initialization pattern
272              "shall be written using a security erasure write technique". See
273              the  NOTES  section on the SCSI SANITIZE command. If this option
274              is given then the --ip_def option cannot be given.
275
276       -6, --six
277              Use 6 byte variants of MODE SENSE and MODE SELECT.  The  default
278              action  is to use the 10 byte variants. Some MO drives need this
279              option set when doing a format.
280
281       -s, --size=LB_SZ
282              where LB_SZ is the logical block size (i.e. number of user bytes
283              in  each  block)  to  format the device to. The default value is
284              whatever is currently reported by the block descriptor in a MODE
285              SENSE command. If the block size given by this option is differ‐
286              ent from the current value then a MODE SELECT command is used to
287              change  it  prior  to  the FORMAT UNIT command being started (as
288              recommended in the SBC standards). Some SCSI disks have 512 byte
289              logical  blocks  by default and allow an alternate logical block
290              size of 4096 bytes. If the given size  in  unacceptable  to  the
291              disk,  most  likely an "Invalid field in parameter list" message
292              will appear in sense data (requires the use of  '-v'  to  decode
293              sense data).
294              Note that formatting a disk to add or remove protection informa‐
295              tion is not regarded as a change to its logical  block  size  so
296              this option should not be used.
297
298       -T, --tape=FM
299              will  send a FORMAT MEDIUM command to the DEVICE with its FORMAT
300              field set to FM. This option is used to prepare a tape (i.e. the
301              "medium") in a tape drive for use. Values for FM include 0 to do
302              the "default" format; 1 to partition a volume  and  2  to  do  a
303              default format then partition.
304
305       -m, --timeout=SECS
306              where  SECS  is the FORMAT UNIT or FORMAT MEDIUM command timeout
307              in seconds. SECS will only be used if it  exceeds  the  internal
308              timeout  which  is  20 seconds if the IMMED bit is set and 72000
309              seconds (20 hours) or higher if the IMMED bit is not set. If the
310              disk  size  exceeds  4 TB then the timeout value is increased to
311              144000 seconds (40 hours). And if it is greater than 8  TB  then
312              the  timeout value is increased to 288000 seconds (80 hours). If
313              the timeout is exceeded then the operating system will typically
314              abort  the  command.  Aborting  a  command may escalate to a LUN
315              reset (or worse). A timeout may also leave the disk or tape for‐
316              mat  operation  incomplete.  And  that may result in the disk or
317              tape being in a "format corrupt" state requiring another  format
318              to  remedy  the  situation.  So for various reasons timeouts are
319              best avoided.
320
321       -v, --verbose
322              increase the level of verbosity,  (i.e.  debug  output).  "-vvv"
323              gives a lot more debug output.
324
325       -y, --verify
326              set the VERIFY bit in the FORMAT MEDIUM cdb. The default is that
327              the VERIFY bit is clear. This option  is  only  appropriate  for
328              tapes.
329
330       -V, --version
331              print the version string and then exit.
332
333       -w, --wait
334              the  default format action is to set the "IMMED" bit in the FOR‐
335              MAT UNIT command's (short)  parameter  header.  If  this  option
336              (i.e.  --wait)  is  given  then  the  "IMMED" bit is not set. If
337              --wait is given then the FORMAT UNIT or  FORMAT  MEDIUM  command
338              waits  until the format operation completes before returning its
339              response. This can be many hours on large disks. See the --time‐
340              out=SECS option.
341

LISTS

343       The  SBC-3 draft (revision 20) defines PLIST, CLIST, DLIST and GLIST in
344       section 4.10 on "Medium defects". Briefly, the PLIST is  the  "primary"
345       list of manufacturer detected defects, the CLIST ("certification" list)
346       contains those detected during the format operation,  the  DLIST  is  a
347       list of defects that can be given to the format operation. The GLIST is
348       the grown list which starts in the format process  as  CLIST+DLIST  and
349       can  "grow"  later due to automatic reallocation (see the ARRE and AWRE
350       bits in the Read-Write Error Recovery mode page  (see  sdparm(8)))  and
351       use of the SCSI REASSIGN BLOCKS command (see sg_reassign(8)).
352
353       By the SBC-3 standard (following draft revision 36) the CLIST and DLIST
354       had been removed, leaving PLIST and GLIST. Only  PLIST  and  GLIST  are
355       found in the SBC-4 drafts.
356
357       The  CMPLST  bit  (controlled  by  the  --cmplst=0|1 option) determines
358       whether the existing GLIST, when the format operation  is  invoked,  is
359       taken  into  account.  The  sg_format  utility sets the FOV bit to zero
360       which causes DPRY=0, so the PLIST is taken into account, and DCRT=0, so
361       the CLIST is generated and used during the format process.
362
363       The  sg_format  utility does not permit a user to provide a defect list
364       (i.e. DLIST).
365

PROTECTION INFORMATION

367       Protection Information (PI) is additional information held with logical
368       blocks  so  that  an  application and/or host bus adapter can check the
369       correctness of those logical blocks. PI is placed in one or  more  pro‐
370       tection  intervals  interleaved  in each logical block. Each protection
371       interval follows the user data to which it refers. A protection  inter‐
372       val contains 8 bytes made up of a 2 byte "logical block guard" (CRC), a
373       2 byte "logical block application guard", and a 4 byte  "logical  block
374       reference tag". Devices with 512 byte logical block size typically have
375       one protection interval appended, making its  logical  block  data  520
376       bytes long. Devices with 4096 byte logical block size often have 8 pro‐
377       tection intervals spread across its logical block data for a total size
378       of  4160 bytes. Note that for all other purposes the logical block size
379       is considered to be 512 and 4096 bytes respectively.
380
381       The SBC-3 standard have added several  "protection  types"  to  the  PI
382       introduced  in  the  SBC-2  standard.  SBC-3 defines 4 protection types
383       (types 0 to 3) with protection type 0  meaning  no  PI  is  maintained.
384       While a device may support one or more protection types, it can only be
385       formatted with 1 of the 4. To change a  device's  protection  type,  it
386       must be re-formatted.  For more information see the Protection Informa‐
387       tion in section 4.22 of draft SBC-4 revision 15.
388
389       A device that supports PI information (i.e. supports one or  more  pro‐
390       tection  types  1,  2  and  3)  sets  the "PROTECT" bit in its standard
391       INQUIRY response. It also sets the SPT field in  the  EXTENDED  INQUIRY
392       VPD page response to indicate which protection types it supports. Given
393       PROTECT=1 then SPT=0 implies the device supports PI type 1 only,  SPT=1
394       implies  the  device  supports  PI  types  1  and  2, and various other
395       non-obvious mappings up to SPT=7 which implies protection  types  1,  2
396       and 3 are supported. The current protection type of a disk can be found
397       in the "P_TYPE" and "PROT_EN" fields in the response of a READ CAPACITY
398       (16) command (e.g. with the 'sg_readcap --long' utility).
399
400       Given  that  a device supports a particular protection type, a user can
401       then choose to format that disk with that protection  type  by  setting
402       the  "FMTPINFO"  and "Protection Field Usage" fields in the FORMAT UNIT
403       command.  Those  fields  correspond  to  the  --fmtpinfo=FPI  and   the
404       --pfu=PFU  options  in this utility. The list below shows the four pro‐
405       tection types followed by the options of this utility needed to  select
406       them:
407         0 : --fmtpinfo=0 --pfu=0
408         1 : --fmtpinfo=2 --pfu=0
409         2 : --fmtpinfo=3 --pfu=0
410         3 : --fmtpinfo=3 --pfu=1
411       The default value of FPI (in --fmtpinfo=FPI) is 0 and the default value
412       of PFU (in --pfu=PFU) is 0. So if neither --fmtpinfo=FPI nor  --pfu=PFU
413       are  given  then  protection type 0 (i.e. no protection information) is
414       chosen.
415

NOTES

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

TAPE

525       Tape  system  use  a  variant of the FORMAT UNIT command used on disks.
526       Tape systems use the FORMAT MEDIUM command which is simpler  with  only
527       three  fields  in  the  cdb typically used. Apart from sharing the same
528       opcode the cdbs of FORMAT UNIT and FORMAT MEDIUM are  quite  different.
529       FORMAT  MEDIUM's  fields  are  VERIFY,  IMMED and FORMAT (with TRANSFER
530       LENGTH always set to 0).  The VERIFY bit field is set with the --verify
531       option.  The  IMMED bit is manipulated by the --wait option in the same
532       way it is for disks; one difference is that if the --poll=PT option  is
533       not given then it defaults to PT of 1 which means the poll is done with
534       REQUEST SENSE commands.
535
536       The argument given to the --tape=FM option is used to  set  the  FORMAT
537       field.  FM  can  take values from "-1" to "15" where "-1" (the default)
538       means don't do a tape format; value "8" to "15" are for vendor specific
539       formats.  The  --early option may also be used to set the IMMED bit and
540       then exit this utility (rather than poll periodically until it is  fin‐
541       ished). In this case the tape drive will still be busy doing the format
542       for some time but, according to T10, should still respond  in  full  to
543       the INQUIRY and REPORT LUNS commands. Other commands (including REQUEST
544       SENSE) should yield a "not ready" sense key with  an  additional  sense
545       code  of  "Logical  unit  not  ready, format in progress". Additionally
546       REQUEST SENSE should contain a progress indication in its sense data.
547
548       When FM is 1 or 2 then the settings in the Medium partition  mode  page
549       control  the  partitioning.  That  mode page can be viewed and modified
550       with the sdparm utility.
551
552       Prior to invoking this utility the tape may need to  be  positioned  to
553       the  beginning of partition 0. In Linux that can typically be done with
554       the mt utility (e.g. 'mt -f /dev/st0 rewind').
555

EXAMPLES

557       These examples use Linux device names. For  suitable  device  names  in
558       other supported Operating Systems see the sg3_utils(8) man page.
559
560       In the first example below simply find out the existing block count and
561       size derived from two sources: a block descriptor in a MODE SELECT com‐
562       mand  response  and  from  the response of a READ CAPACITY commands. No
563       changes are made:
564
565          # sg_format /dev/sdm
566
567       Now a simple format, leaving the block count and size as they were pre‐
568       viously.   The  FORMAT  UNIT  command is executed in IMMED mode and the
569       device is polled every 60 seconds to print out a progress indication:
570
571          # sg_format --format /dev/sdm
572
573       Now the same format, but waiting (passively) until the format operation
574       is complete:
575
576          # sg_format --format --wait /dev/sdm
577
578       Next  is  a  format in which the block size is changed to 520 bytes and
579       the block count is set to the manufacturer's maximum  value  (for  that
580       block size). Note, not all disks support changing the block size:
581
582          # sg_format --format --size=520 /dev/sdm
583
584       Now a resize operation so that only the first 0x10000 (65536) blocks on
585       a disk are accessible. The remaining blocks remain unaltered.
586
587          # sg_format --resize --count=0x10000 /dev/sdm
588
589       Now resize the disk back to its normal (maximum) block count:
590
591          # sg_format --resize --count=-1 /dev/sdm
592
593       One reason to format a SCSI disk  is  to  add  protection  information.
594       First check which protection types are supported by a disk (by checking
595       the SPT field in the Extended inquiry VPD page together with  the  Pro‐
596       tect bit in the standard inquiry response):
597
598          # sg_vpd -p ei -l /dev/sdb
599          extended INQUIRY data VPD page:
600            ACTIVATE_MICROCODE=0
601            SPT=1 [protection types 1 and 2 supported]
602            ....
603
604       Format with type 1 protection:
605
606          # sg_format --format --fmtpinfo=2 /dev/sdm
607
608       After  a  successful  format  with type 1 protection, READ CAPACITY(16)
609       should show something like this:
610
611          # sg_readcap -l /dev/sdm
612          Read Capacity results:
613             Protection: prot_en=1, p_type=0, p_i_exponent=0 [type  1  protec‐
614       tion]
615             Logical block provisioning: lbpme=0, lbprz=0
616             ....
617
618       To format with type 3 protection:
619
620          # sg_format --format --fmtpinfo=3 --pfu=1 /dev/sdm
621
622       For  the  disk shown above this will probably fail because the Extended
623       inquiry VPD page showed only types 1 and 2 protection are supported.
624
625       Here are examples of using fast format (FFMT field in FORMAT UNIT  cdb)
626       to  quickly switch between 512 and 4096 byte logical block size. Assume
627       disk starts with 4096 byte logical block size and  all  important  data
628       has been backed up.
629
630          # sg_format --format --ffmt=1 --size=512 /dev/sdd
631
632       Now  /dev/sdd should have 512 byte logical block size. And to switch it
633       back:
634
635          # sg_format --format --ffmt=1 --size=4096 /dev/sdd
636

EXIT STATUS

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

AUTHORS

644       Written by Grant Grundler, James Bottomley and Douglas Gilbert.
645

REPORTING BUGS

647       Report bugs to <dgilbert at interlog dot com>.
648
650       Copyright  ©  2005-2018  Grant  Grundler,  James  Bottomley and Douglas
651       Gilbert
652       This software is distributed under the GPL version 2. There is NO  war‐
653       ranty;  not  even  for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
654       POSE.
655

SEE ALSO

657       sg_turs(8), sg_requests(8), sg_inq(8), sg_modes(8), sg_vpd(8), sg_reas‐
658       sign(8),    sg_readcap(8),   sg3_utils(8),   sg_sanitize(8)   [all   in
659       sg3_utils],  lsscsi(8),   mt(mt-st),   sdparm(8),   scsiformat   (old),
660       hdparm(8)
661
662
663
664sg3_utils-1.43                  September 2018                    SG_FORMAT(8)
Impressum