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