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] [--early] [--format]  [--help]
11       [--long]   [--pfu=PFU]   [--pinfo]   [--resize]   [--rto_req]   [--six]
12       [--size=SIZE] [--verbose] [--version] [--wait] DEVICE
13

DESCRIPTION

15       Not all SCSI direct access devices need to be formatted and  some  have
16       vendor  specific  formatting procedures. SCSI disks with rotating media
17       are probably the largest group that  do  support  a  'standard'  format
18       operation.  They are typically factory formatted to a block size of 512
19       bytes with the largest number of blocks that  the  manufacturer  recom‐
20       mends. That number of blocks typically leaves aside a certain number of
21       tracks and sectors for reassignment of logical block  addresses  during
22       the life of the disk.
23
24       This  utility can format modern SCSI disks and potentially change their
25       block size (if permitted) and the block count (i.e. number of  accessi‐
26       ble  blocks  on the media also known as "resizing"). Resizing a disk to
27       less than the  manufacturer's  recommended  block  count  is  sometimes
28       called  "short  stroking" (see NOTES section). Resizing the block count
29       while not changing the block size may not require a  format  operation.
30       Recent changes to the SBC-2 draft standard (see www.t10.org) have obso‐
31       leted the "format device" mode page. Many  of  the  low  level  details
32       found  in that mode page are now left up to the discretion of the manu‐
33       facturer.
34
35       When this utility is used without options (apart from  a  device  name)
36       then it prints out the existing block size and block count derived from
37       two sources. These two sources are a block descriptor in  the  response
38       to  a  MODE  SENSE command and the response to a READ CAPACITY command.
39       The reason for this double check is to detect a "format corrupt"  state
40       (see NOTES section).
41
42       A  recent  addition  in  the SBC-2 is "protection information". See the
43       section of that name (section 4.16 in draft SBC-2 rev 16). It  adds  an
44       extra  8 bytes of protection information to each block (a 2 byte "logi‐
45       cal block guard" (CRC), a 2 byte "logical block application guard", and
46       a 4 byte "logical block reference tag"). A device that supports protec‐
47       tion information sets the "protect" bit in a standard INQUIRY response.
48       The "FMTPINFO" and "RTO_REQ" bits in the FORMAT command cdb are associ‐
49       ated with protection information and can be set by this utility.
50

OPTIONS

52       Arguments to long options are mandatory for short options as well.
53
54       -C, --cmplst=0 | 1
55              sets the CMPLST ("complete list") bit in the FORMAT cdb to 0  or
56              1.   The  default  is  1 in which case the existing GLIST (grown
57              list) is ignored.  If the value is 0 then th existing  GLIST  is
58              taken into account. See the LISTS section below. Active when the
59              --format option is given. In most cases this bit should be  left
60              set;  some MO disk drives need this bit cleared. The SCSI to ATA
61              Translation (SAT) draft standard (sat-r09) requires this bit  to
62              be cleared.
63
64       -c, --count=COUNT
65              where  COUNT is the number of blocks to be formatted or media to
66              be resized to. Can be used with  either  --format  or  --resize.
67              With  --format this option need not be given in which case it is
68              assumed to be zero. With --format the  interpretation  of  COUNT
69              is:
70                (COUNT > 0) : only format the first COUNT blocks and READ
71                              CAPACITY will report COUNT blocks after format
72                (COUNT  =  0)  and  block  size unchanged : use existing block
73              count
74                (COUNT = 0) and block size changed : recommended maximum block
75                                                     count for new block size
76                (COUNT = -1) : use recommended maximum block count
77                (COUNT < -1) : illegal
78              With --resize this option must  be  given  and  COUNT  has  this
79              interpretation:
80                (COUNT > 0) : after resize READ CAPACITY will report COUNT
81                              blocks
82                (COUNT = 0) : after resize READ CAPACITY will report 0 blocks
83                (COUNT = -1) : after resize READ CAPACITY will report its
84                               maximum number of blocks
85                (COUNT < -1) : illegal
86              In  both  cases if the given COUNT exceeds the maximum number of
87              blocks (for the block size) then the disk reports an error.  See
88              NOTES section below.
89
90       -e, --early
91              this option is active when --format is given. The default action
92              of this utility is to poll the disk every 30 seconds  to  deter‐
93              mine  the progress of the format operation until it is finished.
94              When this option is given this utility will exit "early" as soon
95              as  the  format  has  commenced.  Then  the user can monitor the
96              progress of the ongoing format operation  with  other  utilities
97              (e.g.  sg_turs  or  sg_requests).  This option and --wait cannot
98              both be given.
99
100       -F, --format
101              issue a SCSI FORMAT command.  This will  destroy  all  the  data
102              held  on the media.  This option is required to change the block
103              size of a disk.  The user is given a 10  second  count  down  to
104              ponder  the  wisdom  of  doing this, during which time control-C
105              (amongst other Unix commands) can be used to kill  this  process
106              before  it does any damage. See NOTES section for implementation
107              details and EXAMPLES section for typical use.
108
109       -h, --help
110              print out the usage information then exit.
111
112       -l, --long
113              the default action of this utility is to assume 32  bit  logical
114              block  addresses. With 512 byte block size this permits almost 2
115              terabytes (almost 2 ** 41 bytes) on a single disk.  This  option
116              selects  commands  and  parameters that allow for 64 bit logical
117              block addresses.  Specifically this is the "longlba" flag in the
118              MODE  SENSE (10) command and READ CAPACITY (16) rather than READ
119              CAPACITY (10). When a  disk  supports  "protection  information"
120              then this option may also be useful.
121
122       -P, --pfu=PFU
123              sets  the  "Protection Field Usage" field in the parameter block
124              associated with a FORMAT command to PFU. The default value is 0,
125              values in the range 0 to 7 may be given.
126
127       -p, --pinfo
128              instructs  a format operation to add an extra 8 bytes of protec‐
129              tion information by setting the FMTPINFO bit in the FORMAT  com‐
130              mand cdb. Default action is not to format with protection infor‐
131              mation. Has no action unless --format is given.
132
133       -r, --resize
134              rather than format the disk,  it  can  be  resized.  This  means
135              changing the number of blocks on the device reported by the READ
136              CAPACITY  command.   This  option  should  be  used   with   the
137              --count=COUNT option.  The contents of all logical blocks on the
138              media remain unchanged when this option is used. This means that
139              any resize operation can be reversed. This option cannot be used
140              together with either --format or a --size=SIZE whose argument is
141              different to the existing block size.
142
143       -R, --rto_req
144              instructs a format to enable application client ownership of the
145              "logical block reference tag" field (i.e. the RTO_REQ bit in the
146              FORMAT cdb). The default action is to disable application client
147              ownership of that field. Has no action unless both --format  and
148              --pinfo are given.
149
150       -6, --six
151              Use  6  byte variants of MODE SENSE and MODE SELECT. The default
152              action is to use the 10 byte variants. Some MO drives need  this
153              option set when doing a format.
154
155       -s, --size=SIZE
156              where  SIZE  is  the  block  size  (i.e. number of bytes in each
157              block) to format the device to.  The default value  is  whatever
158              is  currently  reported  by the block descriptor in a MODE SENSE
159              command. This option is only active when the --format option  is
160              also  given. If the block size given by this option is different
161              from the current value then a MODE SELECT  command  is  used  to
162              change  it  prior to the FORMAT command being started (as recom‐
163              mended in the draft standard). Recent SCSI  disks  usually  have
164              512  byte sectors by default and allow up to 16 bytes extra in a
165              sector (i.e. 528 byte sectors).  If the given size in  unaccept‐
166              able  to  the  disk,  most likely an "Invalid field in parameter
167              list" message will appear in sense data  (requires  the  use  of
168              '-v' to decode sense data).
169
170       -v, --verbose
171              increase  the  level  of  verbosity, (i.e. debug output). "-vvv"
172              gives the maximum debug output.
173
174       -V, --version
175              print the version string and then exit.
176
177       -w, --wait
178              this option only has an  effect  when  used  together  with  the
179              --format option. The default format action is to set the "IMMED"
180              bit in the FORMAT UNIT command's (short)  parameter  header.  If
181              this  option  (i.e. --wait) is given then the "IMMED" bit is not
182              set. Then the FORMAT UNIT command waits until the format  opera‐
183              tion  completes  before returning its response. This can be sev‐
184              eral hours on large disks. This utility sets a four hour timeout
185              on such a FORMAT UNIT command.
186

LISTS

188       The  SBC-3  draft (revision 6) defines PLIST, CLIST, DLIST and GLIST in
189       section 4.8 on "Medium defects". Briefly, the PLIST  is  the  "primary"
190       list of manufacturer detected defects, the CLIST ("certification" list)
191       are those detected during the format operation, the DLIST is a list  of
192       defects  that  can  be  given to the format operation. The GLIST is the
193       grown list which starts in the format process as  CLIST+DLIST  and  can
194       "grow"  later due to automatic reallocation (see the ARRE and AWRE bits
195       in the read-write error recovery mode page (see sdparm)) and use of the
196       SCSI REASSIGN BLOCKS command (see sg_reassign).
197
198       The  CMPLST  bit  (controlled  by  the  --cmplst=0|1 option) determines
199       whether the existing GLIST, when the format operation  is  invoked,  is
200       taken  into  account.  The  sg_format  utility sets the FOV bit to zero
201       which causes the DPRY=0, so  the  PLIST  is  taken  into  account,  and
202       DCRT=0, so the CLIST is generated and used during the format process.
203
204       The  sg_format  utility does not permit a user to provide a defect list
205       (i.e. DLIST). All protection information options are defaulted to off.
206

NOTES

208       The SBC-2 draft standard (revision 16) says that the REQUEST SENSE com‐
209       mand should be used for obtaining a progress indication when the format
210       command returns prior to the completion of the format operation.   How‐
211       ever,  tests  on a selection of recent disks shows that TEST UNIT READY
212       commands yield progress indications (but not REQUEST SENSE commands). A
213       new  option  may  be required to handle this when disks catch up to the
214       current draft.
215
216       When the --format option is given then there is a 10 second window dur‐
217       ing  which  the  user is invited to abort sg_format. This is just prior
218       the SCSI FORMAT UNIT command being issued. If the --wait option is  not
219       given  then  the  SCSI FORMAT UNIT command is issued with the IMMED bit
220       set which causes the SCSI command to return after it  has  started  the
221       format  operation.  The  --early option will cause sg_format to exit at
222       that point. Otherwise the DEVICE is polled every 30 seconds  with  TEST
223       UNIT  READY  commands  until it reports an "all clear" (i.e. the format
224       operation has completed). Normally these polling commands  will  result
225       in a progress indicator (expressed as a percentage) being output to the
226       screen. If the user  gets  bored  watching  the  progress  report  then
227       sg_format  process  can  be  terminated  (e.g.  with control-C) without
228       affecting the format operation which continues. However a bus or device
229       reset  (or  a  power cycle) may well cause the device to become "format
230       corrupt".
231
232       When the --format and --wait options are both given then  this  utility
233       may  take  a long time to return. In this case care should be taken not
234       to send any other SCSI commands to the disk as it may not respon  leav‐
235       ing  those  commands  queued behind the active format command. This may
236       cause a timeout in the OS driver (in a lot shorter period than 4  hours
237       applicable  to the format command). This may result in the OS resetting
238       the disk leaving the format operation incomplete. This  may  leave  the
239       disk in a "format corrupt" state requiring another format to remedy the
240       situation.
241
242       When the block size (i.e. the number of bytes in each block) is changed
243       on  a  disk two SCSI commands must be sent: a MODE SELECT to change the
244       block size followed by a FORMAT command. If  the  MODE  SELECT  command
245       succeeds  and the FORMAT fails then the disk may be in a state that the
246       draft standard calls "format corrupt". A block descriptor in  a  subse‐
247       quent  MODE SENSE will report the requested new block size while a READ
248       CAPACITY command will report the existing (i.e. different) block  size.
249       Alternatively  the READ CAPACITY command may fail, reporting the device
250       is not ready, potentially requiring a format. The solution to this sit‐
251       uation  is  to do a format again (and this time the new block size does
252       not have to be given) or change the block size  back  to  the  original
253       size.
254
255       The draft SBC-2 standard states that the block count can be set back to
256       the manufacturer's maximum recommended value  in  a  format  or  resize
257       operation. This can be done by placing an address of 0xffffffff (or the
258       64 bit equivalent) in the appropriate block descriptor field to a  MODE
259       SELECT command. In signed (two's complement) arithmetic that value cor‐
260       responds to '-1'. So a --count=-1 causes the block count to be set back
261       to  the  manufacturer's maximum recommended value. To see exactly which
262       SCSI commands are being executed and parameters passed  add  "-vvv"  to
263       the sg_format command line.
264
265       Short  stroking  is  a technique to trade off capacity for performance.
266       Disk performance is usually highest on the  outer  tracks  (i.e.  lower
267       logical  block  addresses)  so  by resizing or reformatting a disk to a
268       smaller capacity, average performance will usually be increased.
269
270       Other utilities may be useful in finding  information  associated  with
271       formatting.  These include sg_inq to fetch standard INQUIRY information
272       (e.g. the PROTECT bit) and to fetch the extended INQUIRY VPD page (e.g.
273       RTO  and  GRD_CHK  bits). The sdparm (or sginfo) utility can be used to
274       access and potentially change the now obsolete format mode page.
275
276       scsiformat is another utility available for formatting SCSI disks  with
277       linux.  It  dates  from 1997 (most recent update) and may be useful for
278       disks whose firmware is of that vintage.
279
280       The COUNT value is a number which may be followed by one of these  mul‐
281       tiplicative  suffixes:  c  C  *1;  w W *2; b B *512; k K KiB *1,024; KB
282       *1,000; m M MiB *1,048,576; MB *1,000,000 . This pattern continues  for
283       "G", "T" and "P". Also a suffix of the form "x<n>" multiplies the lead‐
284       ing number by <n>. Alternatively numerical values can be given in hexa‐
285       decimal  preceded  by  either  "0x"  or "0X" (or with a trailing "h" or
286       "H"). When hex numbers are given, multipliers cannot be used.
287

EXAMPLES

289       First, do not alter anything but print out the existing block count and
290       size derived from two sources: a block descriptor in a MODE SELECT com‐
291       mand response and from the response of a READ CAPACITY commands:
292
293          sg_format /dev/sdm
294
295       Now a simple format, leaving the block count and size as they were pre‐
296       viously. The FORMAT command is executed in IMMED mode and the device is
297       polled every 30 seconds to print out a progress indication:
298
299          sg_format --format /dev/sdm
300
301       Now the same format, but waiting (passively) until the format operation
302       is complete:
303
304          sg_format --format --wait /dev/sdm
305
306       Next  is  a  format in which the block size is changed to 520 bytes and
307       the block count is set to the manufacturer's maximum  value  (for  that
308       block size). Note, not all disks support changing the block size:
309
310          sg_format --format --size=520 /dev/sdm
311
312       Now a resize operation so that only the first 0x10000 (65536) blocks on
313       a disk are accessible. The remaining blocks remain unaltered.
314
315          sg_format --resize --count=0x10000 /dev/sdm
316
317       Now resize the disk back to its normal (maximum) block count:
318
319          sg_format --resize --count=-1 /dev/sdm
320

EXIT STATUS

322       The exit status of sg_format is 0 when it is successful. Otherwise  see
323       the  sg3_utils(8) man page. Unless the --wait option is given, the exit
324       status may not reflect to success of otherwise of  the  format.   Using
325       sg_turs and sg_readcap after the format operation may be wise.
326

AUTHORS

328       Written by Grant Grundler, James Bottomley and Douglas Gilbert.
329

REPORTING BUGS

331       Report bugs to <dgilbert at interlog dot com>.
332
334       Copyright  ©  2005-2007  Grant  Grundler,  James  Bottomley and Douglas
335       Gilbert
336       This software is distributed under the GPL version 2. There is NO  war‐
337       ranty;  not  even  for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR‐
338       POSE.
339

SEE ALSO

341       sg_turs, sg_requests, sg_inq, sg_modes,  sginfo,  sg_reassign  (all  in
342       sg3_utils), sdparm, scsiformat, setblocksize
343
344
345
346sg3_utils-1.23                   January 2007                     SG_FORMAT(8)
Impressum