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