1.\" $FreeBSD$ 2.\" 3.Dd October 1, 2013 4.Dt FDISK 8 5.Os 6.Sh NAME 7.Nm fdisk 8.Nd PC slice table maintenance utility 9.Sh SYNOPSIS 10.Nm 11.Op Fl BIaipqstu 12.Op Fl b Ar bootcode 13.Op Fl 1234 14.Op Ar disk 15.Nm 16.Fl f Ar configfile 17.Op Fl itv 18.Op Ar disk 19.Sh PROLOGUE 20In order for the BIOS to boot the kernel, 21certain conventions must be adhered to. 22Sector 0 of the disk must contain boot code, 23a slice table, 24and a magic number. 25BIOS slices can be used to break the disk up into several pieces. 26The BIOS brings in sector 0 and verifies the magic number. 27The sector 280 boot code then searches the slice table to determine which 29slice is marked 30.Dq active . 31This boot code then brings in the bootstrap from the 32active slice and, if marked bootable, runs it. 33Under 34.Tn DOS , 35you can have one or more slices with one active. 36The 37.Tn DOS 38.Nm 39utility can be used to divide space on the disk into slices and set one 40active. 41.Sh DESCRIPTION 42.Bf -symbolic 43This command is obsolete. 44Users are advised to use 45.Xr gpart 8 46instead. 47.Ef 48.Pp 49The 50.Fx 51utility, 52.Nm , 53serves a similar purpose to the 54.Tn DOS 55utility. 56The first form is used to 57display slice information or to interactively edit the slice 58table. 59The second is used to write a slice table using a 60.Ar configfile , 61and is designed to be used by other scripts/programs. 62.Pp 63Options are: 64.Bl -tag -width indent 65.It Fl a 66Change the active slice only. 67Ignored if 68.Fl f 69is given. 70.It Fl b Ar bootcode 71Get the boot code from the file 72.Ar bootcode . 73Default is 74.Pa /boot/mbr . 75.It Fl B 76Reinitialize the boot code contained in sector 0 of the disk. 77Ignored if 78.Fl f 79is given. 80.It Fl f Ar configfile 81Set slice values using the file 82.Ar configfile . 83The 84.Ar configfile 85only modifies explicitly specified slices, unless 86.Fl i 87is also given, in which case all existing slices are deleted (marked 88as 89.Dq unused ) 90before the 91.Ar configfile 92is read. 93The 94.Ar configfile 95can be 96.Sq Fl , 97in which case standard input is read. 98See 99.Sx CONFIGURATION FILE , 100below, for file syntax. 101.Pp 102.Em WARNING : 103when 104.Fl f 105is used, you are not asked if you really want to write the slices 106table (as you are in the interactive mode). 107Use with caution! 108.It Fl i 109Initialize sector 0 of the disk. 110Existing slice entries will be cleared 111(marked as unused) before editing. 112(Compare with 113.Fl u . ) 114.It Fl I 115Initialize sector 0 slice table 116for one 117.Fx 118slice covering the entire disk. 119.It Fl p 120Print a slice table in 121.Nm 122configuration file format and exit; see 123.Sx CONFIGURATION FILE , 124below. 125.It Fl q 126Be quiet. 127Benign warnings (such as "GEOM not found") are suppressed. 128.It Fl s 129Print summary information and exit. 130.It Fl t 131Test mode; do not write slice values. 132Generally used with the 133.Fl f 134option to see what would be written to the slice table. 135Implies 136.Fl v . 137.It Fl u 138Update (edit) the disk's sector 0 slice table. 139Ignored if 140.Fl f 141is given. 142.It Fl v 143Be verbose. 144When 145.Fl f 146is used, 147.Nm 148prints out the slice table that is written to the disk. 149.It Fl 1234 150Operate on a single slice table entry only. 151Ignored if 152.Fl f 153is given. 154.El 155.Pp 156The final disk name can be provided as a 157.Dq bare 158disk name only, e.g.\& 159.Pa da0 , 160or as a full pathname. 161If omitted, 162.Nm 163tries to figure out the default disk device name from the 164mounted root device. 165.Pp 166When called with no arguments, it prints the sector 0 slice table. 167An example follows: 168.Bd -literal 169 ******* Working on device /dev/ada0 ******* 170 parameters extracted from in-core disklabel are: 171 cylinders=769 heads=15 sectors/track=33 (495 blks/cyl) 172 173 parameters to be used for BIOS calculations are: 174 cylinders=769 heads=15 sectors/track=33 (495 blks/cyl) 175 176 Warning: BIOS sector numbering starts with sector 1 177 Information from DOS bootblock is: 178 The data for partition 1 is: 179 sysid 165,(FreeBSD/NetBSD/386BSD) 180 start 495, size 380160 (185 Meg), flag 0 181 beg: cyl 1/ sector 1/ head 0; 182 end: cyl 768/ sector 33/ head 14 183 The data for partition 2 is: 184 sysid 164,(unknown) 185 start 378180, size 2475 (1 Meg), flag 0 186 beg: cyl 764/ sector 1/ head 0; 187 end: cyl 768/ sector 33/ head 14 188 The data for partition 3 is: 189 <UNUSED> 190 The data for partition 4 is: 191 sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach) 192 start 380656, size 224234 (109 Meg), flag 80 193 beg: cyl 769/ sector 2/ head 0; 194 end: cyl 197/ sector 33/ head 14 195.Ed 196.Pp 197The disk is divided into three slices that happen to fill the disk. 198The second slice overlaps the end of the first. 199(Used for debugging purposes.) 200.Bl -tag -width ".Em cyl , sector No and Em head" 201.It Em sysid 202is used to label the slice. 203.Fx 204reserves the 205magic number 165 decimal (A5 in hex). 206.It Xo 207.Em start 208and 209.Em size 210.Xc 211fields provide the start address 212and size of a slice in sectors. 213.It Em "flag 80" 214specifies that this is the active slice. 215.It Xo 216.Em cyl , sector 217and 218.Em head 219.Xc 220fields are used to specify the beginning and end addresses of the slice. 221.El 222.Pp 223.Em Note : 224these numbers are calculated using BIOS's understanding of the disk geometry 225and saved in the bootblock. 226.Pp 227The 228.Fl i 229and 230.Fl u 231flags are used to indicate that the slice data is to be updated. 232Unless the 233.Fl f 234option is also given, 235.Nm 236will enter a conversational mode. 237In this mode, no changes will be written to disk unless you explicitly tell 238.Nm 239to. 240.Pp 241The 242.Nm 243utility will display each slice and ask whether you want to edit it. 244If you say yes, 245.Nm 246will step through each field, show you the old value, 247and ask you for a new one. 248When you are done with the slice, 249.Nm 250will display it and ask you whether it is correct. 251It will then proceed to the next entry. 252.Pp 253Getting the 254.Em cyl , sector , 255and 256.Em head 257fields correct is tricky, so by default, 258they will be calculated for you; 259you can specify them if you choose to though. 260.Pp 261After all the slices are processed, 262you are given the option to change the 263.Dq active 264slice. 265Finally, when all the new data for sector 0 has been accumulated, 266you are asked to confirm whether you really want to rewrite it. 267.Pp 268The difference between the 269.Fl u 270and 271.Fl i 272flags is that 273the 274.Fl u 275flag edits (updates) the existing slice parameters 276while the 277.Fl i 278flag is used to 279.Dq initialize 280them (old values will be ignored); 281if you edit the first slice, 282.Fl i 283will also set it up to use the whole disk for 284.Fx 285and make it active. 286.Sh NOTES 287The automatic calculation of starting cylinder etc.\& uses 288a set of figures that represent what the BIOS thinks the 289geometry of the drive is. 290These figures are taken from the in-core disklabel by default, 291but 292.Nm 293initially gives you an opportunity to change them. 294This allows you to create a bootblock that can work with drives 295that use geometry translation under the BIOS. 296.Pp 297If you hand craft your disk layout, 298please make sure that the 299.Fx 300slice starts on a cylinder boundary. 301.Pp 302Editing an existing slice will most likely result in the loss of 303all data in that slice. 304.Pp 305You should run 306.Nm 307interactively once or twice to see how it works. 308This is completely safe as long as you answer the last question 309in the negative. 310There are subtleties that 311.Nm 312detects that are not fully explained in this manual page. 313.Sh CONFIGURATION FILE 314When the 315.Fl f 316option is given, a disk's slice table can be written using values 317from a 318.Ar configfile . 319The syntax of this file is very simple; 320each line is either a comment or a specification, as follows: 321.Bl -tag -width indent 322.It Ic # Ar comment ... 323Lines beginning with a 324.Ic # 325are comments and are ignored. 326.It Ic g Ar spec1 spec2 spec3 327Set the BIOS geometry used in slice calculations. 328There must be 329three values specified, with a letter preceding each number: 330.Bl -tag -width indent 331.It Cm c Ns Ar num 332Set the number of cylinders to 333.Ar num . 334.It Cm h Ns Ar num 335Set the number of heads to 336.Ar num . 337.It Cm s Ns Ar num 338Set the number of sectors/track to 339.Ar num . 340.El 341.Pp 342These specs can occur in any order, as the leading letter determines 343which value is which; however, all three must be specified. 344.Pp 345This line must occur before any lines that specify slice 346information. 347.Pp 348It is an error if the following is not true: 349.Bd -literal -offset indent 3501 <= number of cylinders 3511 <= number of heads <= 256 3521 <= number of sectors/track < 64 353.Ed 354.Pp 355The number of cylinders should be less than or equal to 1024, but this 356is not enforced, although a warning will be printed. 357Note that bootable 358.Fx 359slices (the 360.Dq Pa / 361file system) must lie completely within the 362first 1024 cylinders; if this is not true, booting may fail. 363Non-bootable slices do not have this restriction. 364.Pp 365Example (all of these are equivalent), for a disk with 1019 cylinders, 36639 heads, and 63 sectors: 367.Bd -literal -offset indent 368g c1019 h39 s63 369g h39 c1019 s63 370g s63 h39 c1019 371.Ed 372.It Ic p Ar slice type start length 373Set the slice given by 374.Ar slice 375(1-4) to type 376.Ar type , 377starting at sector 378.Ar start 379for 380.Ar length 381sectors. 382If the 383.Ar start 384or 385.Ar length 386is suffixed with a 387.Em K , 388.Em M 389or 390.Em G , 391it is taken as a 392.Em Kilobyte , 393.Em Megabyte 394or 395.Em Gigabyte 396measurement respectively. 397If the 398.Ar start 399is given as 400.Qq * 401it is set to the value of the previous partition end. 402If the 403.Ar length 404is given as 405.Qq * 406the partition end is set to the end of the disk. 407.Pp 408Only those slices explicitly mentioned by these lines are modified; 409any slice not referenced by a 410.Ic p 411line will not be modified. 412However, if an invalid slice table is present, or the 413.Fl i 414option is specified, all existing slice entries will be cleared 415(marked as unused), and these 416.Ic p 417lines will have to be used to 418explicitly set slice information. 419If multiple slices need to be 420set, multiple 421.Ic p 422lines must be specified; one for each slice. 423.Pp 424These slice lines must occur after any geometry specification lines, 425if one is present. 426.Pp 427The 428.Ar type 429is 165 for 430.Fx 431slices. 432Specifying a slice type of zero is 433the same as clearing the slice and marking it as unused; however, 434dummy values (such as 435.Dq 0 ) 436must still be specified for 437.Ar start 438and 439.Ar length . 440.Pp 441Note: the start offset will be rounded upwards to a head boundary if 442necessary, and the end offset will be rounded downwards to a cylinder 443boundary if necessary. 444.Pp 445Example: to clear slice 4 and mark it as unused: 446.Pp 447.Dl "p 4 0 0 0" 448.Pp 449Example: to set slice 1 to a 450.Fx 451slice, starting at sector 1 452for 2503871 sectors (note: these numbers will be rounded upwards and 453downwards to correspond to head and cylinder boundaries): 454.Pp 455.Dl "p 1 165 1 2503871" 456.Pp 457Example: to set slices 1, 2 and 4 to 458.Fx 459slices, the first being 2 Gigabytes, the second being 10 Gigabytes and the 460forth being the remainder of the disk (again, numbers will be rounded 461appropriately): 462.Pp 463.Dl "p 1 165 63 2G" 464.Dl "p 2 165 * 10G" 465.Dl "p 3 0 0 0" 466.Dl "p 4 165 * *" 467.It Ic a Ar slice 468Make 469.Ar slice 470the active slice. 471Can occur anywhere in the config file, but only 472one must be present. 473.Pp 474Example: to make slice 1 the active slice: 475.Pp 476.Dl "a 1" 477.El 478.Sh FILES 479.Bl -tag -width ".Pa /boot/mbr" -compact 480.It Pa /boot/mbr 481The default boot code. 482.El 483.Sh SEE ALSO 484.Xr boot0cfg 8 , 485.Xr bsdlabel 8 , 486.Xr gpart 8 , 487.Xr newfs 8 488.Sh BUGS 489The default boot code will not necessarily handle all slice types 490correctly, in particular those introduced since 491.Tn MS-DOS 4926.x. 493.Pp 494The entire utility should be made more user-friendly. 495.Pp 496Most users new to 497.Fx 498do not understand the difference between 499.Dq slice 500and 501.Dq partition , 502causing difficulty to adjust. 503.Pp 504You cannot use this command to completely dedicate a disk to 505.Fx . 506The 507.Xr bsdlabel 8 508command must be used for this. 509