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