1 .\" $NetBSD: fdisk.8,v 1.68 2009/12/17 14:27:49 pooka Exp $
8 .Nd MS-DOS partition maintenance program
13 .Op Fl 0 | 1 | 2 | 3 | E Ar number
22 .Op Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset
25 .Op Fl b Ar cylinders/heads/sectors
28 .Op Fl s Ar id/start/size Ns Bq Ar /bootmenu
44 program is used to display or update the
45 .Em "master boot record"
48 in the first sector (sector 0)
49 of a disk that uses the MBR style of partitioning.
52 ports use this style of disk partitioning:
53 amd64, arc, bebox, cobalt, hpcarm, hpcmips, hpcsh, i386, macppc,
54 mvmeppc, netwinder, ofppc, and prep.
56 The MBR contains bootable code, a partition table,
57 an indication of which partition is
59 and (optionally, depending on the boot code) a menu
60 for selecting a partition to be booted.
61 There can be at most 4 partitions defined in sector 0,
62 one of which can be an extended
63 partition which can be split into any number of sub-partitions.
65 The boot code in the MBR is usually invoked by the BIOS or firmware,
66 and the MBR passes control to the next stage boot code
67 stored in the first sector of the partition to be booted
69 .Em "partition boot record"
75 does not use the partitioning done by
79 disklabel saved in sector 1 of the
84 for a way of using information from the MBR
89 The standard MBR boot code will only boot the
94 contains additional boot programs which allow the user to
95 interactively select which of the partitions to boot.
100 from an extended partition but will not work on old systems that do not
101 support LBA reads, the
105 will read and write from a serial port.
108 program will determine whether the disk sector 0 is valid as a boot sector.
109 (This is determined by checking the magic number.)
112 will initialise the boot code as well as the partition table.
113 During this, all four partitions will be marked empty.
120 are used to indicate that the partition data is to be updated.
123 program will enter an interactive conversational mode.
124 This mode is designed not to change any data unless you explicitly tell it to;
126 selects defaults for its questions to guarantee that behaviour.
128 If partition data is going to be updated and the disk carries GUID Partition
131 will remove both primary and backup GPT headers from the disk.
134 for information on how to manipulate GUID Partition Tables.
137 will calculate the correct
142 values for any partition you edit.
145 you will be asked whether you want to specify them yourself.
147 Finally, when all the data for the first sector has been accumulated,
149 will ask if you really want to write the new partition table.
150 Only if you reply affirmatively to this question will
152 write anything to the disk.
158 Specify partition slot 0 to be printed or updated.
160 Specify partition slot 1 to be printed or updated.
162 Specify partition slot 2 to be printed or updated.
164 Specify partition slot 3 to be printed or updated.
166 Change the active partition.
167 In interactive mode this question will be asked after the partitions
169 .It Fl A Ar ptn_alignment Ns Bq Ar /ptn_0_offset
170 Specify the alignment for all partitions and optionally the offset for the
171 first partition of the disk and of extended partitions.
176 is not specified, then the offset is set to the alignment.
179 isn't specified, then the alignment of the first partition is inspected.
180 If it ends on a 2048 sector boundary, then the alignment is set to 2048,
181 if the start is a power of 2 less than, or equal to 2048 then the offset
182 is set to the start sector.
183 If the first partition isn't defined then the alignment and offset for disks
184 larger than 128GB is set to 2048 (1MB).
185 In all other cases the alignment default to a cylinder
186 and the offset to a track (both using the BIOS geometry).
187 The 1MB alignment is the same as that used by recent windows versions.
188 .It Fl b Ar cylinders/heads/sectors
189 Specify the BIOS geometry parameters for
194 It is used only in conjunction with the
197 If not specified the BIOS geometry will be obtained using sysctl (i386 and
198 amd64) or by solving the simultaenous equations from the existing partition
200 If that fails then either the geometry from the disklabel or 63 sectors and
203 On an i386 or amd64 system, interactively update the boot selector settings.
204 (The boot selector permits the user to interactively select the boot
205 partition, and thus which operating system is run, at system boot time.
208 for more information.)
210 Specify the filename that
212 should read the bootcode from.
213 If the name of a directory is specified, then
215 will look for files with the default names in that directory.
216 The default is to read from
218 .Pa /usr/mdec/mbr_bootsel
220 .Pa /usr/mdec/mbr_ext
223 was specified for any partitions
224 on an i386 machine, and leave the bootcode empty for other
227 Specify extended partition
229 to be printed or updated.
230 If the specified extended partition doesn't exist on updating partition data
231 an additional extended partition will be created.
235 in a non-interactive mode.
236 In this mode, you can only change the disk parameters by using the
239 This is provided only so scripts or other programs may use
241 as part of an automatic installation process.
247 makes it impossible to specify the starting and ending
253 .Pq only Ar start No and Ar size No can be specified by Fl s No option .
254 They will be automatically computed using the BIOS geometry.
259 Unless the geometry of
266 will count the 512-byte sectors in
268 and produce a fake geometry.
273 will be used implicitly.
275 Explicitly request initialisation of the master boot code
280 even if the magic number in the first sector is ok.
281 The partition table is left alone by this (but see above).
287 Read the boot record from file
289 instead of the specified disk.
290 The geometry information used is still that of the disk volume.
291 Any changes are written back to the file.
292 .It Fl s Ar id/start/size Ns Bq Ar /bootmenu
293 Specify the partition
299 This flag requires the use of a partition selection flag
300 .Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number .
302 When used with no other flags print a series of
304 commands for setting variables to the partition information.
305 This could be used by installation scripts.
316 instead of the disklabel on
319 Update partition data, including
320 .Em id , start , No and Em size .
324 .Pq non-interactive mode
327 will display the partitions and interactively ask which one you want to edit.
329 will step through each field showing the old value and asking for a new one.
334 can be specified in blocks (NN),
335 cylinders (NNc or NNcyl),
336 megabytes (NNm or NNMB),
337 or gigabytes (NNg or NNGB), values in megabytes and gigabytes
338 will be rounded to the nearest cylinder boundary.
343 in which case the partition will extend to the end of the available free space.
345 In a non-interactive mode
346 .Pq specified by Fl f No option ,
347 partition data should be specified by
350 A partition selection option
351 .Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number
352 should also be specified to select a partition slot to be updated.
355 will not allow you to create partitions which overlap.
360 are specified in a non-interactive mode
361 then the details of the specified partition will be changed.
362 Any other partitions which overlap the requested part of the disk will be
367 is specified for any partition
369 will determine whether the installed boot code supports the bootselect code,
370 if it doesn't you will be asked whether you want to install the required
379 Be more verbose, specifying
381 more than once may increase the amount of output.
387 allows the user to change more parameters than normally permitted.
389 Write the modified partition table to file
394 When called with no arguments, it prints the partition table.
398 NetBSD disklabel disk geometry:
399 cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
400 total sectors: 40032696
403 cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
404 total sectors: 40032696
407 0: NetBSD (sysid 169)
409 start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active
410 1: Primary DOS with 32 bit FAT (sysid 11)
412 start 63, size 4208967 (2055 MB, Cyls 0-262)
413 2: NetBSD (sysid 169)
415 start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40)
416 3: Ext. partition - LBA (sysid 15)
417 start 12498570, size 20016990 (9774 MB, Cyls 778-2024)
418 Extended partition table:
419 E0: NetBSD (sysid 169)
421 start 12498633, size 12305727 (6009 MB, Cyls 778-1544)
422 E1: Primary DOS with 32 bit FAT (sysid 11)
423 start 24804423, size 4096512 (2000 MB, Cyls 1544-1799)
424 E2: Primary DOS with 32 bit FAT (sysid 11)
425 start 28900998, size 3614562 (1765 MB, Cyls 1799-2024)
426 Bootselector enabled, infinite timeout.
427 First active partition: 0
430 This example disk is divided into four partitions the last of which is
431 an extended partition.
432 The sub-partitions of the extended partition are also shown.
433 In this case there is no free space in either the disk or in the extended
436 The various fields in each partition entry are:
439 .Em ptn_number : id_name
452 .Em first Ns No - Ns Em next )
456 .Bl -tag -width "bootmenu"
458 is the number of the partition.
460 is the name of the filesystem type or operating system that uses this partition.
462 is the number that identifies the partition type.
463 169 decimal is used for
466 15 decimal to create an extended partition
467 and 0 to mark a partition as unused.
471 to list the known partition types.
473 is the menu prompt output by the interactive boot code for this partition.
474 This line is omitted if the prompt is not defined.
475 .It Em start , Em size
476 are the start address and size of the partition in sectors.
478 is the size of the partition in megabytes.
479 .It Em first , Em next
480 are the bounds of this partition displayed as cylinder/head/sector.
481 If the partition starts (or ends) on a cylinder boundary the head and
482 sector values are omitted.
485 is not specified the start of extended partitions and the first partition
486 on the disk are rounded down to include the mandatory red tape in the
489 is output if this is the active partition.
494 flag is specified, the beginning and end of each partition are also
495 displayed as follows:
511 .Bl -tag -width "bootmenu"
512 .It Em "cylinder" , Em "head" , Em "sector"
513 are the beginning or ending address of a partition.
516 these numbers are read from the bootblock, so are the values calculated
522 attempts to check whether each partition is bootable,
523 by checking the magic number and some other characteristics
524 of the first sector of each partition (the PBR).
525 If the partition does not apear to be bootable,
527 will print a line containing
528 .Dq "PBR is not bootable"
529 followed by an error message.
530 If the partition is bootable, and if the
535 .Dq "PBR appears to be bootable" .
538 flag is specified more than once,
540 will print the heading
541 .Dq "Information from PBR:"
542 followed by one or more lines of information gleaned from the PBR;
543 this additional information may be incorrect or misleading,
544 because different operating systems use different PBR formats.
545 Note that, even if no errors are reported, an attempt to boot
546 from the partition might fail.
548 partitions may be made bootable using
551 This program is only available (and useful) on systems with PC-platform-style
554 Traditionally the partition boundaries should be on cylinder boundaries
555 using the BIOS geometry, with the exception of the first partition,
556 which traditionally begins in the second track of the first cylinder
557 (cylinder 0, head 1, sector 1).
558 Although the BIOS geometry is typically different from the geometry
559 reported by the drive, neither will match the actual physical geometry
560 for modern disks (the actual geometry will vary across the disk).
561 Keeping the partition boundaries on cylinder boundaries makes partitioning
562 a driver easier as only relatively small numbers need be entered.
564 The automatic calculation of the starting cylinder and
565 other parameters uses
566 a set of figures that represent what the BIOS thinks is the
567 geometry of the drive.
568 The default values should be correct for the system on which
570 is run, however if you move the disk to a different system the
571 BIOS of that system might use a different geometry translation.
573 If you run the equivalent of
575 on a different operating system then the
577 strings associated with extended partitions may be lost.
579 Editing an existing partition is risky, and may cause you to
580 lose all the data in that partition.
582 You should run this program interactively once or twice to see how it works.
583 This is completely safe as long as you answer the last question in the negative.
586 to write the output to a file and later specify
588 to read back the updated information.
589 This can be done without having write access to the disk volume.
591 .Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact
593 Default location of i386 bootcode
594 .It Pa /usr/mdec/mbr_bootsel
595 Default location of i386 bootselect code
596 .It Pa /usr/mdec/mbr_ext
597 Default location of i386 bootselect for extended partitions
600 Update MBR partition data of
604 .Dl Ic fdisk -u /dev/rwd0d
606 Change active MBR partition of
610 .Dl Ic fdisk -a /dev/rwd0d
613 .Pa /usr/mdec/mbr_bootsel
617 .Dl Ic fdisk -c /usr/mdec/mbr_bootsel /dev/rwd0d
619 Set MBR partition data for slot 0 of
621 specifying values without prompt:
623 .Dl Ic fdisk -f -u -0 -s 169/63/2097089 /dev/rwd0d
625 Make partition slot 0 of
627 active without prompt:
629 .Dl Ic fdisk -f -a -0 /dev/rwd0d
631 Initialize and create MBR partition data using bootcode
632 .Pa destdir/usr/mdec/mbr
633 without prompt against 1GB disk image file
636 .Dl Ic fdisk -f -i -b 130/255/63 -c destdir/usr/mdec/mbr -F diskimg
638 Create MBR partition data for slot 0 which has an active NetBSD partition
639 using whole disk without prompt against 1GB disk image file
642 .Dl Ic fdisk -f -a -u -0 -s 169/63/2097089 -F diskimg
654 is used to mean both an MBR partition and a
656 partition, sometimes in the same sentence.
658 There are subtleties that the program detects that are not explained in