Annotation of src/sbin/fdisk/fdisk.8, Revision 1.66
1.66 ! tsutsui 1: .\" $NetBSD: fdisk.8,v 1.65 2009/11/28 17:25:45 tsutsui Exp $
1.8 cgd 2: .\"
1.64 tsutsui 3: .Dd November 28, 2009
1.1 cgd 4: .Dt FDISK 8
1.25 wiz 5: .Os
1.1 cgd 6: .Sh NAME
7: .Nm fdisk
1.43 lukem 8: .Nd MS-DOS partition maintenance program
1.1 cgd 9: .Sh SYNOPSIS
1.34 wiz 10: .Nm
1.44 dyoung 11: .Op Fl afiuvBFS
1.17 mycroft 12: .Bk -words
1.9 phil 13: .Op Fl 0 | 1 | 2 | 3
1.17 mycroft 14: .Ek
15: .Bk -words
1.44 dyoung 16: .Op Fl t Ar disktab
17: .Ek
18: .Bk -words
19: .Op Fl T Ar disktype
20: .Ek
21: .Bk -words
1.35 dsl 22: .Op Fl E Ar number
23: .Ek
24: .Bk -words
1.10 phil 25: .Op Fl b Ar cylinders/heads/sectors
1.17 mycroft 26: .Ek
27: .Bk -words
1.38 wiz 28: .Op Fl s Ar id/start/size Ns Bq Ar /bootmenu
1.17 mycroft 29: .Ek
30: .Bk -words
1.16 ws 31: .Op Fl c Ar bootcode
1.17 mycroft 32: .Ek
33: .Bk -words
1.35 dsl 34: .Op Fl r|w Ar file
35: .Ek
36: .Bk -words
1.6 mycroft 37: .Op Ar device
1.17 mycroft 38: .Ek
1.35 dsl 39: .Nm
40: .Fl l
1.24 lukem 41: .Sh DESCRIPTION
1.35 dsl 42: The
1.1 cgd 43: .Nm
1.54 apb 44: program is used to display or update the
45: .Em "master boot record"
46: or
47: .Em MBR
48: in the first sector (sector 0)
49: of a disk that uses the MBR style of partitioning.
50: The following
51: .Nx
52: ports use this style of disk partitioning:
53: amd64, arc, bebox, cobalt, hpcarm, hpcmips, hpcsh, i386, macppc,
54: mvmeppc, netwinder, ofppc, playstation2, and prep.
55: .Pp
56: The MBR contains bootable code, a partition table,
57: an indication of which partition is
58: .Sq active ,
59: and (optionally, depending on the boot code) a menu
60: for selecting a partition to be booted.
1.35 dsl 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.
1.6 mycroft 64: .Pp
1.54 apb 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
68: (the
69: .Em "partition boot record"
70: or
71: .Em PBR ) .
72: .Pp
73: After booting,
1.13 perry 74: .Nx
1.35 dsl 75: does not use the partitioning done by
76: .Nm ,
77: instead it uses a
78: .Nx
79: disklabel saved in sector 1 of the
80: .Nx
81: partition.
1.54 apb 82: See
83: .Xr mbrlabel 8
84: for a way of using information from the MBR
85: to construct a
86: .Nx
87: disklabel.
1.1 cgd 88: .Pp
1.45 snj 89: The standard MBR boot code will only boot the
90: .Sq active
91: partition.
1.35 dsl 92: However
93: .Nx
1.59 dsl 94: contains additional boot programs which allow the user to
1.35 dsl 95: interactively select which of the partitions to boot.
1.45 snj 96: The
97: .Sq mbr_ext
1.59 dsl 98: code will also boot
1.13 perry 99: .Nx
1.35 dsl 100: from an extended partition but will not work on old systems that do not
1.59 dsl 101: support LBA reads, the
102: .Sq mbr_com0
103: and
104: .Sq mbr_com0_9600
105: will read and write from a serial port.
1.24 lukem 106: At the start the
107: .Nm
108: program will determine whether the disk sector 0 is valid as a boot sector.
109: (This is determined by checking the magic number.)
110: If not,
111: .Nm
1.35 dsl 112: will initialise the boot code as well as the partition table.
1.24 lukem 113: During this, all four partitions will be marked empty.
114: .Pp
1.1 cgd 115: The flags
1.9 phil 116: .Fl a ,
1.26 wiz 117: .Fl i
1.1 cgd 118: or
119: .Fl u
1.4 jtc 120: are used to indicate that the partition data is to be updated.
1.1 cgd 121: The
122: .Nm
1.24 lukem 123: program will enter an interactive conversational mode.
1.6 mycroft 124: This mode is designed not to change any data unless you explicitly tell it to;
1.1 cgd 125: .Nm
1.35 dsl 126: selects defaults for its questions to guarantee that behaviour.
1.1 cgd 127: .Pp
1.61 snj 128: If partition data is going to be updated and the disk carries GUID Partition
129: Tables,
1.60 christos 130: .Nm
131: will remove both primary and backup GPT headers from the disk.
132: See
133: .Xr gpt 8
134: for information on how to manipulate GUID Partition Tables.
135: .Pp
1.35 dsl 136: .Nm
137: will calculate the correct
1.11 lukem 138: .Em cylinder ,
139: .Em head ,
1.1 cgd 140: and
1.11 lukem 141: .Em sector
1.38 wiz 142: values for any partition you edit.
143: If you specify
1.35 dsl 144: .Fl v
145: you will be asked whether you want to specify them yourself.
1.1 cgd 146: .Pp
1.35 dsl 147: Finally, when all the data for the first sector has been accumulated,
1.6 mycroft 148: .Nm
1.35 dsl 149: will ask if you really want to write the new partition table.
1.6 mycroft 150: Only if you reply affirmatively to this question will
151: .Nm
152: write anything to the disk.
1.1 cgd 153: .Pp
1.24 lukem 154: Available options:
1.18 fvdl 155: .Pp
1.24 lukem 156: .Bl -tag -width Ds
157: .It Fl 0
1.64 tsutsui 158: Specify partition slot 0 to be printed or updated.
1.24 lukem 159: .It Fl 1
1.64 tsutsui 160: Specify partition slot 1 to be printed or updated.
1.24 lukem 161: .It Fl 2
1.64 tsutsui 162: Specify partition slot 2 to be printed or updated.
1.24 lukem 163: .It Fl 3
1.64 tsutsui 164: Specify partition slot 3 to be printed or updated.
1.24 lukem 165: .It Fl a
166: Change the active partition.
167: In interactive mode this question will be asked after the partitions
168: have been processed.
169: .It Fl b Ar cylinders/heads/sectors
170: Specify the BIOS parameters for
171: .Ar cylinders ,
1.38 wiz 172: .Ar heads ,
1.10 phil 173: and
1.24 lukem 174: .Ar sectors .
175: It is used only in conjunction with the
1.10 phil 176: .Fl u
1.15 ws 177: flag.
1.24 lukem 178: .It Fl B
1.35 dsl 179: On an i386 or amd64 system, interactively update the boot selector settings.
1.32 perry 180: (The boot selector permits the user to interactively select the boot
181: partition, and thus which operating system is run, at system boot time.
1.33 wiz 182: See
1.32 perry 183: .Xr mbr 8
184: for more information.)
1.24 lukem 185: .It Fl c Ar bootcode
186: Specify the filename that
187: .Nm
188: should read the bootcode from.
1.35 dsl 189: If the name of a directory is specified, then
190: .Nm
191: will look for files with the default names in that directory.
1.24 lukem 192: The default is to read from
1.35 dsl 193: .Pa /usr/mdec/mbr ,
194: .Pa /usr/mdec/mbr_bootsel
195: or
196: .Pa /usr/mdec/mbr_ext
197: depending on whether
1.40 dsl 198: .Ar bootmenu
1.35 dsl 199: was specified for any partitions
200: on an i386 machine, and leave the bootcode empty for other
1.24 lukem 201: machines.
1.35 dsl 202: .It Fl E Ar number
1.64 tsutsui 203: Specify extended partition
204: .Ar number
205: to be printed or updated.
206: If the specified extended partition doesn't exist on updating partition data
207: an additional extended partition will be created.
1.24 lukem 208: .It Fl f
209: Run
1.9 phil 210: .Nm
1.24 lukem 211: in a non-interactive mode.
1.26 wiz 212: In this mode, you can only change the disk parameters by using the
1.10 phil 213: .Fl b
1.24 lukem 214: flag.
215: This is provided only so scripts or other programs may use
216: .Nm
217: as part of an automatic installation process.
1.47 lukem 218: .Pp
1.24 lukem 219: Using the
1.9 phil 220: .Fl f
1.12 ross 221: flag with
1.9 phil 222: .Fl u
1.10 phil 223: makes it impossible to specify the starting and ending
1.24 lukem 224: .Ar cylinder ,
1.38 wiz 225: .Ar head ,
1.26 wiz 226: and
1.24 lukem 227: .Ar sector
1.64 tsutsui 228: fields
229: .Pq only Ar start No and Ar size No can be specified by Fl s No option .
1.24 lukem 230: They will be automatically computed using the BIOS geometry.
1.45 snj 231: .It Fl F
1.44 dyoung 232: Indicate that
233: .Ar device
1.45 snj 234: is a regular file.
235: Unless the geometry of
1.44 dyoung 236: .Ar device
237: is told to
1.46 wiz 238: .Nm
1.44 dyoung 239: by
240: .Fl T Ar disktype ,
1.46 wiz 241: .Nm
1.44 dyoung 242: will count the 512-byte sectors in
243: .Ar device
244: and produce a fake geometry.
1.24 lukem 245: .It Fl i
1.35 dsl 246: Explicitly request initialisation of the master boot code
1.24 lukem 247: (similar to what
1.46 wiz 248: .Ic fdisk /mbr
1.24 lukem 249: does under
1.43 lukem 250: .Tn MS-DOS ) ,
1.26 wiz 251: even if the magic number in the first sector is ok.
1.24 lukem 252: The partition table is left alone by this (but see above).
1.30 christos 253: .It Fl l
254: Lists known
255: .Em sysid
256: values and exit.
1.35 dsl 257: .It Fl r Ar file
258: Read the boot record from file
259: .Ar file
260: instead of the specified disk.
261: The geometry information used is still that of the disk volume.
262: Any changes are written back to the file.
1.38 wiz 263: .It Fl s Ar id/start/size Ns Bq Ar /bootmenu
1.24 lukem 264: Specify the partition
265: .Ar id ,
1.35 dsl 266: .Ar start ,
1.38 wiz 267: .Ar size ,
1.35 dsl 268: and optionally
269: .Ar bootmenu .
1.24 lukem 270: This flag requires the use of a partition selection flag
1.64 tsutsui 271: .Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number .
1.24 lukem 272: .It Fl S
1.26 wiz 273: When used with no other flags print a series of
1.24 lukem 274: .Pa /bin/sh
275: commands for setting variables to the partition information.
1.35 dsl 276: This could be used by installation scripts.
1.44 dyoung 277: .It Fl t Ar disktab
1.45 snj 278: Read
1.44 dyoung 279: .Ar disktype
1.45 snj 280: from the named
281: .Xr disktab 5
1.44 dyoung 282: file instead of from
1.45 snj 283: .Pa /etc/disktab .
1.44 dyoung 284: .It Fl T Ar disktype
1.45 snj 285: Use the disklabel
1.44 dyoung 286: .Ar disktype
287: instead of the disklabel on
288: .Ar device .
1.24 lukem 289: .It Fl u
1.64 tsutsui 290: Update partition data, including
291: .Em id , start , No and Em size .
292: Unless
293: .Fl f
294: option
295: .Pq non-interactive mode
296: is specified,
297: .Nm
298: will display the partitions and interactively ask which one you want to edit.
1.24 lukem 299: .Nm
1.35 dsl 300: will step through each field showing the old value and asking for a new one.
301: The
302: .Em start
1.36 wiz 303: and
1.35 dsl 304: .Em size
1.65 tsutsui 305: can be specified in blocks (NN),
306: cylinders (NNc or NNcyl),
307: megabytes (NNm or NNMB),
308: or gigabytes (NNg or NNGB), values in megabytes and gigabytes
1.51 dsl 309: will be rounded to the nearest cylinder boundary.
1.35 dsl 310: The
311: .Em size
312: may be specified as
313: .Em $
314: in which case the partition will extend to the end of the available free space.
1.47 lukem 315: .Pp
1.64 tsutsui 316: In a non-interactive mode
317: .Pq specified by Fl f No option ,
318: partition data should be specified by
319: .Fl s
320: option.
321: A partition selection option
322: .Pq Fl 0 , 1 , 2 , 3 , No or Fl E Ar number
323: should also be specified to select a partition slot to be updated.
324: .Pp
1.35 dsl 325: .Nm
326: will not allow you to create partitions which overlap.
1.64 tsutsui 327: If
328: .Fl u
329: and
330: .Fl s
331: are specified in a non-interactive mode
332: then the details of the specified partition will be changed.
333: Any other partitions which overlap the requested part of the disk will be
334: silently deleted.
1.35 dsl 335: .Pp
336: If
337: .Em bootmenu
338: is specified for any partition
339: .Nm
340: will determine whether the installed boot code supports the bootselect code,
341: if it doesn't you will be asked whether you want to install the required
1.53 wiz 342: boot code.
343: To remove a
1.52 jmcneill 344: .Em bootmenu
1.53 wiz 345: label, simply press
346: .Aq space
347: followed by
348: .Aq return .
1.35 dsl 349: .It Fl v
350: Be more verbose, specifying
351: .Fl v
352: more than once may increase the amount of output.
1.47 lukem 353: .Pp
354: Using
1.35 dsl 355: .Fl v
356: with
357: .Fl u
1.47 lukem 358: allows the user to change more parameters than normally permitted.
1.35 dsl 359: .It Fl w Ar file
360: Write the modified partition table to file
361: .Ar file
362: instead of the disk.
363: .El
364: .Pp
365: When called with no arguments, it prints the partition table.
366: An example follows:
367: .Bd -literal
368: Disk: /dev/rwd0d
369: NetBSD disklabel disk geometry:
370: cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
371: total sectors: 40032696
372:
373: BIOS disk geometry:
374: cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
375: total sectors: 40032696
376:
377: Partition table:
378: 0: NetBSD (sysid 169)
379: bootmenu: net 1.5.
380: start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active
381: 1: Primary DOS with 32 bit FAT (sysid 11)
382: bootmenu: win98
383: start 63, size 4208967 (2055 MB, Cyls 0-262)
384: 2: NetBSD (sysid 169)
385: bootmenu: current
386: start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40)
387: 3: Ext. partition - LBA (sysid 15)
388: start 12498570, size 20016990 (9774 MB, Cyls 778-2024)
389: Extended partition table:
390: E0: NetBSD (sysid 169)
391: bootmenu: test
392: start 12498633, size 12305727 (6009 MB, Cyls 778-1544)
393: E1: Primary DOS with 32 bit FAT (sysid 11)
394: start 24804423, size 4096512 (2000 MB, Cyls 1544-1799)
395: E2: Primary DOS with 32 bit FAT (sysid 11)
396: start 28900998, size 3614562 (1765 MB, Cyls 1799-2024)
397: Bootselector enabled, infinite timeout.
1.57 apb 398: First active partition: 0
1.35 dsl 399: .Ed
400: .Pp
401: This example disk is divided into four partitions the last of which is
402: an extended partition.
403: The sub-partitions of the extended partition are also shown.
404: In this case there is no free space in either the disk or in the extended
405: partition.
406: .Pp
407: The various fields in each partition entry are:
408: .br
409: .in +4
410: .Em ptn_number : id_name
411: (sysid
412: .Em id_number )
413: .br
414: .in +4
415: bootmenu:
416: .Em bootmenu
417: .br
418: start
419: .Em start ,
420: size
1.39 wiz 421: .Em size ( MB
1.35 dsl 422: MB, Cyls
1.39 wiz 423: .Em first Ns No - Ns Em next )
1.35 dsl 424: .Op , Active
425: .in -4
426: .in -4
427: .Bl -tag -width "bootmenu"
428: .It Em ptn_number
429: is the number of the partition.
430: .It Em id_name
431: is the name of the filesystem type or operating system that uses this partition.
432: .It Em id_number
433: is the number that identifies the partition type.
434: 169 decimal is used for
435: .Nx
436: partitions,
437: 15 decimal to create an extended partition
438: and 0 to mark a partition as unused.
439: Use
1.24 lukem 440: .Nm
1.35 dsl 441: .Fl l
442: to list the known partition types.
443: .It Em bootmenu
444: is the menu prompt output by the interactive boot code for this partition.
445: This line is omitted if the prompt is not defined.
1.63 joerg 446: .It Em start , Em size
1.35 dsl 447: are the start address and size of the partition in sectors.
448: .It Em MB
449: is the size of the partition in megabytes.
1.63 joerg 450: .It Em first , Em next
1.35 dsl 451: are the bounds of this partition displayed as cylinder/head/sector.
452: If the partition starts (or ends) on a cylinder boundary the head and
453: sector values are omitted.
1.36 wiz 454: If
1.35 dsl 455: .Fl v
456: is not specified the start of extended partitions and the first partition
457: on the disk are rounded down to include the mandatory red tape in the
1.45 snj 458: preceding track.
1.35 dsl 459: .It Active
460: is output if this is the active partition.
461: .El
462: .Pp
463: If the
464: .Fl v
1.56 wiz 465: flag is specified, the beginning and end of each partition are also
1.54 apb 466: displayed as follows:
1.35 dsl 467: .in +4
468: beg: cylinder
469: .Em cylinder ,
470: head
471: .Em head ,
472: sector
473: .Em sector
474: .br
475: end: cylinder
476: .Em cylinder ,
477: head
478: .Em head ,
479: sector
480: .Em sector
481: .in -4
482: .Bl -tag -width "bootmenu"
1.63 joerg 483: .It Em "cylinder" , Em "head" , Em "sector"
1.35 dsl 484: are the beginning or ending address of a partition.
1.47 lukem 485: .Pp
1.35 dsl 486: .Em "Note:"
487: these numbers are read from the bootblock, so are the values calculated
488: by a previous run of
489: .Nm .
1.24 lukem 490: .El
1.54 apb 491: .Pp
492: .Nm
493: attempts to check whether each partition is bootable,
494: by checking the magic number and some other characteristics
495: of the first sector of each partition (the PBR).
496: If the partition does not apear to be bootable,
497: .Nm
498: will print a line containing
499: .Dq "PBR is not bootable"
500: followed by an error message.
501: If the partition is bootable, and if the
502: .Fl v
503: flag is specified,
504: .Nm
505: will print
506: .Dq "PBR appears to be bootable" .
507: If the
508: .Fl v
509: flag is specified more than once,
510: .Nm
511: will print the heading
512: .Dq "Information from PBR:"
513: followed by one or more lines of information gleaned from the PBR;
514: this additional information may be incorrect or misleading,
515: because different operating systems use different PBR formats.
516: Note that, even if no errors are reported, an attempt to boot
517: from the partition might fail.
518: .Nx
519: partitions may be made bootable using
520: .Xr installboot 8 .
1.1 cgd 521: .Sh NOTES
1.48 darcy 522: This program is only available (and useful) on systems with PC-platform-style
1.49 wiz 523: MBR partitioning.
1.48 darcy 524: .Pp
1.35 dsl 525: Traditionally the partition boundaries should be on cylinder boundaries
1.58 apb 526: using the BIOS geometry, with the exception of the first partition,
527: which traditionally begins in the second track of the first cylinder
528: (cylinder 0, head 1, sector 1).
1.35 dsl 529: Although the BIOS geometry is typically different from the geometry
530: reported by the drive, neither will match the actual physical geometry
531: for modern disks (the actual geometry will vary across the disk).
532: Keeping the partition boundaries on cylinder boundaries makes partitioning
533: a driver easier as only relatively small numbers need be entered.
534: .Pp
1.12 ross 535: The automatic calculation of the starting cylinder and
536: other parameters uses
1.1 cgd 537: a set of figures that represent what the BIOS thinks is the
538: geometry of the drive.
1.35 dsl 539: The default values should be correct for the system on which
540: .Nm
541: is run, however if you move the disk to a different system the
542: BIOS of that system might use a different geometry translation.
543: .Pp
544: If you run the equivalent of
1.6 mycroft 545: .Nm
1.35 dsl 546: on a different operating system then the
1.40 dsl 547: .Ar bootmenu
1.35 dsl 548: strings associated with extended partitions may be lost.
1.1 cgd 549: .Pp
1.6 mycroft 550: Editing an existing partition is risky, and may cause you to
1.1 cgd 551: lose all the data in that partition.
552: .Pp
553: You should run this program interactively once or twice to see how it works.
554: This is completely safe as long as you answer the last question in the negative.
1.35 dsl 555: You can also specify
556: .Fl w Ar file
557: to write the output to a file and later specify
558: .Fl r Ar file
559: to read back the updated information.
560: This can be done without having write access to the disk volume.
1.16 ws 561: .Sh FILES
1.18 fvdl 562: .Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact
1.16 ws 563: .It Pa /usr/mdec/mbr
564: Default location of i386 bootcode
1.18 fvdl 565: .It Pa /usr/mdec/mbr_bootsel
566: Default location of i386 bootselect code
1.35 dsl 567: .It Pa /usr/mdec/mbr_ext
568: Default location of i386 bootselect for extended partitions
1.16 ws 569: .El
1.62 yamt 570: .Sh EXAMPLES
1.66 ! tsutsui 571: Update MBR partition data of
! 572: .Pa /dev/rwd0d
! 573: in interactive mode:
! 574: .Pp
! 575: .Dl Ic fdisk -u /dev/rwd0d
! 576: .Pp
! 577: Change active MBR partition of
! 578: .Pa /dev/rwd0d
! 579: in interactive mode:
! 580: .Pp
! 581: .Dl Ic fdisk -a /dev/rwd0d
! 582: .Pp
! 583: Install MBR bootcode
! 584: .Pa /usr/mdec/mbr_bootsel
! 585: into
! 586: .Pa /dev/rwd0d :
! 587: .Pp
! 588: .Dl Ic fdisk -c /usr/mdec/mbr_bootsel /dev/rwd0d
! 589: .Pp
! 590: Set MBR partition data for slot 0 of
! 591: .Pa /dev/rwd0d
! 592: specifying values without prompt:
! 593: .Pp
! 594: .Dl Ic fdisk -f -u -0 -s 169/63/2097089 /dev/rwd0d
! 595: .Pp
! 596: Make partition slot 0 of
! 597: .Pa /dev/rwd0d
! 598: active without prompt:
! 599: .Pp
! 600: .Dl Ic fdisk -f -a -0 /dev/rwd0d
! 601: .Pp
! 602: Initialize and create MBR partition data using bootcode
! 603: .Pa destdir/usr/mdec/mbr
! 604: without prompt against 1GB disk image file
! 605: .Pa diskimg :
! 606: .Pp
! 607: .Dl Ic fdisk -f -i -b 130/255/63 -c destdir/usr/mdec/mbr -F diskimg
! 608: .Pp
! 609: Create MBR partition data for slot 0 which has an active NetBSD partition
! 610: using whole disk without prompt against 1GB disk image file
! 611: .Pa diskimg :
! 612: .Pp
! 613: .Dl Ic fdisk -f -a -u -0 -s 169/63/2097089 -F diskimg
1.1 cgd 614: .Sh SEE ALSO
1.45 snj 615: .Xr disktab 5 ,
1.54 apb 616: .Xr boot 8 ,
1.23 abs 617: .Xr disklabel 8 ,
1.60 christos 618: .Xr gpt 8 ,
1.54 apb 619: .Xr installboot 8 ,
1.27 fair 620: .Xr mbr 8 ,
1.23 abs 621: .Xr mbrlabel 8
1.1 cgd 622: .Sh BUGS
1.45 snj 623: The word
624: .Sq partition
625: is used to mean both an MBR partition and a
1.35 dsl 626: .Nx
627: partition, sometimes in the same sentence.
628: .Pp
1.6 mycroft 629: There are subtleties that the program detects that are not explained in
630: this manual page.
CVSweb <webmaster@jp.NetBSD.org>