1SFDISK(8)                    System Administration                   SFDISK(8)
2
3
4

NAME

6       sfdisk - partition table manipulator for Linux
7

SYNOPSIS

9       sfdisk [options] device
10       sfdisk -s [partition]
11

DESCRIPTION

13       sfdisk  has  four  (main)  uses: list the size of a partition, list the
14       partitions on a device, check the partitions on a device,  and  -  very
15       dangerous - repartition a device.
16
17       sfdisk  doesn't understand the GUID Partition Table (GPT) format and it
18       is not designed for large partitions.  In  these  cases  use  the  more
19       advanced GNU parted(8).
20
21       Note  that sfdisk does not align partitions to block device I/O limits.
22       This functionality is provided by fdisk(8).
23
24
25   List sizes
26       sfdisk -s partition gives the size of partition in blocks.  This may be
27       useful  in  connection with programs like mkswap(8).  Here partition is
28       usually something like /dev/hda1 or /dev/sdb12,  but  may  also  be  an
29       entire disk, like /dev/xda.
30
31              % sfdisk -s /dev/hda9
32              81599
33
34       If the partition argument is omitted, sfdisk will list the sizes of all
35       block devices, and the total:
36
37              % sfdisk -s
38              /dev/hda: 208896
39              /dev/hdb: 1025136
40              /dev/hdc: 1031063
41              /dev/sda: 8877895
42              /dev/sdb: 1758927
43              total: 12901917 blocks
44
45
46   List partitions
47       The second type of invocation: sfdisk -l device will  list  the  parti‐
48       tions  on the specified device.  If the device argument is omitted, the
49       partitions on all block devices are listed.
50
51              % sfdisk -l /dev/hdc
52
53              Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
54              Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
55
56                 Device Boot Start     End   #cyls   #blocks   Id  System
57              /dev/hdc1          0+    406     407-   205096+  83  Linux native
58              /dev/hdc2        407     813     407    205128   83  Linux native
59              /dev/hdc3        814    2044    1231    620424   83  Linux native
60              /dev/hdc4          0       -       0         0    0  Empty
61
62       The trailing - and + signs indicate that rounding has taken place,  and
63       that  the actual value is slightly less or more.  To see the exact val‐
64       ues, ask for a listing with sectors as unit (-u S).
65
66
67   Check partitions
68       The third type of invocation: sfdisk -V device will apply various  con‐
69       sistency  checks  to the partition tables on device.  It prints `OK' or
70       complains.  The -V option can be used together with  -l.   In  a  shell
71       script one might use sfdisk -V -q device which only returns a status.
72
73
74   Create partitions
75       The  fourth type of invocation: sfdisk device will cause sfdisk to read
76       the specification for the desired partitioning of device from  standard
77       input,  and  then  to change the partition tables on that block device.
78       Thus it is possible to use sfdisk from a  shell  script.   When  sfdisk
79       determines  that its standard input is a terminal, it will be conversa‐
80       tional; otherwise it will abort on any error.
81
82       BE EXTREMELY CAREFUL - ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST
83
84       As a precaution, one can save the sectors changed by sfdisk:
85
86              % sfdisk /dev/hdd -O hdd-partition-sectors.save
87              ...
88
89
90       Then, if you discover that you did  something  stupid  before  anything
91       else  has  been  written  to  the  block  device, it may be possible to
92       recover the old situation with:
93
94              % sfdisk /dev/hdd -I hdd-partition-sectors.save
95
96
97       (This is not the same as saving the old  partition  table:  a  readable
98       version  of  the  old partition table can be saved using the -d option.
99       However, if you create logical partitions, the sectors describing  them
100       are  located  somewhere  on block device, possibly on sectors that were
101       not part of the partition table before.  Thus, the information  the  -O
102       option saves is not a binary version of the output of -d.)
103
104       There are many options.
105
106

OPTIONS

108       -v, --version
109              Print version number of sfdisk and exit immediately.
110
111       -h, --help
112              Print a usage message and exit immediately.
113
114       -T, --list-types
115              Print the recognized types (system Id's).
116
117       -s, --show-size
118              List the size of a partition.
119
120       -g, --show-geometry
121              List  the  kernel's  idea of the geometry of the indicated block
122              device(s).
123
124       -G, --show-pt-geometry
125              List the geometry of the  indicated  block  devices  guessed  by
126              looking at the partition table.
127
128       -l, --list
129              List the partitions of a device.
130
131       -d, --dump
132              Dump  the  partitions  of a device in a format that is usable as
133              input to sfdisk.  For example,
134                  % sfdisk -d /dev/hda > hda.out
135                  % sfdisk /dev/hda < hda.out
136              will correct the bad last extended partition that the OS/2 fdisk
137              creates.
138
139       -V, --verify
140              Test whether partitions seem correct.  (See the third invocation
141              type above.)
142
143       -i, --increment
144              Number cylinders etc. starting from 1 instead of 0.
145
146       -N number
147              Change only the single partition indicated.  For example:
148                  % sfdisk /dev/hdb -N5
149                  ,,,*
150              will make the fifth partition on  /dev/hdb  bootable  (`active')
151              and  change  nothing  else.  (Probably  this  fifth partition is
152              called /dev/hdb5, but you are free to call  it  something  else,
153              like `/my_equipment/disks/2/5' or so).
154
155       -A, --activate number
156              Make the indicated partition(s) active, and all others inactive.
157
158       -c, --id number [Id]
159              If no Id argument given: print the partition Id of the indicated
160              partition.  If an Id argument is present: change the  type  (Id)
161              of  the indicated partition to the given value.  This option has
162              two longer forms, --print-id and --change-id.  For example:
163                  % sfdisk --print-id /dev/hdb 5
164                  6
165                  % sfdisk --change-id /dev/hdb 5 83
166                  OK
167              first reports that /dev/hdb5 has Id 6,  and  then  changes  that
168              into 83.
169
170       -u, --unit letter
171              Interpret  the  input and show the output in the units specified
172              by letter.  This letter can be one of S, C, B or M, meaning Sec‐
173              tors,   Cylinders,  Blocks  and  Megabytes,  respectively.   The
174              default is cylinders, at least when the geometry is known.
175
176       -x, --show-extended
177              Also list non-primary extended partitions on output, and  expect
178              descriptors for them on input.
179
180       -C, --cylinders cylinders
181              Specify  the  number  of cylinders, possibly overriding what the
182              kernel thinks.
183
184       -H, --heads heads
185              Specify the number of heads, possibly overriding what the kernel
186              thinks.
187
188       -S, --sectors sectors
189              Specify the number of sectors, possibly overriding what the ker‐
190              nel thinks.
191
192       -f, --force
193              Do what I say, even if it is stupid.
194
195       -q, --quiet
196              Suppress warning messages.
197
198       -L, --Linux
199              Do not complain about things irrelevant for Linux.
200
201       -D, --DOS
202              For DOS-compatibility: waste a little space.   (More  precisely:
203              if a partition cannot contain sector 0, e.g. because that is the
204              MBR of the  device,  or  contains  the  partition  table  of  an
205              extended  partition,  then  sfdisk  would make it start the next
206              sector.  However, when this option is  given  it  skips  to  the
207              start of the next track, wasting for example 33 sectors (in case
208              of 34 sectors/track), just like certain  versions  of  DOS  do.)
209              Certain  Disk  Managers  and boot loaders (such as OSBS, but not
210              LILO or the OS/2 Boot Manager) also live in this empty space, so
211              maybe you want this option if you use one.
212
213       -E, --DOS-extended
214              Take  the starting sector numbers of "inner" extended partitions
215              to be relative to the starting cylinder boundary  of  the  outer
216              one  (like some versions of DOS do), rather than relative to the
217              actual starting sector (like Linux does).  (The fact that  there
218              is  a  difference here means that one should always let extended
219              partitions start at cylinder boundaries if DOS and Linux  should
220              interpret  the  partition  table in the same way.  Of course one
221              can only know where cylinder boundaries are when one knows  what
222              geometry DOS will use for this block device.)
223
224       --IBM, --leave-last
225              Certain  IBM  diagnostic  programs  assume that they can use the
226              last cylinder on a device for  disk-testing  purposes.   If  you
227              think  you might ever run such programs, use this option to tell
228              sfdisk that it should not allocate the last cylinder.  Sometimes
229              the last cylinder contains a bad sector table.
230
231       -n     Go  through  all the motions, but do not actually write to block
232              device.
233
234       -R, --re-read
235              Only execute the BLKRRPART ioctl (to make the kernel re-read the
236              partition  table).   This  can be useful for checking in advance
237              that the final BLKRRPART will be successful, and also  when  you
238              changed  the  partition  table  `by hand' (e.g., using dd from a
239              backup).  If the kernel complains (`device busy for revalidation
240              (usage  =  2)')  then  something  still uses the device, and you
241              still have to unmount some file system, or say swapoff  to  some
242              swap partition.
243
244       --no-reread
245              When  starting a repartitioning of a block device, sfdisk checks
246              that this device is not mounted, or in use as a swap device, and
247              refuses  to continue if it is.  This option suppresses the test.
248              (On the other hand, the -f option would force sfdisk to continue
249              even when this test fails.)
250
251       --in-order
252              Caution, see warning section.  To be documented.
253
254       --not-in-order
255              Caution, see warning section.  To be documented.
256
257       --inside-outer
258              Caution, see warning section.  Chaining order.
259
260       --not-inside-outer
261              Caution, see warning section.  Chaining order.
262
263       --nested
264              Caution,  see  warning section.  Every partition is contained in
265              the surrounding partitions and is disjoint from all others.
266
267       --chained
268              Caution, see warning section.  Every data partition is contained
269              in  the surrounding partitions and disjoint from all others, but
270              extended partitions may  lie  outside  (insofar  as  allowed  by
271              all_logicals_inside_outermost_extended).
272
273       --onesector
274              Caution,  see warning section.  All data partitions are mutually
275              disjoint; extended partitions each use one sector  only  (except
276              perhaps for the outermost one).
277
278       -O file
279              Just  before  writing the new partition, output the sectors that
280              are going to  be  overwritten  to  file  (where  hopefully  file
281              resides on another block device, or on a floppy).
282
283       -I file
284              After  destroying  your  filesystems  with an unfortunate sfdisk
285              command, you would have been able to restore the  old  situation
286              if only you had preserved it using the -O flag.
287
288

THEORY

290       Block 0 of a block device (the Master Boot Record) contains among other
291       things four partition descriptors. The partitions  described  here  are
292       called primary partitions.
293
294       A partition descriptor has 6 fields:
295              struct partition {
296                  unsigned char bootable;        /* 0 or 0x80 */
297                  hsc begin_hsc;
298                  unsigned char id;
299                  hsc end_hsc;
300                  unsigned int starting_sector;
301                  unsigned int nr_of_sectors;
302              }
303
304       The  two hsc fields indicate head, sector and cylinder of the begin and
305       the end of the partition. Since each hsc field only takes 3 bytes, only
306       24  bits  are  available,  which does not suffice for big block devices
307       (say > 8GB). In fact, due to the wasteful representation (that  uses  a
308       byte  for the number of heads, which is typically 16), problems already
309       start with 0.5GB.  However Linux does not use these fields,  and  prob‐
310       lems  can  arise  only at boot time, before Linux has been started. For
311       more details, see the lilo documentation.
312
313       Each partition has a type, its `Id',  and  if  this  type  is  5  or  f
314       (`extended  partition') the starting sector of the partition again con‐
315       tains 4 partition descriptors. MSDOS only uses the first two of  these:
316       the  first  one  an  actual data partition, and the second one again an
317       extended partition (or empty).   In  this  way  one  gets  a  chain  of
318       extended  partitions.   Other operating systems have slightly different
319       conventions.  Linux also accepts type 85 as equivalent to  5  and  f  -
320       this can be useful if one wants to have extended partitions under Linux
321       past the 1024 cylinder boundary, without DOS FDISK hanging.  (If  there
322       is  no good reason, you should just use 5, which is understood by other
323       systems.)
324
325       Partitions that are not primary or extended are called logical.  Often,
326       one cannot boot from logical partitions (because the process of finding
327       them is more involved than just looking at the MBR).  Note that  of  an
328       extended  partition only the Id and the start are used. There are vari‐
329       ous conventions about what to write in the other fields. One should not
330       try to use extended partitions for data storage or swap.
331
332

INPUT FORMAT

334       sfdisk reads lines of the form
335              <start> <size> <id> <bootable> <c,h,s> <c,h,s>
336       where each line fills one partition descriptor.
337
338       Fields are separated by whitespace, or comma or semicolon possibly fol‐
339       lowed by whitespace; initial and trailing whitespace is ignored.   Num‐
340       bers  can be octal, decimal or hexadecimal, decimal is default.  When a
341       field is absent or empty, a default value is used.
342
343       The <c,h,s> parts can (and probably should) be omitted  -  sfdisk  com‐
344       putes  them  from  <start>  and <size> and the block device geometry as
345       given by the kernel or specified using the -H, -S, -C flags.
346
347       Bootable is specified as [*|-], with  as  default  not-bootable.   (The
348       value  of  this  field is irrelevant for Linux - when Linux runs it has
349       been booted already - but might play a role for  certain  boot  loaders
350       and  for  other operating systems.  For example, when there are several
351       primary DOS partitions, DOS assigns C: to the first among these that is
352       bootable.)
353
354       Id  is  given  in  hex, without the 0x prefix, or is [E|S|L|X], where L
355       (LINUX_NATIVE (83))  is  the  default,  S  is  LINUX_SWAP  (82),  E  is
356       EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85).
357
358       The default value of start is the first nonassigned sector/cylinder/...
359
360       The  default value of size is as much as possible (until next partition
361       or end-of-device).
362
363       However, for the four partitions  inside  an  extended  partition,  the
364       defaults are: Linux partition, Extended partition, Empty, Empty.
365
366       But  when  the -N option (change a single partition only) is given, the
367       default for each field is its previous value.
368
369       A '+' can be specified instead of a number for  size,  which  means  as
370       much as possible. This is useful with the -N option.
371

EXAMPLE

373       The command
374              sfdisk /dev/hdc << EOF
375              0,407
376              ,407
377              ;
378              ;
379              EOF
380       will partition /dev/hdc just as indicated above.
381
382       The command
383              sfdisk /dev/hdb << EOF
384              ,3,L
385              ,60,L
386              ,19,S
387              ,,E
388              ,130,L
389              ,130,L
390              ,130,L
391              ,,L
392              EOF
393       will  partition  /dev/hdb  into two Linux partitions of 3 and 60 cylin‐
394       ders, a swap space of 19 cylinders, and an extended partition  covering
395       the  rest.  Inside  the extended partition there are four Linux logical
396       partitions, three of 130 cylinders and one covering the rest.
397
398       With the -x option, the number of input lines must be a multiple of  4:
399       you have to list the two empty partitions that you never want using two
400       blank lines. Without the -x option, you give one line  for  the  parti‐
401       tions  inside a extended partition, instead of four, and terminate with
402       end-of-file (^D).  (And sfdisk will assume that your input line  repre‐
403       sents  the  first of four, that the second one is extended, and the 3rd
404       and 4th are empty.)
405

CAUTION WARNINGS

407       The options marked with caution in the manual page are dangerous.   For
408       example not all functionality is completely implemented, which can be a
409       reason for unexpected results.
410

DOS 6.x WARNING

412       The DOS 6.x FORMAT command looks for some information in the first sec‐
413       tor  of  the data area of the partition, and treats this information as
414       more reliable than the information in the partition table.  DOS  FORMAT
415       expects  DOS  FDISK  to clear the first 512 bytes of the data area of a
416       partition whenever a size change occurs.  DOS FORMAT will look at  this
417       extra  information  even  if the /U flag is given -- we consider this a
418       bug in DOS FORMAT and DOS FDISK.
419
420       The bottom line is that if you use sfdisk to change the size of  a  DOS
421       partition  table entry, then you must also use dd to zero the first 512
422       bytes of that partition before using DOS FORMAT to  format  the  parti‐
423       tion.   For  example,  if you were using sfdisk to make a DOS partition
424       table entry for /dev/hda1, then (after  exiting  sfdisk  and  rebooting
425       Linux  so  that the partition table information is valid) you would use
426       the command "dd if=/dev/zero of=/dev/hda1 bs=512 count=1" to  zero  the
427       first  512 bytes of the partition.  BE EXTREMELY CAREFUL if you use the
428       dd command, since a small typo can make all of the data on  your  block
429       device useless.
430
431       For  best results, you should always use an OS-specific partition table
432       program.  For example, you should make  DOS  partitions  with  the  DOS
433       FDISK program and Linux partitions with the Linux sfdisk program.
434
435

DRDOS WARNINGS

437       Stephen  Tweedie reported (930515): `Most reports of superblock corrup‐
438       tion turn out to be due to bad partitioning, with one filesystem  over‐
439       running  the  start  of the next and corrupting its superblock.  I have
440       even had this problem with the  supposedly-reliable  DRDOS.   This  was
441       quite  possibly  due  to DRDOS-6.0's FDISK command.  Unless I created a
442       blank track or cylinder between the DRDOS partition and the immediately
443       following one, DRDOS would happily stamp all over the start of the next
444       partition.  Mind you, as long as I keep  a  little  free  device  space
445       after any DRDOS partition, I don't have any other problems with the two
446       coexisting on the one drive.'
447
448       A. V. Le Blanc writes in README.efdisk: `Dr. DOS 5.0 and 6.0  has  been
449       reported to have problems cooperating with Linux, and with this version
450       of efdisk in particular.  This efdisk sets the system type to hexadeci‐
451       mal  81.  Dr. DOS seems to confuse this with hexadecimal 1, a DOS code.
452       If you use Dr. DOS, use the efdisk command 't'  to  change  the  system
453       code of any Linux partitions to some number less than hexadecimal 80; I
454       suggest 41 and 42 for the moment.'
455
456       A. V. Le Blanc writes in his README.fdisk:  `DR-DOS  5.0  and  6.0  are
457       reported  to  have  difficulties with partition ID codes of 80 or more.
458       The Linux `fdisk' used to set the system  type  of  new  partitions  to
459       hexadecimal 81.  DR-DOS seems to confuse this with hexadecimal 1, a DOS
460       code.  The values 82 for swap and 83 for file systems should not  cause
461       problems  with DR-DOS.  If they do, you may use the `fdisk' command `t'
462       to change the system code of any Linux partitions to some  number  less
463       than hexadecimal 80; I suggest 42 and 43 for the moment.'
464
465       In fact, it seems that only 4 bits are significant for the DRDOS FDISK,
466       so that for example 11 and 21 are listed as  DOS  2.0.  However,  DRDOS
467       itself  seems  to  use the full byte. I have not been able to reproduce
468       any corruption with DRDOS or its fdisk.
469
470

BUGS

472       There are too many options.
473
474       There is no support for non-DOS partition types.
475
476

SEE ALSO

478       cfdisk(8), fdisk(8), mkfs(8), parted(8), partprobe(8), kpartx(8)
479

AVAILABILITY

481       The sfdisk command is part of the util-linux package and  is  available
482       from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
483
484
485
486util-linux                        August 2011                        SFDISK(8)
Impressum