1.\" $FreeBSD: src/sbin/i386/fdisk/fdisk.8,v 1.17.2.11 2002/04/25 16:25:12 trhodes Exp $ 2.\" 3.Dd September 29, 2016 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 226magic number 165 decimal (A5 in hex). 227.It Em start No and Em size 228fields provide the start address 229and size of a slice in sectors. 230.It Em "flag 80" 231specifies that this is the active slice. 232.It Em cyl , sector No and Em head 233fields are used to specify the beginning and end addresses of the slice. 234.It Em Note : 235these numbers are calculated using BIOS's understanding of the disk geometry 236and saved in the bootblock. 237.El 238.Pp 239The 240.Fl i 241and 242.Fl u 243flags are used to indicate that the slice data is to be updated. 244Unless the 245.Fl f 246option is also given, 247.Nm 248will enter a conversational mode. 249In this mode, no changes will be written to disk unless you explicitly tell 250.Nm 251to. 252.Pp 253.Nm Fdisk 254will display each slice and ask whether you want to edit it. 255If you say yes, 256.Nm 257will step through each field, show you the old value, 258and ask you for a new one. 259When you are done with the slice, 260.Nm 261will display it and ask you whether it is correct. 262.Nm Fdisk 263will then proceed to the next entry. 264.Pp 265Getting the 266.Em cyl , sector , 267and 268.Em head 269fields correct is tricky, so by default, 270they will be calculated for you; 271you can specify them if you choose to though. 272.Pp 273After all the slices are processed, 274you are given the option to change the 275.Em active 276slice. 277Finally, when all the new data for sector 0 has been accumulated, 278you are asked to confirm whether you really want to rewrite it. 279.Pp 280The difference between the 281.Fl u 282and 283.Fl i 284flags is that 285the 286.Fl u 287flag just edits (updates) the fields as they appear on the disk, 288while the 289.Fl i 290flag is used to 291.Dq initialize 292sector 0; 293it will set up the last BIOS slice to use the whole disk for 294.Dx 295and make it active. 296.Sh NOTES 297The automatic calculation of starting cylinder etc.\& uses 298a set of figures that represent what the BIOS thinks the 299geometry of the drive is. 300These figures are taken from the in-core disklabel by default, 301but 302.Nm 303initially gives you an opportunity to change them. 304This allows you to create a bootblock that can work with drives 305that use geometry translation under the BIOS. 306.Pp 307If you hand craft your disk layout, 308please make sure that the 309.Dx 310slice starts on a cylinder boundary. 311A number of decisions made later may assume this. 312(This might not be necessary later.) 313.Pp 314Editing an existing slice will most likely result in the loss of 315all data in that slice. 316.Pp 317You should run 318.Nm 319interactively once or twice to see how it works. 320This is completely safe as long as you answer the last question 321in the negative. 322There are subtleties that 323.Nm 324detects that are not fully explained in this manual page. 325.Sh CONFIGURATION FILE 326When the 327.Fl f 328option is given, a disk's slice table can be written using values 329from a 330.Ar configfile . 331The syntax of this file is very simple; 332each line is either a comment or a specification, as follows: 333.Bl -tag -width Ds 334.It Xo 335.Ic # 336.Ar comment ... 337.Xc 338Lines beginning with a 339.Sq # 340are comments and are ignored. 341.It Xo 342.Ic g 343.Ar spec1 344.Ar spec2 345.Ar spec3 346.Xc 347Set the BIOS geometry used in slice calculations. 348There must be 349three values specified, with a letter preceding each number: 350.Bl -tag -width Ds 351.Sm off 352.It Cm c Ar num 353.Sm on 354Set the number of cylinders to 355.Ar num . 356.Sm off 357.It Cm h Ar num 358.Sm on 359Set the number of heads to 360.Ar num . 361.Sm off 362.It Cm s Ar num 363.Sm on 364Set the number of sectors/track to 365.Ar num . 366.El 367.Pp 368These specs can occur in any order, as the leading letter determines 369which value is which; however, all three must be specified. 370.Pp 371This line must occur before any lines that specify slice 372information. 373.Pp 374It is an error if the following is not true: 375.Bd -literal -offset indent 3761 \(<= number of cylinders 3771 \(<= number of heads \(<= 256 3781 \(<= number of sectors/track < 64 379.Ed 380.Pp 381The number of cylinders should be less than or equal to 1024, but this 382is not enforced, although a warning will be printed. 383Note that a bootable 384.Dx 385slice (the 386.Dq Pa / 387file system) must lie completely within the 388first 1024 cylinders, if 389.Dq packet 390mode isn't used, see 391.Xr boot0cfg 8 ; 392if this is not true, booting may fail. 393Non-bootable slices do not have this restriction. 394.Pp 395Example (all of these are equivalent), for a disk with 1019 cylinders, 39639 heads, and 63 sectors: 397.Bd -literal -offset indent 398g c1019 h39 s63 399g h39 c1019 s63 400g s63 h39 c1019 401.Ed 402.It Xo 403.Ic p 404.Ar slice 405.Ar type 406.Ar start 407.Ar length 408.Xc 409Set the slice given by 410.Ar slice 411(1-4) to type 412.Ar type , 413starting at sector 414.Ar start 415for 416.Ar length 417sectors. 418.Pp 419Only those slices explicitly mentioned by these lines are modified; 420any slice not referenced by a 421.Cm p 422line will not be modified. 423However, if an invalid slice table is present, or the 424.Fl i 425option is specified, all existing slice entries will be cleared 426(marked as unused), and these 427.Cm p 428lines will have to be used to 429explicitly set slice information. 430If multiple slices need to be 431set, multiple 432.Cm p 433lines must be specified; one for each slice. 434.Pp 435These slice lines must occur after any geometry specification lines, 436if one is present. 437.Pp 438The 439.Ar type 440is 165 for 441.Dx 442slices. 443Specifying a slice type of zero is 444the same as clearing the slice and marking it as unused; however, 445dummy values (such as 446.Sq 0 ) 447must still be specified for 448.Ar start 449and 450.Ar length . 451.Pp 452Note: the start offset will be rounded upwards to a head boundary if 453necessary, and the end offset will be rounded downwards to a cylinder 454boundary if necessary. 455.Pp 456Example: to clear slice 4 and mark it as unused: 457.Bd -literal -offset indent 458p 4 0 0 0 459.Ed 460.Pp 461Example: to set slice 1 to a 462.Dx 463slice, starting at sector 1 464for 2503871 sectors (note: these numbers will be rounded upwards and 465downwards to correspond to head and cylinder boundaries): 466.Bd -literal -offset indent 467p 1 165 1 2503871 468.Ed 469.It Xo 470.Ic a 471.Ar slice 472.Xc 473Make 474.Ar slice 475the active slice. 476Can occur anywhere in the config file, but only 477one must be present. 478If no 479.Cm a 480line is present, all slices of the disk are made inactive. 481.Pp 482Example: to make slice 1 the active slice: 483.Bd -literal -offset indent 484a 1 485.Ed 486.El 487.Sh FILES 488.Bl -tag -width /boot/mbr -compact 489.It Pa /boot/mbr 490The default boot code 491.El 492.Sh COMPATIBILITY 493Due to the use of 32 bit to store the number of sectors in the MBR, 494.Nm 495can at most use 2^32 - 1 sectors. 496For the prevalent sector size of 512B this means a maximum of 2TB. 497Larger disks should be partitioned using 498.Xr gpt 8 . 499.Pp 500The MBR that 501.Nm 502manipulates, is used by many different OSs, but the exact requirements seems to differ, 503it can be a hassle to get multiple OSs to recognize the same MBR. 504Some OSs will require that slices are located at cylinder boundaries. 505.Sh SEE ALSO 506.Xr boot0cfg 8 , 507.Xr disklabel 8 , 508.Xr gpt 8 , 509.Xr newfs 8 510.Sh HISTORY 511A version of 512.Nm 513first appeared in the Mach Operating System. 514It was subsequently ported to 515.Bx 386 . 516.Sh AUTHORS 517.An -nosplit 518.Nm 519for Mach Operating System was written by 520.An Robert Baron Aq Mt rvb@cs.cmu.edu . 521It was ported to 522.Bx 386 523by 524.An Julian Elischer Aq Mt julian@tfs.com . 525.Sh BUGS 526Only slices s1-s4 527.Pq primary DOS partitions 528can be changed by 529.Nm , 530s5-s30 531.Pq slices in extended DOS partitions 532can't be changed by 533.Nm . 534.Pp 535The default boot code will not necessarily handle all slice types 536correctly, in particular those introduced since MS-DOS 6.x. 537.Pp 538The entire program should be made more user-friendly. 539.Pp 540Most users new to 541.Dx 542do not understand the difference between 543.Ar slice 544and 545.Ar partition 546causing difficulty to adjust. 547.Pp 548You cannot use this command to completely dedicate a disk to 549.Dx . 550The 551.Xr disklabel 8 552command must be used for this. 553