1 .\" Copyright 1995 Andries E. Brouwer (aeb@cwi.nl)
2 .\" May be distributed under the GNU General Public License
3 .\" The `DOS 6.x Warning' was taken from the old fdisk.8, which says
4 .\" -- Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
5 .\" -- May be distributed under the GNU General Public License
6 .\" The `DRDOS Warning' was taken from a net post by Stephen Tweedie.
8 .TH SFDISK 8 "1 September 1995" "Linux" "Linux Programmer's Manual"
10 sfdisk \- Partition table manipulator for Linux
20 has four (main) uses: list the size of a partition, list the partitions
21 on a device, check the partitions on a device, and - very dangerous -
25 doesn't understand GUID Partition Table (GPT) and
26 it is not designed for large partitions. In particular case use more advanced GNU
30 .BI "sfdisk \-s " partition
33 in blocks. This may be useful in connection with programs like
37 is usually something like
41 but may also be an entire disk, like
47 % sfdisk \-s /dev/hda9
53 If the partition argument is omitted,
55 will list the sizes of all disks, and the total:
66 total: 12901917 blocks
73 The second type of invocation:
77 will list the partitions on this device.
78 If the device argument is omitted, the partitions on all hard disks
85 Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
86 Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
88 Device Boot Start End #cyls #blocks Id System
89 /dev/hdc1 0+ 406 407\- 205096+ 83 Linux native
90 /dev/hdc2 407 813 407 205128 83 Linux native
91 /dev/hdc3 814 2044 1231 620424 83 Linux native
92 /dev/hdc4 0 \- 0 0 0 Empty
96 The trailing \- and + signs indicate that rounding has taken place,
97 and that the actual value is slightly less (more).
98 To see the exact values, ask for a listing with sectors as unit.
100 .SS "Check partitions"
101 The third type of invocation:
102 .BI "sfdisk \-V " device
103 will apply various consistency checks to the partition tables on
105 It prints `OK' or complains. The \-V option can be used together
106 with \-l. In a shell script one might use
107 .BI "sfdisk \-V \-q " device
108 which only returns a status.
110 .SS "Create partitions"
111 The fourth type of invocation:
115 to read the specification for the desired partitioning of
117 from its standard input, and then to change the partition tables
118 on that disk. Thus, it is possible to use
120 from a shell script. When
122 determines that its standard input is a terminal, it will be
123 conversational; otherwise it will abort on any error.
125 BE EXTREMELY CAREFUL - ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST
127 As a precaution, one can save the sectors changed by
132 % sfdisk /dev/hdd \-O hdd-partition-sectors.save
139 Then, if you discover that you did something stupid before anything
140 else has been written to disk, it may be possible to recover
141 the old situation with
145 % sfdisk /dev/hdd \-I hdd-partition-sectors.save
151 (This is not the same as saving the old partition table:
152 a readable version of the old partition table can be saved
153 using the \-d option. However, if you create logical partitions,
154 the sectors describing them are located somewhere on disk,
155 possibly on sectors that were not part of the partition table
156 before. Thus, the information the \-O option saves is not a binary
157 version of the output of \-d.)
159 There are many options.
163 .BR \-v " or " \-\-version
164 Print version number of
166 and exit immediately.
168 .BR \-? " or " \-\-help
169 Print a usage message and exit immediately.
171 .BR \-T " or " \-\-list\-types
172 Print the recognized types (system Id's).
174 .BR \-s " or " \-\-show\-size
175 List the size of a partition.
177 .BR \-g " or " \-\-show\-geometry
178 List the kernel's idea of the geometry of the indicated disk(s).
180 .BR \-G " or " \-\-show\-pt\-geometry
181 List the geometry of the indicated disks guessed by looking at
184 .BR \-l " or " \-\-list
185 List the partitions of a device.
188 Dump the partitions of a device in a format useful as input
189 to sfdisk. For example,
193 % sfdisk -d /dev/hda > hda.out
194 % sfdisk /dev/hda < hda.out
197 will correct the bad last extended partition that the OS/2
200 .BR \-V " or " \-\-verify
201 Test whether partitions seem correct. (See above.)
203 .BR \-i " or " \-\-increment
204 Number cylinders etc. starting from 1 instead of 0.
207 Change only the single partition indicated. For example:
211 % sfdisk /dev/hdb \-N5
216 will make the fifth partition on /dev/hdb bootable (`active')
217 and change nothing else. (Probably this fifth partition
218 is called /dev/hdb5, but you are free to call it something else,
219 like `/my_equipment/disks/2/5' or so).
222 Make the indicated partition(s) active, and all others inactive.
224 .BI \-c "\fR or " \-\-id " number [Id]"
225 If no Id argument given: print the partition Id of the indicated
226 partition. If an Id argument is present: change the type (Id) of
227 the indicated partition to the given value.
228 This option has the two very long forms \-\-print\-id and \-\-change\-id.
233 % sfdisk --print-id /dev/hdb 5
235 % sfdisk --change-id /dev/hdb 5 83
239 first reports that /dev/hdb5 has Id 6, and then changes that into 83.
241 .BR \-uS " or " \-uB " or " \-uC " or " \-uM
242 Accept or report in units of sectors (blocks, cylinders, megabytes,
243 respectively). The default is cylinders, at least when the geometry
246 .BR \-x " or " \-\-show\-extended
247 Also list non-primary extended partitions on output,
248 and expect descriptors for them on input.
251 Specify the number of cylinders, possibly overriding what the kernel thinks.
254 Specify the number of heads, possibly overriding what the kernel thinks.
257 Specify the number of sectors, possibly overriding what the kernel thinks.
259 .BR \-f " or " \-\-force
260 Do what I say, even if it is stupid.
262 .BR \-q " or " \-\-quiet
263 Suppress warning messages.
265 .BR \-L " or " \-\-Linux
266 Do not complain about things irrelevant for Linux.
268 .BR \-D " or " \-\-DOS
269 For DOS-compatibility: waste a little space.
270 (More precisely: if a partition cannot contain sector 0,
271 e.g. because that is the MBR of the device, or contains
272 the partition table of an extended partition, then
274 would make it start the next sector. However, when this
275 option is given it skips to the start of the next track,
276 wasting for example 33 sectors (in case of 34 sectors/track),
277 just like certain versions of DOS do.)
278 Certain Disk Managers and boot loaders (such as OSBS, but not
279 LILO or the OS/2 Boot Manager) also live in this empty space,
280 so maybe you want this option if you use one.
282 .BR \-E " or " \-\-DOS\-extended
283 Take the starting sector numbers of "inner" extended partitions
284 to be relative to the starting cylinder boundary of the outer one,
285 (like some versions of DOS do) rather than to the starting sector
287 (The fact that there is a difference here means that one should
288 always let extended partitions start at cylinder boundaries if
289 DOS and Linux should interpret the partition table in the same way.
290 Of course one can only know where cylinder boundaries are when
291 one knows what geometry DOS will use for this disk.)
293 .BR \-\-IBM " or " \-\-leave\-last
294 Certain IBM diagnostic programs assume that they can use the
295 last cylinder on a disk for disk-testing purposes. If you think
296 you might ever run such programs, use this option to tell
298 that it should not allocate the last cylinder.
299 Sometimes the last cylinder contains a bad sector table.
302 Go through all the motions, but do not actually write to disk.
305 Only execute the BLKRRPART ioctl (to make the kernel re-read
306 the partition table). This can be useful for checking in advance
307 that the final BLKRRPART will be successful, and also when you
308 changed the partition table `by hand' (e.g., using dd from a backup).
309 If the kernel complains (`device busy for revalidation (usage = 2)')
310 then something still uses the device, and you still have to unmount
311 some file system, or say swapoff to some swap partition.
314 When starting a repartitioning of a disk, sfdisk checks that this disk
315 is not mounted, or in use as a swap device, and refuses to continue
316 if it is. This option suppresses the test. (On the other hand, the \-f
317 option would force sfdisk to continue even when this test fails.)
320 Just before writing the new partition, output the sectors
321 that are going to be overwritten to
325 resides on another disk, or on a floppy).
328 After destroying your filesystems with an unfortunate
330 command, you would have been able to restore the old situation
331 if only you had preserved it using the \-O flag.
334 Block 0 of a disk (the Master Boot Record) contains among
335 other things four partition descriptors. The partitions
336 described here are called
340 A partition descriptor has 6 fields:
345 unsigned char bootable; /* 0 or 0x80 */
349 unsigned int starting_sector;
350 unsigned int nr_of_sectors;
355 The two hsc fields indicate head, sector and cylinder of the
356 begin and the end of the partition. Since each hsc field only
357 takes 3 bytes, only 24 bits are available, which does not
358 suffice for big disks (say > 8GB). In fact, due to the wasteful
359 representation (that uses a byte for the number of heads, which
360 is typically 16), problems already start with 0.5GB.
361 However Linux does not use these fields, and problems can arise
362 only at boot time, before Linux has been started. For more
367 Each partition has a type, its `Id', and if this type is 5 or f
368 .IR "" "(`" "extended partition" "')"
369 the starting sector of the partition
370 again contains 4 partition descriptors. MSDOS only uses the
371 first two of these: the first one an actual data partition,
372 and the second one again an extended partition (or empty).
373 In this way one gets a chain of extended partitions.
374 Other operating systems have slightly different conventions.
375 Linux also accepts type 85 as equivalent to 5 and f - this can be
376 useful if one wants to have extended partitions under Linux past
377 the 1024 cylinder boundary, without DOS FDISK hanging.
378 (If there is no good reason, you should just use 5, which is
379 understood by other systems.)
381 Partitions that are not primary or extended are called
383 Often, one cannot boot from logical partitions (because the
384 process of finding them is more involved than just looking
386 Note that of an extended partition only the Id and the start
387 are used. There are various conventions about what to write
388 in the other fields. One should not try to use extended partitions
389 for data storage or swap.
393 reads lines of the form
396 <start> <size> <id> <bootable> <c,h,s> <c,h,s>
398 where each line fills one partition descriptor.
400 Fields are separated by whitespace, or comma or semicolon possibly
401 followed by whitespace; initial and trailing whitespace is ignored.
402 Numbers can be octal, decimal or hexadecimal, decimal is default.
403 When a field is absent or empty, a default value is used.
405 The <c,h,s> parts can (and probably should) be omitted -
407 computes them from <start> and <size> and the disk geometry
408 as given by the kernel or specified using the \-H, \-S, \-C flags.
410 Bootable is specified as [*|\-], with as default not-bootable.
411 (The value of this field is irrelevant for Linux - when Linux
412 runs it has been booted already - but might play a role for
413 certain boot loaders and for other operating systems.
414 For example, when there are several primary DOS partitions,
415 DOS assigns C: to the first among these that is bootable.)
417 Id is given in hex, without the 0x prefix, or is [E|S|L|X], where
418 L (LINUX_NATIVE (83)) is the default, S is LINUX_SWAP (82), E
419 is EXTENDED_PARTITION (5), and X is LINUX_EXTENDED (85).
421 The default value of start is the first nonassigned sector/cylinder/...
423 The default value of size is as much as possible (until next
424 partition or end-of-disk).
426 However, for the four partitions inside an extended partition,
427 the defaults are: Linux partition, Extended partition, Empty, Empty.
429 But when the \-N option (change a single partition only) is given,
430 the default for each field is its previous value.
437 sfdisk /dev/hdc << EOF
446 will partition /dev/hdc just as indicated above.
452 sfdisk /dev/hdb << EOF
465 will partition /dev/hdb into two Linux partitions of 3 and 60
466 cylinders, a swap space of 19 cylinders, and an extended partition
467 covering the rest. Inside the extended partition there are four
468 Linux logical partitions, three of 130 cylinders and one
471 With the \-x option, the number of input lines must be a multiple of 4:
472 you have to list the two empty partitions that you never want
473 using two blank lines. Without the \-x option, you give one line
474 for the partitions inside a extended partition, instead of four,
475 and terminate with end-of-file (^D).
478 will assume that your input line represents the first of four,
479 that the second one is extended, and the 3rd and 4th are empty.)
481 .SH "DOS 6.x WARNING"
483 The DOS 6.x FORMAT command looks for some information in the first
484 sector of the data area of the partition, and treats this information
485 as more reliable than the information in the partition table. DOS
486 FORMAT expects DOS FDISK to clear the first 512 bytes of the data area
487 of a partition whenever a size change occurs. DOS FORMAT will look at
488 this extra information even if the /U flag is given -- we consider
489 this a bug in DOS FORMAT and DOS FDISK.
491 The bottom line is that if you use sfdisk to change the size of a
492 DOS partition table entry, then you must also use
494 to zero the first 512 bytes of that partition before using DOS FORMAT to
495 format the partition. For example, if you were using sfdisk to make a DOS
496 partition table entry for /dev/hda1, then (after exiting sfdisk and
497 rebooting Linux so that the partition table information is valid) you
498 would use the command "dd if=/dev/zero of=/dev/hda1 bs=512 count=1" to zero
499 the first 512 bytes of the partition.
500 .B BE EXTREMELY CAREFUL
503 command, since a small typo can make all of the data on your disk useless.
505 For best results, you should always use an OS-specific partition table
506 program. For example, you should make DOS partitions with the DOS FDISK
507 program and Linux partitions with the Linux sfdisk program.
511 Stephen Tweedie reported (930515): `Most reports of superblock
512 corruption turn out to be due to bad partitioning, with one filesystem
513 overrunning the start of the next and corrupting its superblock.
514 I have even had this problem with the supposedly-reliable DRDOS. This
515 was quite possibly due to DRDOS-6.0's FDISK command. Unless I created
516 a blank track or cylinder between the DRDOS partition and the
517 immediately following one, DRDOS would happily stamp all over the
518 start of the next partition. Mind you, as long as I keep a little
519 free disk space after any DRDOS partition, I don't have any other
520 problems with the two coexisting on the one drive.'
522 A. V. Le Blanc writes in README.efdisk: `Dr. DOS 5.0 and 6.0 has been
523 reported to have problems cooperating with Linux, and with this version
524 of efdisk in particular. This efdisk sets the system type
525 to hexadecimal 81. Dr. DOS seems to confuse
526 this with hexadecimal 1, a DOS code. If you use Dr. DOS, use the
527 efdisk command 't' to change the system code of any Linux partitions
528 to some number less than hexadecimal 80; I suggest 41 and 42 for
531 A. V. Le Blanc writes in his README.fdisk: `DR-DOS 5.0 and 6.0
532 are reported to have difficulties with partition ID codes of 80 or more.
533 The Linux `fdisk' used to set the system type
534 of new partitions to hexadecimal 81. DR-DOS seems to confuse this with
535 hexadecimal 1, a DOS code. The values 82 for swap and 83 for file
536 systems should not cause problems with DR-DOS. If they do, you may use
537 the `fdisk' command `t' to change the system code of any Linux
538 partitions to some number less than hexadecimal 80; I suggest 42 and 43
541 In fact, it seems that only 4 bits are significant for the DRDOS FDISK,
542 so that for example 11 and 21 are listed as DOS 2.0. However, DRDOS
543 itself seems to use the full byte. I have not been able to reproduce
544 any corruption with DRDOS or its fdisk.
547 There are too many options.
549 There is no support for non-DOS partition types.
552 .\" A. E. Brouwer (aeb@cwi.nl)
562 The sfdisk command is part of the util-linux-ng package and is available from
563 ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.