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