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