Penguin
Annotated edit history of sfdisk(8) version 2, including all changes. View license author blame.
Rev Author # Line
1 perry 1 SFDISK
2 !!!SFDISK
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 OPTIONS
7 THEORY
8 INPUT FORMAT
9 EXAMPLE
10 DOS 6.x WARNING
11 DRDOS WARNINGS
12 BUGS
13 AUTHOR
14 SEE ALSO
15 ----
16 !!NAME
17
18
19 sfdisk - Partition table manipulator for Linux
20 !!SYNOPSIS
21
22
23 __sfdisk__ [[options] device__
24 sfdisk -s__ [[partition]
25 !!DESCRIPTION
26
27
28 __sfdisk__ has four (main) uses: list the size of a
29 partition, list the partitions on a device, check the
30 partitions on a device, and - very dangerous - repartition a
31 device.
32
33
34 __List Sizes__
35
36
37 __sfdisk -s__ ''partition'' gives the size of
38 ''partition'' in blocks. This may be useful in connection
39 with programs like __mkswap__ or so. Here
40 ''partition'' is usually something like ''/dev/hda1''
41 or ''/dev/sdb12'', but may also be an entire disk, like
42 ''/dev/xda''.
43
44
2 YazzAtlas 45 % sfdisk -s /dev/hda9
46 81599
47 %
1 perry 48
49
50 If the partition argument is omitted, __sfdisk__ will
51 list the sizes of all disks, and the total:
52
53
2 YazzAtlas 54 % sfdisk -s
55 /dev/hda: 208896
56 /dev/hdb: 1025136
57 /dev/hdc: 1031063
58 /dev/sda: 8877895
59 /dev/sdb: 1758927
60 total: 12901917 blocks
61 %
1 perry 62
63
64 __List Partitions__
65
66
67 The second type of invocation: __sfdisk -l__ ''[[options]
68 device'' will list the partitions on this device. If the
69 device argument is omitted, the partitions on all hard disks
70 are listed.
71
72
2 YazzAtlas 73 % sfdisk -l /dev/hdc
74
75 Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
76 Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
77 Device Boot Start End #cyls #blocks Id System
78
79 /dev/hdc1 0+ 406 407- 205096+ 83 Linux native
80 /dev/hdc2 407 813 407 205128 83 Linux native
81 /dev/hdc3 814 2044 1231 620424 83 Linux native
82 /dev/hdc4 0 - 0 0 0 Empty
83 %
84
1 perry 85 The trailing - and + signs indicate that rounding has taken place, and that the actual value is slightly less (more). To see the exact values, ask for a listing with sectors as unit.
86
87
88 __Check partitions__
89
90
91 The third type of invocation: __sfdisk -V__ ''device''
92 will apply various consistency checks to the partition
93 tables on ''device''. It prints `OK' or complains. The -V
94 option can be used together with -l. In a shell script one
95 might use __sfdisk -V -q__ ''device'' which only
96 returns a status.
97
98
99 __Create partitions__
100
101
102 The fourth type of invocation: __sfdisk__ ''device''
103 will cause __sfdisk__ to read the specification for the
104 desired partitioning of ''device'' from its standard
105 input, and then to change the partition tables on that disk.
106 Thus, it is possible to use __sfdisk__ from a shell
107 script. When __sfdisk__ determines that its standard
108 input is a terminal, it will be conversational; otherwise it
109 will abort on any error.
110
111
112 BE EXTREMELY CAREFUL - ONE TYPING MISTAKE AND ALL YOUR DATA
113 IS LOST
114
115
116 As a precaution, one can save the sectors changed by
117 __sfdisk__:
118
119
2 YazzAtlas 120 % sfdisk /dev/hdd -O hdd-partition-sectors.save
121 ...
122 %
1 perry 123
124
125 Then, if you discover that you did something stupid before
126 anything else has been written to disk, it may be possible
127 to recover the old situation with
128
129
2 YazzAtlas 130 % sfdisk /dev/hdd -I hdd-partition-sectors.save
131 %
1 perry 132
133
134 (This is not the same as saving the old partition table: a
135 readable version of the old partition table can be saved
136 using the -d option. However, if you create logical
137 partitions, the sectors describing them are located
138 somewhere on disk, possibly on sectors that were not part of
139 the partition table before. Thus, the information the -O
140 option saves is not a binary version of the output of
141 -d.)
142
143
144 There are many options.
145 !!OPTIONS
146
147
148 __-v__ or __--version__
149
150
151 Print version number of __sfdisk__ and exit
152 immediately.
153
154
155 __-?__ or __--help__
156
157
158 Print a usage message and exit immediately.
159
160
161 __-T__ or __--list-types__
162
163
164 Print the recognized types (system Id's).
165
166
167 __-s__ or __--show-size__
168
169
170 List the size of a partition.
171
172
173 __-g__ or __--show-geometry__
174
175
176 List the kernel's idea of the geometry of the indicated
177 disk(s).
178
179
180 __-l__ or __--list__
181
182
183 List the partitions of a device.
184
185
186 __-d__
187
188
189 Dump the partitions of a device in a format useful as input
190 to sfdisk. For example,
191
192
193 % sfdisk -d /dev/hda
194 will correct the bad last extended partition that the OS/2 fdisk creates.
195
196
197 __-V__ or __--verify__
198
199
200 Test whether partitions seem correct. (See
201 above.)
202
203
204 __-i__ or __--increment__
205
206
207 Number cylinders etc. starting from 1 instead of
208 0.
209
210
211 __-N__ ''number''
212
213
214 Change only the single partition indicated. For
215 example:
216
217
2 YazzAtlas 218 % sfdisk /dev/hdb -N5
219 ,,,*
220 %
1 perry 221 will make the fifth partition on /dev/hdb bootable (`active') and change nothing else. (Probably this fifth partition is called /dev/hdb5, but you are free to call it something else, like `/my_equipment/disks/2/5' or so).
222
223
224 __-A__''number''
225
226
227 Make the indicated partition(s) active, and all others
228 inactive.
229
230
231 __-c__ ''or'' __--id__ ''number
232 [[Id]''
233
234
235 If no Id argument given: print the partition Id of the
236 indicated partition. If an Id argument is present: change
237 the type (Id) of the indicated partition to the given value.
238 This option has the two very long forms --print-id and
239 --change-id. For example:
240
241
2 YazzAtlas 242 % sfdisk --print-id /dev/hdb 5
243 6
244 % sfdisk --change-id /dev/hdb 5 83
245 OK
1 perry 246 first reports that /dev/hdb5 has Id 6, and then changes that into 83.
247
248
249 __-uS__ or __-uB__ or __-uC__ or
250 __-uM__
251
252
253 Accept or report in units of sectors (blocks, cylinders,
254 megabytes, respectively). The default is cylinders, at least
255 when the geometry is known.
256
257
258 __-x__ or __--show-extended__
259
260
261 Also list non-primary extended partitions on output, and
262 expect descriptors for them on input.
263
264
265 __-C__ ''cylinders''
266
267
268 Specify the number of cylinders, possibly overriding what
269 the kernel thinks.
270
271
272 __-H__ ''heads''
273
274
275 Specify the number of heads, possibly overriding what the
276 kernel thinks.
277
278
279 __-S__ ''sectors''
280
281
282 Specify the number of sectors, possibly overriding what the
283 kernel thinks.
284
285
286 __-f__ or __--force__
287
288
289 Do what I say, even if it is stupid.
290
291
292 __-q__ or __--quiet__
293
294
295 Suppress warning messages.
296
297
298 __-L__ or __--Linux__
299
300
301 Do not complain about things irrelevant for
302 Linux.
303
304
305 __-D__ or __--DOS__
306
307
308 For DOS-compatibility: waste a little space. (More
309 precisely: if a partition cannot contain sector 0, e.g.
310 because that is the MBR of the device, or contains the
311 partition table of an extended partition, then __sfdisk__
312 would make it start the next sector. However, when this
313 option is given it skips to the start of the next track,
314 wasting for example 33 sectors (in case of 34
315 sectors/track), just like certain versions of DOS do.)
316 Certain Disk Managers and boot loaders (such as OSBS, but
317 not LILO or the OS/2 Boot Manager) also live in this empty
318 space, so maybe you want this option if you use
319 one.
320
321
322 __-E__ or __--DOS-extended__
323
324
325 Take the starting sector numbers of
326
327
328 __--IBM__ or __--leave-last__
329
330
331 Certain IBM diagnostic programs assume that they can use the
332 last cylinder on a disk for disk-testing purposes. If you
333 think you might ever run such programs, use this option to
334 tell __sfdisk__ that it should not allocate the last
335 cylinder. Sometimes the last cylinder contains a bad sector
336 table.
337
338
339 __-n__
340
341
342 Go through all the motions, but do not actually write to
343 disk.
344
345
346 __-R__
347
348
349 Only execute the BLKRRPART ioctl (to make the kernel re-read
350 the partition table). This can be useful for checking in
351 advance that the final BLKRRPART will be successful, and
352 also when you changed the partition table `by hand' (e.g.,
353 using dd from a backup). If the kernel complains (`device
354 busy for revalidation (usage = 2)') then something still
355 uses the device, and you still have to unmount some file
356 system, or say swapoff to some swap partition.
357
358
359 __--no-reread__
360
361
362 When starting a repartitioning of a disk, sfdisk checks that
363 this disk is not mounted, or in use as a swap device, and
364 refuses to continue if it is. This option suppresses the
365 test. (On the other hand, the -f option would force sfdisk
366 to continue even when this test fails.)
367
368
369 __-O__ ''file''
370
371
372 Just before writing the new partition, output the sectors
373 that are going to be overwritten to ''file'' (where
374 hopefully ''file'' resides on another disk, or on a
375 floppy).
376
377
378 __-I__ ''file''
379
380
381 After destroying your filesystems with an unfortunate
382 __sfdisk__ command, you would have been able to restore
383 the old situation if only you had preserved it using the -O
384 flag.
385 !!THEORY
386
387
388 Block 0 of a disk (the Master Boot Record) contains among
389 other things four partition descriptors. The partitions
390 described here are called ''primary''
391 partitions.
392
393
394 A partition descriptor has 6 fields:
395
396
397 struct partition {
398 unsigned char bootable; /* 0 or 0x80 */
399 hsc begin_hsc;
400 unsigned char id;
401 hsc end_hsc;
402 unsigned int starting_sector;
403 unsigned int nr_of_sectors;
404 }
405 The two hsc fields indicate head, sector and cylinder of the begin and the end of the partition. Since each hsc field only takes 3 bytes, only 24 bits are available, which does not suffice for big disks (say lilo__ documentation.
406
407
408 Each partition has a type, its `Id', and if this type is 5
409 or f (`''extended partition''') the starting sector of
410 the partition again contains 4 partition descriptors. MSDOS
411 only uses the first two of these: the first one an actual
412 data partition, and the second one again an extended
413 partition (or empty). In this way one gets a chain of
414 extended partitions. Other operating systems have slightly
415 different conventions. Linux also accepts type 85 as
416 equivalent to 5 and f - this can be useful if one wants to
417 have extended partitions under Linux past the 1024 cylinder
418 boundary, without DOS FDISK hanging. (If there is no good
419 reason, you should just use 5, which is understood by other
420 systems.)
421
422
423 Partitions that are not primary or extended are called
424 ''logical''. Often, one cannot boot from logical
425 partitions (because the process of finding them is more
426 involved than just looking at the MBR). Note that of an
427 extended partition only the Id and the start are used. There
428 are various conventions about what to write in the other
429 fields. One should not try to use extended partitions for
430 data storage or swap.
431 !!INPUT FORMAT
432
433
434 __sfdisk__ reads lines of the form
435
436
437
438
439 where each line fills one partition descriptor.
440
441
442 Fields are separated by whitespace, or comma or semicolon
443 possibly followed by whitespace; initial and trailing
444 whitespace is ignored. Numbers can be octal, decimal or
445 hexadecimal, decimal is default. When a field is absent or
446 empty, a default value is used.
447
448
449 The
450 sfdisk__ computes them from
451 __
452
453
454 Bootable is specified as [[*|-], with as default
455 not-bootable. (The value of this field is irrelevant for
456 Linux - when Linux runs it has been booted already - but
457 might play a role for certain boot loaders and for other
458 operating systems. For example, when there are several
459 primary DOS partitions, DOS assigns C: to the first among
460 these that is bootable.)
461
462
463 Id is given in hex, without the 0x prefix, or is [[E|S|L|X],
464 where L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP
465 (82), E is EXTENDED_PARTITION (5), and X is LINUX_EXTENDED
466 (85).
467
468
469 The default value of start is the first nonassigned
470 sector/cylinder/...
471
472
473 The default value of size is as much as possible (until next
474 partition or end-of-disk).
475
476
477 However, for the four partitions inside an extended
478 partition, the defaults are: Linux partition, Extended
479 partition, Empty, Empty.
480
481
482 But when the -N option (change a single partition only) is
483 given, the default for each field is its previous
484 value.
485 !!EXAMPLE
486
487
488 The command
489
490
2 YazzAtlas 491 sfdisk /dev/hdc
1 perry 492
493
494 will partition /dev/hdc just as indicated
495 above.
496
497
498 With the -x option, the number of input lines must be a
499 multiple of 4: you have to list the two empty partitions
500 that you never want using two blank lines. Without the -x
501 option, you give one line for the partitions inside a
502 extended partition, instead of four, and terminate with
503 end-of-file (^D). (And __sfdisk__ will assume that your
504 input line represents the first of four, that the second one
505 is extended, and the 3rd and 4th are empty.)
506 !!DOS 6.x WARNING
507
508
509 The DOS 6.x FORMAT command looks for some information in the
510 first sector of the data area of the partition, and treats
511 this information as more reliable than the information in
512 the partition table. DOS FORMAT expects DOS FDISK to clear
513 the first 512 bytes of the data area of a partition whenever
514 a size change occurs. DOS FORMAT will look at this extra
515 information even if the /U flag is given -- we consider this
516 a bug in DOS FORMAT and DOS FDISK.
517
518
519 The bottom line is that if you use sfdisk to change the size
520 of a DOS partition table entry, then you must also use
521 __dd__ to zero the first 512 bytes of that partition
522 before using DOS FORMAT to format the partition. For
523 example, if you were using sfdisk to make a DOS partition
524 table entry for /dev/hda1, then (after exiting sfdisk and
525 rebooting Linux so that the partition table information is
526 valid) you would use the command
527 __BE EXTREMELY CAREFUL__ if you
528 use the __dd__ command, since a small typo can make all
529 of the data on your disk useless.
530
531
532 For best results, you should always use an OS-specific
533 partition table program. For example, you should make DOS
534 partitions with the DOS FDISK program and Linux partitions
535 with the Linux sfdisk program.
536 !!DRDOS WARNINGS
537
538
539 Stephen Tweedie reported (930515): `Most reports of
540 superblock corruption turn out to be due to bad
541 partitioning, with one filesystem overrunning the start of
542 the next and corrupting its superblock. I have even had this
543 problem with the supposedly-reliable DRDOS. This was quite
544 possibly due to DRDOS-6.0's FDISK command. Unless I created
545 a blank track or cylinder between the DRDOS partition and
546 the immediately following one, DRDOS would happily stamp all
547 over the start of the next partition. Mind you, as long as I
548 keep a little free disk space after any DRDOS partition, I
549 don't have any other problems with the two coexisting on the
550 one drive.'
551
552
553 A. V. Le Blanc writes in README.esfdisk: `Dr. DOS 5.0 and
554 6.0 has been reported to have problems cooperating with
555 Linux, and with this version of efdisk in particular. This
556 efdisk sets the system type to hexadecimal 81. Dr. DOS seems
557 to confuse this with hexadecimal 1, a DOS code. If you use
558 Dr. DOS, use the efdisk command 't' to change the system
559 code of any Linux partitions to some number less than
560 hexadecimal 80; I suggest 41 and 42 for the
561 moment.'
562
563
564 A. V. Le Blanc writes in his README.fdisk: `DR-DOS 5.0 and
565 6.0 are reported to have difficulties with partition ID
566 codes of 80 or more. The Linux `fdisk' used to set the
567 system type of new partitions to hexadecimal 81. DR-DOS
568 seems to confuse this with hexadecimal 1, a DOS code. The
569 values 82 for swap and 83 for file systems should not cause
570 problems with DR-DOS. If they do, you may use the `fdisk'
571 command `t' to change the system code of any Linux
572 partitions to some number less than hexadecimal 80; I
573 suggest 42 and 43 for the moment.'
574
575
576 In fact, it seems that only 4 bits are significant for the
577 DRDOS FDISK, so that for example 11 and 21 are listed as DOS
578 2.0. However, DRDOS itself seems to use the full byte. I
579 have not been able to reproduce any corruption with DRDOS or
580 its fdisk.
581 !!BUGS
582
583
584 A corresponding interactive __cfdisk__ (with curses
585 interface) is still lacking.
586
587
588 There are too many options.
589
590
591 There is no support for non-DOS partition
592 types.
593 !!AUTHOR
594
595
596 A. E. Brouwer (aeb@cwi.nl)
597 !!SEE ALSO
598
599
600 cfdisk(8), fdisk(8),
601 parted(8)
602 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.