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

OPTIONS

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

THEORY

256       Block 0 of a block device (the Master Boot Record) contains among other
257       things four partition descriptors. The partitions  described  here  are
258       called primary partitions.
259
260       A partition descriptor has 6 fields:
261              struct partition {
262                  unsigned char bootable;        /* 0 or 0x80 */
263                  hsc begin_hsc;
264                  unsigned char id;
265                  hsc end_hsc;
266                  unsigned int starting_sector;
267                  unsigned int nr_of_sectors;
268              }
269
270       The  two hsc fields indicate head, sector and cylinder of the begin and
271       the end of the partition. Since each hsc field only takes 3 bytes, only
272       24  bits  are  available,  which does not suffice for big block devices
273       (say > 8GB). In fact, due to the wasteful representation (that  uses  a
274       byte  for the number of heads, which is typically 16), problems already
275       start with 0.5GB.  However Linux does not use these fields,  and  prob‐
276       lems  can  arise  only at boot time, before Linux has been started. For
277       more details, see the lilo documentation.
278
279       Each partition has a type, its `Id',  and  if  this  type  is  5  or  f
280       (`extended  partition') the starting sector of the partition again con‐
281       tains 4 partition descriptors. MSDOS only uses the first two of  these:
282       the  first  one  an  actual data partition, and the second one again an
283       extended partition (or empty).   In  this  way  one  gets  a  chain  of
284       extended  partitions.   Other operating systems have slightly different
285       conventions.  Linux also accepts type 85 as equivalent to  5  and  f  -
286       this can be useful if one wants to have extended partitions under Linux
287       past the 1024 cylinder boundary, without DOS FDISK hanging.  (If  there
288       is  no good reason, you should just use 5, which is understood by other
289       systems.)
290
291       Partitions that are not primary or extended are called logical.  Often,
292       one cannot boot from logical partitions (because the process of finding
293       them is more involved than just looking at the MBR).  Note that  of  an
294       extended  partition only the Id and the start are used. There are vari‐
295       ous conventions about what to write in the other fields. One should not
296       try to use extended partitions for data storage or swap.
297
298

INPUT FORMAT

300       sfdisk reads lines of the form
301              <start> <size> <id> <bootable> <c,h,s> <c,h,s>
302       where each line fills one partition descriptor.
303
304       Fields are separated by whitespace, or comma or semicolon possibly fol‐
305       lowed by whitespace; initial and trailing whitespace is ignored.   Num‐
306       bers  can be octal, decimal or hexadecimal, decimal is default.  When a
307       field is absent or empty, a default value is used.
308
309       The <c,h,s> parts can (and probably should) be omitted  -  sfdisk  com‐
310       putes  them  from  <start>  and <size> and the block device geometry as
311       given by the kernel or specified using the -H, -S, -C flags.
312
313       Bootable is specified as [*|-], with  as  default  not-bootable.   (The
314       value  of  this  field is irrelevant for Linux - when Linux runs it has
315       been booted already - but might play a role for  certain  boot  loaders
316       and  for  other operating systems.  For example, when there are several
317       primary DOS partitions, DOS assigns C: to the first among these that is
318       bootable.)
319
320       Id  is  given  in  hex, without the 0x prefix, or is [E|S|L|X], where L
321       (LINUX_NATIVE (83))  is  the  default,  S  is  LINUX_SWAP  (82),  E  is
322       EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85).
323
324       The default value of start is the first nonassigned sector/cylinder/...
325
326       The  default value of size is as much as possible (until next partition
327       or end-of-device).
328
329       However, for the four partitions  inside  an  extended  partition,  the
330       defaults are: Linux partition, Extended partition, Empty, Empty.
331
332       But  when  the -N option (change a single partition only) is given, the
333       default for each field is its previous value.
334
335

EXAMPLE

337       The command
338              sfdisk /dev/hdc << EOF
339              0,407
340              ,407
341              ;
342              ;
343              EOF
344       will partition /dev/hdc just as indicated above.
345
346       The command
347              sfdisk /dev/hdb << EOF
348              ,3,L
349              ,60,L
350              ,19,S
351              ,,E
352              ,130,L
353              ,130,L
354              ,130,L
355              ,,L
356              EOF
357       will partition /dev/hdb into two Linux partitions of 3  and  60  cylin‐
358       ders,  a swap space of 19 cylinders, and an extended partition covering
359       the rest. Inside the extended partition there are  four  Linux  logical
360       partitions, three of 130 cylinders and one covering the rest.
361
362       With  the -x option, the number of input lines must be a multiple of 4:
363       you have to list the two empty partitions that you never want using two
364       blank  lines.  Without  the -x option, you give one line for the parti‐
365       tions inside a extended partition, instead of four, and terminate  with
366       end-of-file  (^D).  (And sfdisk will assume that your input line repre‐
367       sents the first of four, that the second one is extended, and  the  3rd
368       and 4th are empty.)
369
370

DOS 6.x WARNING

372       The DOS 6.x FORMAT command looks for some information in the first sec‐
373       tor of the data area of the partition, and treats this  information  as
374       more  reliable than the information in the partition table.  DOS FORMAT
375       expects DOS FDISK to clear the first 512 bytes of the data  area  of  a
376       partition  whenever a size change occurs.  DOS FORMAT will look at this
377       extra information even if the /U flag is given -- we  consider  this  a
378       bug in DOS FORMAT and DOS FDISK.
379
380       The  bottom  line is that if you use sfdisk to change the size of a DOS
381       partition table entry, then you must also use dd to zero the first  512
382       bytes  of  that  partition before using DOS FORMAT to format the parti‐
383       tion.  For example, if you were using sfdisk to make  a  DOS  partition
384       table  entry  for  /dev/hda1,  then (after exiting sfdisk and rebooting
385       Linux so that the partition table information is valid) you  would  use
386       the  command  "dd if=/dev/zero of=/dev/hda1 bs=512 count=1" to zero the
387       first 512 bytes of the partition.  BE EXTREMELY CAREFUL if you use  the
388       dd  command,  since a small typo can make all of the data on your block
389       device useless.
390
391       For best results, you should always use an OS-specific partition  table
392       program.   For  example,  you  should  make DOS partitions with the DOS
393       FDISK program and Linux partitions with the Linux sfdisk program.
394
395

DRDOS WARNINGS

397       Stephen Tweedie reported (930515): `Most reports of superblock  corrup‐
398       tion  turn out to be due to bad partitioning, with one filesystem over‐
399       running the start of the next and corrupting its  superblock.   I  have
400       even  had  this  problem  with the supposedly-reliable DRDOS.  This was
401       quite possibly due to DRDOS-6.0's FDISK command.  Unless  I  created  a
402       blank track or cylinder between the DRDOS partition and the immediately
403       following one, DRDOS would happily stamp all over the start of the next
404       partition.   Mind  you,  as  long  as I keep a little free device space
405       after any DRDOS partition, I don't have any other problems with the two
406       coexisting on the one drive.'
407
408       A.  V.  Le Blanc writes in README.efdisk: `Dr. DOS 5.0 and 6.0 has been
409       reported to have problems cooperating with Linux, and with this version
410       of efdisk in particular.  This efdisk sets the system type to hexadeci‐
411       mal 81.  Dr. DOS seems to confuse this with hexadecimal 1, a DOS  code.
412       If  you  use  Dr.  DOS, use the efdisk command 't' to change the system
413       code of any Linux partitions to some number less than hexadecimal 80; I
414       suggest 41 and 42 for the moment.'
415
416       A.  V.  Le  Blanc  writes  in his README.fdisk: `DR-DOS 5.0 and 6.0 are
417       reported to have difficulties with partition ID codes of  80  or  more.
418       The  Linux  `fdisk'  used  to  set the system type of new partitions to
419       hexadecimal 81.  DR-DOS seems to confuse this with hexadecimal 1, a DOS
420       code.   The values 82 for swap and 83 for file systems should not cause
421       problems with DR-DOS.  If they do, you may use the `fdisk' command  `t'
422       to  change  the system code of any Linux partitions to some number less
423       than hexadecimal 80; I suggest 42 and 43 for the moment.'
424
425       In fact, it seems that only 4 bits are significant for the DRDOS FDISK,
426       so  that  for  example  11 and 21 are listed as DOS 2.0. However, DRDOS
427       itself seems to use the full byte. I have not been  able  to  reproduce
428       any corruption with DRDOS or its fdisk.
429
430

BUGS

432       There are too many options.
433
434       There is no support for non-DOS partition types.
435
436

SEE ALSO

438       cfdisk(8), fdisk(8), mkfs(8), parted(8), partprobe(8), kpartx(8)
439

AVAILABILITY

441       The  sfdisk  command is part of the util-linux-ng package and is avail‐
442       able from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
443
444
445
446Linux                          1 September 1995                      SFDISK(8)
Impressum