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

OPTIONS

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

THEORY

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

INPUT FORMAT

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

EXAMPLE

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

DOS 6.x WARNING

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

DRDOS WARNINGS

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

BUGS

427       A corresponding interactive cfdisk (with  curses  interface)  is  still
428       lacking.
429
430       There are too many options.
431
432       There is no support for non-DOS partition types.
433
434

SEE ALSO

436       cfdisk(8), fdisk(8), mkfs(8), parted(8)
437
438
439
440Linux                          1 September 1995                      SFDISK(8)
Impressum