1.\" $NetBSD: fdisk.8,v 1.51 2005/04/07 20:23:13 dsl Exp $ 2.\" 3.Dd April 7, 2005 4.Dt FDISK 8 5.Os 6.Sh NAME 7.Nm fdisk 8.Nd MS-DOS partition maintenance program 9.Sh SYNOPSIS 10.Nm 11.Op Fl afiuvBFS 12.Bk -words 13.Op Fl 0 | 1 | 2 | 3 14.Ek 15.Bk -words 16.Op Fl t Ar disktab 17.Ek 18.Bk -words 19.Op Fl T Ar disktype 20.Ek 21.Bk -words 22.Op Fl E Ar number 23.Ek 24.Bk -words 25.Op Fl b Ar cylinders/heads/sectors 26.Ek 27.Bk -words 28.Op Fl s Ar id/start/size Ns Bq Ar /bootmenu 29.Ek 30.Bk -words 31.Op Fl c Ar bootcode 32.Ek 33.Bk -words 34.Op Fl r|w Ar file 35.Ek 36.Bk -words 37.Op Ar device 38.Ek 39.Nm 40.Fl l 41.Sh DESCRIPTION 42The 43.Nm 44program is used to divide space on a disk into partitions and set 45one active. 46There can be at most 4 partitions defined in sector 0, 47one of which can be an extended 48partition which can be split into any number of sub-partitions. 49.Pp 50.Nx 51does not use the partitioning done by 52.Nm , 53instead it uses a 54.Nx 55disklabel saved in sector 1 of the 56.Nx 57partition. 58.Pp 59The standard MBR boot code will only boot the 60.Sq active 61partition. 62However 63.Nx 64contains two alternate boot programs which allow the user to 65interactively select which of the partitions to boot. 66The 67.Sq mbr_ext 68code will boot 69.Nx 70from an extended partition but will not work on old systems that do not 71support LBA reads. 72.Pp 73At the start the 74.Nm 75program will determine whether the disk sector 0 is valid as a boot sector. 76(This is determined by checking the magic number.) 77If not, 78.Nm 79will initialise the boot code as well as the partition table. 80During this, all four partitions will be marked empty. 81.Pp 82The flags 83.Fl a , 84.Fl i 85or 86.Fl u 87are used to indicate that the partition data is to be updated. 88The 89.Nm 90program will enter an interactive conversational mode. 91This mode is designed not to change any data unless you explicitly tell it to; 92.Nm 93selects defaults for its questions to guarantee that behaviour. 94.Pp 95.Nm 96will calculate the correct 97.Em cylinder , 98.Em head , 99and 100.Em sector 101values for any partition you edit. 102If you specify 103.Fl v 104you will be asked whether you want to specify them yourself. 105.Pp 106Finally, when all the data for the first sector has been accumulated, 107.Nm 108will ask if you really want to write the new partition table. 109Only if you reply affirmatively to this question will 110.Nm 111write anything to the disk. 112.Pp 113Available options: 114.Pp 115.Bl -tag -width Ds 116.It Fl 0 117Update partition slot 0. 118.It Fl 1 119Update partition slot 1. 120.It Fl 2 121Update partition slot 2. 122.It Fl 3 123Update partition slot 3. 124.It Fl a 125Change the active partition. 126In interactive mode this question will be asked after the partitions 127have been processed. 128.It Fl b Ar cylinders/heads/sectors 129Specify the BIOS parameters for 130.Ar cylinders , 131.Ar heads , 132and 133.Ar sectors . 134It is used only in conjunction with the 135.Fl u 136flag. 137.It Fl B 138On an i386 or amd64 system, interactively update the boot selector settings. 139(The boot selector permits the user to interactively select the boot 140partition, and thus which operating system is run, at system boot time. 141See 142.Xr mbr 8 143for more information.) 144.It Fl c Ar bootcode 145Specify the filename that 146.Nm 147should read the bootcode from. 148If the name of a directory is specified, then 149.Nm 150will look for files with the default names in that directory. 151The default is to read from 152.Pa /usr/mdec/mbr , 153.Pa /usr/mdec/mbr_bootsel 154or 155.Pa /usr/mdec/mbr_ext 156depending on whether 157.Ar bootmenu 158was specified for any partitions 159on an i386 machine, and leave the bootcode empty for other 160machines. 161.It Fl E Ar number 162Update extended partition 163.Ar number . 164If the specified extended partition doesn't exist an additional extended 165partition will be created. 166.It Fl f 167Run 168.Nm 169in a non-interactive mode. 170In this mode, you can only change the disk parameters by using the 171.Fl b 172flag. 173This is provided only so scripts or other programs may use 174.Nm 175as part of an automatic installation process. 176.Pp 177Using the 178.Fl f 179flag with 180.Fl u 181makes it impossible to specify the starting and ending 182.Ar cylinder , 183.Ar head , 184and 185.Ar sector 186fields. 187They will be automatically computed using the BIOS geometry. 188.Pp 189If 190.Fl u 191and 192.Fl s 193are specified then the details of the specified partition will be changed. 194Any other partitions which overlap the requested part of the disk will be 195silently deleted. 196.It Fl F 197Indicate that 198.Ar device 199is a regular file. 200Unless the geometry of 201.Ar device 202is told to 203.Nm 204by 205.Fl T Ar disktype , 206.Nm 207will count the 512-byte sectors in 208.Ar device 209and produce a fake geometry. 210.It Fl i 211Explicitly request initialisation of the master boot code 212(similar to what 213.Ic fdisk /mbr 214does under 215.Tn MS-DOS ) , 216even if the magic number in the first sector is ok. 217The partition table is left alone by this (but see above). 218.It Fl l 219Lists known 220.Em sysid 221values and exit. 222.It Fl r Ar file 223Read the boot record from file 224.Ar file 225instead of the specified disk. 226The geometry information used is still that of the disk volume. 227Any changes are written back to the file. 228.It Fl s Ar id/start/size Ns Bq Ar /bootmenu 229Specify the partition 230.Ar id , 231.Ar start , 232.Ar size , 233and optionally 234.Ar bootmenu . 235This flag requires the use of a partition selection flag 236.Po 237.Fl 0 , 238.Fl 1 , 239.Fl 2 , 240.Fl 3 , 241or 242.Fl E Ar number 243.Pc 244.It Fl S 245When used with no other flags print a series of 246.Pa /bin/sh 247commands for setting variables to the partition information. 248This could be used by installation scripts. 249.It Fl t Ar disktab 250Read 251.Ar disktype 252from the named 253.Xr disktab 5 254file instead of from 255.Pa /etc/disktab . 256.It Fl T Ar disktype 257Use the disklabel 258.Ar disktype 259instead of the disklabel on 260.Ar device . 261.It Fl u 262Display the partitions and interactively ask which one you want to edit. 263.Nm 264will step through each field showing the old value and asking for a new one. 265The 266.Em start 267and 268.Em size 269can be specified in blocks (nn), cylinders (nnc), megabytes (nnm), 270or gigabytes (nng), values in megabytes and gigabytes 271will be rounded to the nearest cylinder boundary. 272The 273.Em size 274may be specified as 275.Em $ 276in which case the partition will extend to the end of the available free space. 277.Pp 278.Nm 279will not allow you to create partitions which overlap. 280.Pp 281If 282.Em bootmenu 283is specified for any partition 284.Nm 285will determine whether the installed boot code supports the bootselect code, 286if it doesn't you will be asked whether you want to install the required 287boot code. 288.It Fl v 289Be more verbose, specifying 290.Fl v 291more than once may increase the amount of output. 292.Pp 293Using 294.Fl v 295with 296.Fl u 297allows the user to change more parameters than normally permitted. 298.It Fl w Ar file 299Write the modified partition table to file 300.Ar file 301instead of the disk. 302.El 303.Pp 304When called with no arguments, it prints the partition table. 305An example follows: 306.Bd -literal 307 Disk: /dev/rwd0d 308 NetBSD disklabel disk geometry: 309 cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder) 310 total sectors: 40032696 311 312 BIOS disk geometry: 313 cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder) 314 total sectors: 40032696 315 316 Partition table: 317 0: NetBSD (sysid 169) 318 bootmenu: net 1.5. 319 start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active 320 1: Primary DOS with 32 bit FAT (sysid 11) 321 bootmenu: win98 322 start 63, size 4208967 (2055 MB, Cyls 0-262) 323 2: NetBSD (sysid 169) 324 bootmenu: current 325 start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40) 326 3: Ext. partition - LBA (sysid 15) 327 start 12498570, size 20016990 (9774 MB, Cyls 778-2024) 328 Extended partition table: 329 E0: NetBSD (sysid 169) 330 bootmenu: test 331 start 12498633, size 12305727 (6009 MB, Cyls 778-1544) 332 E1: Primary DOS with 32 bit FAT (sysid 11) 333 start 24804423, size 4096512 (2000 MB, Cyls 1544-1799) 334 E2: Primary DOS with 32 bit FAT (sysid 11) 335 start 28900998, size 3614562 (1765 MB, Cyls 1799-2024) 336 Bootselector enabled, infinite timeout. 337.Ed 338.Pp 339This example disk is divided into four partitions the last of which is 340an extended partition. 341The sub-partitions of the extended partition are also shown. 342In this case there is no free space in either the disk or in the extended 343partition. 344.Pp 345The various fields in each partition entry are: 346.br 347.in +4 348.Em ptn_number : id_name 349(sysid 350.Em id_number ) 351.br 352.in +4 353bootmenu: 354.Em bootmenu 355.br 356start 357.Em start , 358size 359.Em size ( MB 360MB, Cyls 361.Em first Ns No - Ns Em next ) 362.Op , Active 363.in -4 364.in -4 365.Bl -tag -width "bootmenu" 366.It Em ptn_number 367is the number of the partition. 368.It Em id_name 369is the name of the filesystem type or operating system that uses this partition. 370.It Em id_number 371is the number that identifies the partition type. 372169 decimal is used for 373.Nx 374partitions, 37515 decimal to create an extended partition 376and 0 to mark a partition as unused. 377Use 378.Nm 379.Fl l 380to list the known partition types. 381.It Em bootmenu 382is the menu prompt output by the interactive boot code for this partition. 383This line is omitted if the prompt is not defined. 384.It Xo 385.Em start , 386.Em size 387.Xc 388are the start address and size of the partition in sectors. 389.It Em MB 390is the size of the partition in megabytes. 391.It Xo 392.Em first , 393.Em next 394.Xc 395are the bounds of this partition displayed as cylinder/head/sector. 396If the partition starts (or ends) on a cylinder boundary the head and 397sector values are omitted. 398If 399.Fl v 400is not specified the start of extended partitions and the first partition 401on the disk are rounded down to include the mandatory red tape in the 402preceding track. 403.It Active 404is output if this is the active partition. 405.El 406.Pp 407If the 408.Fl v 409flag is given two additional lines are output for each partition: 410.in +4 411beg: cylinder 412.Em cylinder , 413head 414.Em head , 415sector 416.Em sector 417.br 418end: cylinder 419.Em cylinder , 420head 421.Em head , 422sector 423.Em sector 424.in -4 425.Bl -tag -width "bootmenu" 426.It Xo 427.Em "cylinder" , 428.Em "head" , 429.Em "sector" 430.Xc 431are the beginning or ending address of a partition. 432.Pp 433.Em "Note:" 434these numbers are read from the bootblock, so are the values calculated 435by a previous run of 436.Nm . 437.El 438.Sh NOTES 439This program is only available (and useful) on systems with PC-platform-style 440MBR partitioning. 441On 442.Nx 443this includes the following ports: amd64, arc, bebox, cobalt, hpcarm, 444hpcmips, hpcsh, i386, macppc, mvmeppc, netwinder, ofppc, playstation2, 445and prep. 446.Pp 447Traditionally the partition boundaries should be on cylinder boundaries 448using the BIOS geometry, all of the first track should be reserved 449for use by the BIOS. 450Although the BIOS geometry is typically different from the geometry 451reported by the drive, neither will match the actual physical geometry 452for modern disks (the actual geometry will vary across the disk). 453Keeping the partition boundaries on cylinder boundaries makes partitioning 454a driver easier as only relatively small numbers need be entered. 455.Pp 456The automatic calculation of the starting cylinder and 457other parameters uses 458a set of figures that represent what the BIOS thinks is the 459geometry of the drive. 460The default values should be correct for the system on which 461.Nm 462is run, however if you move the disk to a different system the 463BIOS of that system might use a different geometry translation. 464.Pp 465If you run the equivalent of 466.Nm 467on a different operating system then the 468.Ar bootmenu 469strings associated with extended partitions may be lost. 470.Pp 471Editing an existing partition is risky, and may cause you to 472lose all the data in that partition. 473.Pp 474You should run this program interactively once or twice to see how it works. 475This is completely safe as long as you answer the last question in the negative. 476You can also specify 477.Fl w Ar file 478to write the output to a file and later specify 479.Fl r Ar file 480to read back the updated information. 481This can be done without having write access to the disk volume. 482.Sh FILES 483.Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact 484.It Pa /usr/mdec/mbr 485Default location of i386 bootcode 486.It Pa /usr/mdec/mbr_bootsel 487Default location of i386 bootselect code 488.It Pa /usr/mdec/mbr_ext 489Default location of i386 bootselect for extended partitions 490.El 491.Sh SEE ALSO 492.Xr disktab 5 , 493.Xr disklabel 8 , 494.Xr mbr 8 , 495.Xr mbrlabel 8 496.Sh BUGS 497The word 498.Sq partition 499is used to mean both an MBR partition and a 500.Nx 501partition, sometimes in the same sentence. 502.Pp 503There are subtleties that the program detects that are not explained in 504this manual page. 505