1.\" $FreeBSD: src/sbin/i386/fdisk/fdisk.8,v 1.17.2.11 2002/04/25 16:25:12 trhodes Exp $ 2.\" 3.Dd March 27, 2019 4.Dt FDISK 8 5.Os 6.Sh NAME 7.Nm fdisk 8.Nd PC slice table (MBR) maintenance program 9.Sh SYNOPSIS 10.Nm 11.Op Fl BCEIaistu 12.Op Fl b Ar bootcode 13.Op Fl p Ar diskimage 14.Op Fl 1234 15.Op Ar disk 16.Nm 17.Fl f Ar configfile 18.Op Fl itv 19.Op Ar disk 20.Sh PROLOGUE 21In order for the BIOS to boot the kernel, 22certain conventions must be adhered to. 23Sector 0 of the disk must contain an MBR, which contain boot code, 24a slice table, 25and a magic number. 26BIOS slices can be used to break the disk up into several pieces. 27.Dx 28slices are called partitions under DOS 29.Dq ( partition 30has another meaning under 31.Dx , 32see 33.Xr disklabel 8 ) . 34.Dx 35supports 30 MBR slices, s1-s4 will be DOS primary partitions, 36s5-s30 will be DOS partitions in extended DOS partitions. 37The BIOS brings in sector 0 and verifies the magic number. 38The sector 390 boot code then searches the slice table to determine which 40slice is marked 41.Em active . 42This boot code then brings in the bootstrap from the 43.Em active 44slice and, if marked bootable, runs it. 45Under DOS, 46you can have one or more slices with one 47.Em active . 48The DOS 49.Nm 50program can be used to divide space on the disk into slices and set one 51.Em active . 52.Sh DESCRIPTION 53The 54.Dx 55program, 56.Nm , 57serves a similar purpose to the DOS program. 58The first form is used to 59display slice information or to interactively edit the slice table. 60The second is used to write a slice table using a 61.Ar configfile 62and is designed to be used by other scripts/programs. 63.Pp 64Options are: 65.Bl -tag -width indent 66.It Fl a 67Change the active slice only. 68Ignored if 69.Fl f 70is given. 71.It Fl b Ar bootcode 72Get the boot code from the file 73.Ar bootcode . 74Default is 75.Pa /boot/mbr . 76.It Fl p Ar diskimage 77The disk image is specified as a normal file instead of as a device, 78which is useful when building emulated disks for vmware, bochs, etc.\& 79.It Fl B 80Reinitialize the boot code contained in sector 0 of the disk. 81Ignored if 82.Fl f 83is given. 84.It Fl C 85Set CHS fields to wrapped values. 86Normally the CHS fields for a slice are set to all 1's if they 87would otherwise wrap. 88This typically causes BIOSes to properly detect 89that the disk should be put in Large mode. 90This option may be needed on very old PCs. 91.It Fl E 92Use TRIM to erase the device/partition before creating the file system. 93The underlying device must have the TRIM sysctl enabled. 94Only devices that support TRIM will have such a sysctl option 95.Va ( kern.cam.da.X.trim_enabled ) . 96For use with the 97.Fl I 98or 99.Fl u 100option. 101.It Fl f Ar configfile 102Set slice values using the file 103.Ar configfile . 104The 105.Ar configfile 106always modifies existing slices, unless 107.Fl i 108is also given, in which case all existing slices are deleted (marked 109as 110.Dq unused ) 111before the 112.Ar configfile 113is read. 114The 115.Ar configfile 116can be 117.Sq - , 118in which case 119.Ar stdin 120is read. 121See 122.Sx CONFIGURATION FILE , 123below, for file syntax. 124.Pp 125.Em WARNING : 126when 127.Fl f 128is used, you are not asked if you really want to write the slices 129table (as you are in the interactive mode). 130Use with caution! 131.It Fl i 132Initialize sector 0 of the disk. 133This implies 134.Fl u , 135unless 136.Fl f 137is given. 138.It Fl I 139Initialize the contents of sector 0 140for one 141.Dx 142slice covering the entire disk. 143.It Fl s 144Print a summary of all slices on the disk and exit. 145All other options will be ignored. 146.It Fl t 147Test mode; do not write slice values. 148Generally used with the 149.Fl f 150option to see what would be written to the slice table. 151Implies 152.Fl v . 153.It Fl u 154Is used for updating (editing) sector 0 of the disk. 155Ignored if 156.Fl f 157is given. 158.It Fl v 159Be verbose. 160When 161.Fl f 162is used, 163.Nm 164prints out the slice table that is written to the disk. 165.It Fl 1234 166Operate on a single fdisk entry only. 167Ignored if 168.Fl f 169is given. 170.El 171.Pp 172The final disk name can be provided as a 173.Sq bare 174disk name only, e.g.\& 175.Pa da0 , 176or as a fully qualified device node under 177.Pa /dev . 178If omitted, the disks 179.Pa ad0 , 180.Pa da0 181and 182.Pa vkd0 183are searched in that order, until one is found to respond. 184.Pp 185When called without options, 186.Nm 187prints the sector 0 slice table. 188An example follows: 189.Bd -literal 190 ******* Working on device /dev/ad0 ******* 191 parameters extracted from in-core disklabel are: 192 cylinders=769 heads=15 sectors/track=33 (495 blks/cyl) 193 194 parameters to be used for BIOS calculations are: 195 cylinders=769 heads=15 sectors/track=33 (495 blks/cyl) 196 197 Warning: BIOS sector numbering starts with sector 1 198 Information from DOS bootblock is: 199 The data for partition 1 is: 200 sysid 165,(DragonFly/FreeBSD/NetBSD/386BSD) 201 start 495, size 380160 (185 Meg), flag 0 202 beg: cyl 1/ sector 1/ head 0; 203 end: cyl 768/ sector 33/ head 14 204 The data for partition 2 is: 205 sysid 164,(unknown) 206 start 378180, size 2475 (1 Meg), flag 0 207 beg: cyl 764/ sector 1/ head 0; 208 end: cyl 768/ sector 33/ head 14 209 The data for partition 3 is: 210 <UNUSED> 211 The data for partition 4 is: 212 sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach) 213 start 380656, size 224234 (109 Meg), flag 80 214 beg: cyl 769/ sector 2/ head 0; 215 end: cyl 197/ sector 33/ head 14 216.Ed 217.Pp 218The disk is divided into three slices that happen to fill the disk. 219The second slice overlaps the end of the first. 220(Used for debugging purposes.) 221.Bl -tag -width "cyl, sector and head" 222.It Em "sysid" 223is used to label the slice. 224.Dx 225reserves the magic number 108 decimal (6C in hexadecimal). 226.It Em start No and Em size 227fields provide the start address 228and size of a slice in sectors. 229.It Em "flag 80" 230specifies that this is the active slice. 231.It Em cyl , sector No and Em head 232fields are used to specify the beginning and end addresses of the slice. 233.It Em Note : 234these numbers are calculated using BIOS's understanding of the disk geometry 235and saved in the bootblock. 236.El 237.Pp 238The 239.Fl i 240and 241.Fl u 242flags are used to indicate that the slice data is to be updated. 243Unless the 244.Fl f 245option is also given, 246.Nm 247will enter a conversational mode. 248In this mode, no changes will be written to disk unless you explicitly tell 249.Nm 250to. 251.Pp 252.Nm Fdisk 253will display each slice and ask whether you want to edit it. 254If you say yes, 255.Nm 256will step through each field, show you the old value, 257and ask you for a new one. 258When you are done with the slice, 259.Nm 260will display it and ask you whether it is correct. 261.Nm Fdisk 262will then proceed to the next entry. 263.Pp 264Getting the 265.Em cyl , sector , 266and 267.Em head 268fields correct is tricky, so by default, 269they will be calculated for you; 270you can specify them if you choose to though. 271.Pp 272After all the slices are processed, 273you are given the option to change the 274.Em active 275slice. 276Finally, when all the new data for sector 0 has been accumulated, 277you are asked to confirm whether you really want to rewrite it. 278.Pp 279The difference between the 280.Fl u 281and 282.Fl i 283flags is that 284the 285.Fl u 286flag just edits (updates) the fields as they appear on the disk, 287while the 288.Fl i 289flag is used to 290.Dq initialize 291sector 0; 292it will set up the last BIOS slice to use the whole disk for 293.Dx 294and make it active. 295.Sh NOTES 296The automatic calculation of starting cylinder etc.\& uses 297a set of figures that represent what the BIOS thinks the 298geometry of the drive is. 299These figures are taken from the in-core disklabel by default, 300but 301.Nm 302initially gives you an opportunity to change them. 303This allows you to create a bootblock that can work with drives 304that use geometry translation under the BIOS. 305.Pp 306If you hand craft your disk layout, 307please make sure that the 308.Dx 309slice starts on a cylinder boundary. 310A number of decisions made later may assume this. 311(This might not be necessary later.) 312.Pp 313Editing an existing slice will most likely result in the loss of 314all data in that slice. 315.Pp 316You should run 317.Nm 318interactively once or twice to see how it works. 319This is completely safe as long as you answer the last question 320in the negative. 321There are subtleties that 322.Nm 323detects that are not fully explained in this manual page. 324.Sh CONFIGURATION FILE 325When the 326.Fl f 327option is given, a disk's slice table can be written using values 328from a 329.Ar configfile . 330The syntax of this file is very simple; 331each line is either a comment or a specification, as follows: 332.Bl -tag -width Ds 333.It Xo 334.Ic # 335.Ar comment ... 336.Xc 337Lines beginning with a 338.Sq # 339are comments and are ignored. 340.It Xo 341.Ic g 342.Ar spec1 343.Ar spec2 344.Ar spec3 345.Xc 346Set the BIOS geometry used in slice calculations. 347There must be 348three values specified, with a letter preceding each number: 349.Bl -tag -width Ds 350.Sm off 351.It Cm c Ar num 352.Sm on 353Set the number of cylinders to 354.Ar num . 355.Sm off 356.It Cm h Ar num 357.Sm on 358Set the number of heads to 359.Ar num . 360.Sm off 361.It Cm s Ar num 362.Sm on 363Set the number of sectors/track to 364.Ar num . 365.El 366.Pp 367These specs can occur in any order, as the leading letter determines 368which value is which; however, all three must be specified. 369.Pp 370This line must occur before any lines that specify slice 371information. 372.Pp 373It is an error if the following is not true: 374.Bd -literal -offset indent 3751 \(<= number of cylinders 3761 \(<= number of heads \(<= 256 3771 \(<= number of sectors/track < 64 378.Ed 379.Pp 380The number of cylinders should be less than or equal to 1024, but this 381is not enforced, although a warning will be printed. 382Note that a bootable 383.Dx 384slice (the 385.Dq Pa / 386file system) must lie completely within the 387first 1024 cylinders, if 388.Dq packet 389mode isn't used, see 390.Xr boot0cfg 8 ; 391if this is not true, booting may fail. 392Non-bootable slices do not have this restriction. 393.Pp 394Example (all of these are equivalent), for a disk with 1019 cylinders, 39539 heads, and 63 sectors: 396.Bd -literal -offset indent 397g c1019 h39 s63 398g h39 c1019 s63 399g s63 h39 c1019 400.Ed 401.It Xo 402.Ic p 403.Ar slice 404.Ar type 405.Ar start 406.Ar length 407.Xc 408Set the slice given by 409.Ar slice 410(1-4) to type 411.Ar type , 412starting at sector 413.Ar start 414for 415.Ar length 416sectors. 417.Pp 418Only those slices explicitly mentioned by these lines are modified; 419any slice not referenced by a 420.Cm p 421line will not be modified. 422However, if an invalid slice table is present, or the 423.Fl i 424option is specified, all existing slice entries will be cleared 425(marked as unused), and these 426.Cm p 427lines will have to be used to 428explicitly set slice information. 429If multiple slices need to be 430set, multiple 431.Cm p 432lines must be specified; one for each slice. 433.Pp 434These slice lines must occur after any geometry specification lines, 435if one is present. 436.Pp 437The 438.Ar type 439is 108 for 440.Dx 441slices. 442Specifying a slice type of zero is 443the same as clearing the slice and marking it as unused; however, 444dummy values (such as 445.Sq 0 ) 446must still be specified for 447.Ar start 448and 449.Ar length . 450.Pp 451Note: the start offset will be rounded upwards to a head boundary if 452necessary, and the end offset will be rounded downwards to a cylinder 453boundary if necessary. 454.Pp 455Example: to clear slice 4 and mark it as unused: 456.Bd -literal -offset indent 457p 4 0 0 0 458.Ed 459.Pp 460Example: to set slice 1 to a 461.Dx 462slice, starting at sector 1 463for 2503871 sectors (note: these numbers will be rounded upwards and 464downwards to correspond to head and cylinder boundaries): 465.Bd -literal -offset indent 466p 1 108 1 2503871 467.Ed 468.It Xo 469.Ic a 470.Ar slice 471.Xc 472Make 473.Ar slice 474the active slice. 475Can occur anywhere in the config file, but only 476one must be present. 477If no 478.Cm a 479line is present, all slices of the disk are made inactive. 480.Pp 481Example: to make slice 1 the active slice: 482.Bd -literal -offset indent 483a 1 484.Ed 485.El 486.Sh FILES 487.Bl -tag -width /boot/mbr -compact 488.It Pa /boot/mbr 489The default boot code 490.El 491.Sh COMPATIBILITY 492Due to the use of 32 bit to store the number of sectors in the MBR, 493.Nm 494can at most use 2^32 - 1 sectors. 495For the prevalent sector size of 512B this means a maximum of 2TB. 496Larger disks should be partitioned using 497.Xr gpt 8 . 498.Pp 499The MBR that 500.Nm 501manipulates, is used by many different OSs, but the exact requirements seems to differ, 502it can be a hassle to get multiple OSs to recognize the same MBR. 503Some OSs will require that slices are located at cylinder boundaries. 504.Sh SEE ALSO 505.Xr boot0cfg 8 , 506.Xr disklabel 8 , 507.Xr gpt 8 , 508.Xr newfs 8 509.Sh HISTORY 510A version of 511.Nm 512first appeared in the Mach Operating System. 513It was subsequently ported to 514.Bx 386 . 515.Sh AUTHORS 516.An -nosplit 517.Nm 518for Mach Operating System was written by 519.An Robert Baron Aq Mt rvb@cs.cmu.edu . 520It was ported to 521.Bx 386 522by 523.An Julian Elischer Aq Mt julian@tfs.com . 524.Sh BUGS 525Only slices s1-s4 526.Pq primary DOS partitions 527can be changed by 528.Nm , 529s5-s30 530.Pq slices in extended DOS partitions 531can't be changed by 532.Nm . 533.Pp 534The default boot code will not necessarily handle all slice types 535correctly, in particular those introduced since MS-DOS 6.x. 536.Pp 537The entire program should be made more user-friendly. 538.Pp 539Most users new to 540.Dx 541do not understand the difference between 542.Ar slice 543and 544.Ar partition 545causing difficulty to adjust. 546.Pp 547You cannot use this command to completely dedicate a disk to 548.Dx . 549The 550.Xr disklabel 8 551command must be used for this. 552