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] [--resize]  [--rto_req]  [--security]  [--six]  [--size=SIZE]
13       [--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       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  (apart  from  a  DEVICE)  it
36       prints  out  the  existing  block size and block count derived from two
37       sources. These two sources are a block descriptor in the response to  a
38       MODE  SENSE  command  and  the response to a READ CAPACITY command. The
39       reason for this double check is to detect a "format corrupt" state (see
40       NOTES section). This usage will not modify the disk.
41
42       When  this utility is used with the "--format" (or "-F") option it will
43       attempt to format the given DEVICE. There is a 10 second  pause  during
44       which time the user is invited (twice 5 seconds apart) to abort sg_for‐
45       mat. This occurs just prior the SCSI FORMAT UNIT command being  issued.
46       See the NOTES section for more information.
47
48       Recent  SBC-3  drafts add several "protection types" to the "protection
49       information" introduced in the  SBC-2  standard.  See  the  "protection
50       information"  section  (section 4.18 in draft SBC-3 rev 18). 8 bytes of
51       protection information are added to each block (a 2 byte "logical block
52       guard"  (CRC), a 2 byte "logical block application guard", and a 4 byte
53       "logical block reference  tag").  A  device  that  supports  protection
54       information  sets  the  "PROTECT" bit in its standard INQUIRY response.
55       The "FMTPINFO" field in in the FORMAT UNIT command cdb plus  the  "Pro‐
56       tection  Field  Usage" in the parameter header are associated with pro‐
57       tection information and can be set by this utility.
58

OPTIONS

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

LISTS

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

NOTES

256       The SBC-2 standard states that the REQUEST SENSE command should be used
257       for  obtaining  a progress indication when the format command is under‐
258       way.  However, tests on a selection of recent  disks  shows  that  TEST
259       UNIT  READY  commands yield progress indications (but not REQUEST SENSE
260       commands). So the current version of this utility uses TEST UNIT  READY
261       commands to poll the disk to find out the progress of the format. A new
262       option may be required to handle this when disks catch up.
263
264       When the --format option is given without the --wait  option  then  the
265       SCSI  FORMAT UNIT command is issued with the IMMED bit set which causes
266       the SCSI command to return after it has started the  format  operation.
267       The  --early option will cause sg_format to exit at that point.  Other‐
268       wise the DEVICE is polled every 30 seconds with TEST  UNIT  READY  com‐
269       mands  until  it  reports an "all clear" (i.e. the format operation has
270       completed). Normally these polling commands will result in  a  progress
271       indicator  (expressed  as  a percentage) being output to the screen. If
272       the user gets bored watching the progress report then sg_format process
273       can  be  terminated  (e.g. with control-C) without affecting the format
274       operation which continues. However a bus or device reset  (or  a  power
275       cycle) will probably cause the device to become "format corrupt".
276
277       When  the  --format and --wait options are both given then this utility
278       may take a long time to return. In this case care should be  taken  not
279       to send any other SCSI commands to the disk as it may not respond leav‐
280       ing those commands queued behind the active format  command.  This  may
281       cause  a timeout in the OS driver (in a lot shorter period than 4 hours
282       applicable to some format operations). This may result in the OS reset‐
283       ting  the  disk leaving the format operation incomplete. This may leave
284       the disk in a "format corrupt" state requiring another format to remedy
285       the situation.
286
287       When the block size (i.e. the number of bytes in each block) is changed
288       on a disk two SCSI commands must be sent: a MODE SELECT to  change  the
289       block  size  followed  by  a FORMAT command. If the MODE SELECT command
290       succeeds and the FORMAT fails then the disk may be in a state that  the
291       draft  standard  calls "format corrupt". A block descriptor in a subse‐
292       quent MODE SENSE will report the requested new block size while a  READ
293       CAPACITY  command will report the existing (i.e. different) block size.
294       Alternatively the READ CAPACITY command may fail, reporting the  device
295       is not ready, potentially requiring a format. The solution to this sit‐
296       uation is to do a format again (and this time the new block  size  does
297       not  have  to  be  given) or change the block size back to the original
298       size.
299
300       The SBC-2 standard states that the block count can be set back  to  the
301       manufacturer's  maximum  recommended value in a format or resize opera‐
302       tion. This can be done by placing an address of 0xffffffff (or  the  64
303       bit  equivalent)  in  the  appropriate block descriptor field to a MODE
304       SELECT command. In signed (two's complement) arithmetic that value cor‐
305       responds to '-1'. So a --count=-1 causes the block count to be set back
306       to the manufacturer's maximum recommended value. To see  exactly  which
307       SCSI  commands  are  being executed and parameters passed add "-vvv" to
308       the sg_format command line.
309
310       Short stroking is a technique to trade off  capacity  for  performance.
311       Disk  performance  is  usually  highest on the outer tracks (i.e. lower
312       logical block addresses) so by resizing or reformatting  a  disk  to  a
313       smaller capacity, average performance will usually be increased.
314
315       Other  utilities  may  be useful in finding information associated with
316       formatting. These include sg_inq(8) to fetch standard INQUIRY  informa‐
317       tion  (e.g. the PROTECT bit) and to fetch the extended INQUIRY VPD page
318       (e.g. RTO and GRD_CHK bits). The  sdparm(8)  utility  can  be  used  to
319       access and potentially change the now obsolete format mode page.
320
321       scsiformat  is another utility available for formatting SCSI disks with
322       linux. It dates from 1997 (most recent update) and may  be  useful  for
323       disks whose firmware is of that vintage.
324
325       The  COUNT  numeric  argument may include a multiplicative suffix or be
326       given in hexadecimal.  See  the  "NUMERIC  ARGUMENTS"  section  in  the
327       sg3_utils(8) man page.
328

EXAMPLES

330       In the first example below simply find out the existing block count and
331       size derived from two sources: a block descriptor in a MODE SELECT com‐
332       mand  response  and  from  the response of a READ CAPACITY commands. No
333       changes are made:
334
335          sg_format /dev/sdm
336
337       Now a simple format, leaving the block count and size as they were pre‐
338       viously.   The  FORMAT  UNIT  command is executed in IMMED mode and the
339       device is polled every 30 seconds to print out a progress indication:
340
341          sg_format --format /dev/sdm
342
343       Now the same format, but waiting (passively) until the format operation
344       is complete:
345
346          sg_format --format --wait /dev/sdm
347
348       Next  is  a  format in which the block size is changed to 520 bytes and
349       the block count is set to the manufacturer's maximum  value  (for  that
350       block size). Note, not all disks support changing the block size:
351
352          sg_format --format --size=520 /dev/sdm
353
354       Now a resize operation so that only the first 0x10000 (65536) blocks on
355       a disk are accessible. The remaining blocks remain unaltered.
356
357          sg_format --resize --count=0x10000 /dev/sdm
358
359       Now resize the disk back to its normal (maximum) block count:
360
361          sg_format --resize --count=-1 /dev/sdm
362
363       Format with type 1 protection:
364
365          sg_format --format --fmtpinfo=3 --pfu /dev/sdm
366

EXIT STATUS

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

AUTHORS

374       Written by Grant Grundler, James Bottomley and Douglas Gilbert.
375

REPORTING BUGS

377       Report bugs to <dgilbert at interlog dot com>.
378
380       Copyright  ©  2005-2009  Grant  Grundler,  James  Bottomley and Douglas
381       Gilbert
382       This software is distributed under the GPL version 2. There is NO  war‐
383       ranty;  not  even  for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
384       POSE.
385

SEE ALSO

387       sg_turs(8), sg_requests(8), sg_inq(8), sg_modes(8), sg_vpd(8), sg_reas‐
388       sign(8), sg_readcap(8) [all in sg3_utils], sdparm(8), scsiformat (old),
389       hdparm(8)
390
391
392
393sg3_utils-1.27                    March 2009                      SG_FORMAT(8)
Impressum