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 fdisk 11.Op Fl Baeitu 12.Op Fl b Ar bootcode 13.Op Fl 1234 14.Op Ar disk 15.Bl -tag -width time 16.Nm fdisk 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.Bx Free 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 e 66Initialize the contents of sector 0 with one FreeBSD slice covering the entire disk. 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 Ns : 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 t 97Test mode; do not write partition values. Generally used with the 98.Fl f 99option to see what would be written to the partition table. Implies 100.Fl v . 101.It Fl u 102Is used for updating (editing) sector 0 of the disk. Ignored if 103.Fl f 104is given. 105.It Fl v 106Be verbose. When 107.Fl f 108is used, 109.Nm 110prints out the partition table that is written to the disk. 111.It Fl 1234 112Operate on a single fdisk entry only. Ignored if 113.Fl f 114is given. 115.El 116.Pp 117The final disk name can be provided as a 118.Sq bare 119disk name only, e.g. 120.Ql da0 , 121or as a fully qualified device node under 122.Pa /dev . 123If omitted, the disks 124.Ql wd0 , 125.Ql da0 , 126and 127.Ql od0 128are being searched in that order, until one is 129being found responding. 130.Pp 131When called with no arguments, it prints the sector 0 partition table. 132An example follows: 133 134.Bd -literal 135 ******* Working on device /dev/rwd0 ******* 136 parameters extracted from in-core disklabel are: 137 cylinders=769 heads=15 sectors/track=33 (495 blks/cyl) 138 139 parameters to be used for BIOS calculations are: 140 cylinders=769 heads=15 sectors/track=33 (495 blks/cyl) 141 142 Warning: BIOS sector numbering starts with sector 1 143 Information from DOS bootblock is: 144 The data for partition 1 is: 145 sysid 165,(FreeBSD/NetBSD/386BSD) 146 start 495, size 380160 (185 Meg), flag 0 147 beg: cyl 1/ sector 1/ head 0; 148 end: cyl 768/ sector 33/ head 14 149 The data for partition 2 is: 150 sysid 164,(unknown) 151 start 378180, size 2475 (1 Meg), flag 0 152 beg: cyl 764/ sector 1/ head 0; 153 end: cyl 768/ sector 33/ head 14 154 The data for partition 3 is: 155 <UNUSED> 156 The data for partition 4 is: 157 sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach) 158 start 380656, size 224234 (109 Meg), flag 80 159 beg: cyl 769/ sector 2/ head 0; 160 end: cyl 197/ sector 33/ head 14 161.Ed 162.Pp 163The disk is divided into three partitions that happen to fill the disk. 164The second partition overlaps the end of the first. 165(Used for debugging purposes) 166.Bl -tag -width "cyl, sector and head" 167.It Em "sysid" 168is used to label the partition. 169.Bx Free 170reserves the 171magic number 165 decimal (A5 in hex). 172.It Em "start and size" 173fields provide the start address 174and size of a partition in sectors. 175.It Em "flag 80" 176specifies that this is the active partition. 177.It Em "cyl, sector and head" 178fields are used to specify the beginning address 179and end address for the partition. 180.It Em "Note:" 181these numbers are calculated using BIOS's understanding of the disk geometry 182and saved in the bootblock. 183.El 184.Pp 185The flags 186.Fl i 187or 188.Fl u 189are used to indicate that the partition data is to be updated, unless the 190.Fl f 191option is used. If the 192.Fl f 193option is not used, the 194.Nm 195program will enter a conversational mode. 196This mode is designed not to change any data unless you explicitly tell it to. 197.Nm Fdisk 198selects defaults for its questions to guarantee the above behavior. 199.Pp 200It displays each partition 201and ask if you want to edit it. 202If you say yes, 203it will step through each field showing the old value 204and asking for a new one. 205When you are done with a partition, 206.Nm 207will display it and ask if it is correct. 208.Nm Fdisk 209will then proceed to the next entry. 210.Pp 211Getting the 212.Em cyl, sector, 213and 214.Em head 215fields correct is tricky. 216So by default, 217they will be calculated for you; 218you can specify them if you choose. 219.Pp 220After all the partitions are processed, 221you are given the option to change the 222.Em active 223partition. 224Finally, 225when the all the data for the first sector has been accumulated, 226you are asked if you really want to rewrite sector 0. 227Only if you answer yes, 228will the data be written to disk. 229.Pp 230The difference between the 231.Fl u 232flag and 233.Fl i 234flag is that 235the 236.Fl u 237flag just edits the fields as they appear on the disk. 238While the 239.Fl i 240flag is used to "initialize" sector 0; 241it will setup the last BIOS partition to use the whole disk for 242.Bx Free ; 243and make it active. 244.Sh NOTES 245The automatic calculation of starting cylinder etc. uses 246a set of figures that represent what the BIOS thinks is the 247geometry of the drive. 248These figures are by default taken from the incore disklabel, 249but the program initially gives you an opportunity to change them. 250This allows the user to create a bootblock that can work with drives 251that use geometry translation under the BIOS. 252.Pp 253If you hand craft your disk layout, 254please make sure that the 255.Bx Free 256partition starts on a cylinder boundary. 257A number of decisions made later may assume this. 258(This might not be necessary later.) 259.Pp 260Editing an existing partition will most likely cause you to 261lose all the data in that partition. 262.Pp 263You should run this program interactively once or twice to see how it 264works. This is completely safe as long as you answer the last question 265in the negative. There are subtleties that the program detects that are 266not fully explained in this manual page. 267.Sh CONFIGURATION FILE 268When the 269.Fl f 270option is given, a disk's partition table can be written using values 271from a 272.Ar configfile . 273The syntax of this file is very simple. Each line is either a comment or 274a specification, and whitespace (except for newlines) are ignored: 275.Bl -tag -width Ds 276.It Xo 277.Ic # 278.No Ar comment ... 279.Xc 280Lines beginning with a "#" are comments and are ignored. 281.It Xo 282.Ic g 283.No Ar spec1 284.No Ar spec2 285.No Ar spec3 286.Xc 287Set the BIOS geometry used in partition calculations. There must be 288three values specified, with a letter preceding each number: 289.Bl -tag -width Ds 290.Sm off 291.It Cm c No Ar num 292.Sm on 293Set the number of cylinders to 294.Ar num . 295.Sm off 296.It Cm h No Ar num 297.Sm on 298Set the number of heads to 299.Ar num . 300.Sm off 301.It Cm s No Ar num 302.Sm on 303Set the number of sectors/track to 304.Ar num . 305.El 306.Pp 307These specs can occur in any order, as the leading letter determines 308which value is which; however, all three must be specified. 309.Pp 310This line must occur before any lines that specify partition 311information. 312.Pp 313It is an error if the following is not true: 314.Pp 315.nf 316 1 <= number of cylinders 317 1 <= number of heads <= 256 318 1 <= number of sectors/track < 64 319.fi 320.Pp 321The number of cylinders should be less than or equal to 1024, but this 322is not enforced, although a warning will be output. Note that bootable 323.Bx Free 324partitions (the "/" filesystem) must lie completely within the 325first 1024 cylinders; if this is not true, booting may fail. 326Non-bootable partitions do not have this restriction. 327.Pp 328Example (all of these are equivalent), for a disk with 1019 cylinders, 32939 heads, and 63 sectors: 330.Pp 331.nf 332 g c1019 h39 s63 333 g h39 c1019 s63 334 g s63 h39 c1019 335.fi 336.It Xo 337.Ic p 338.No Ar partition 339.No Ar type 340.No Ar start 341.No 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.Bx Free 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.Pp 382.nf 383 p 4 0 0 0 384.fi 385.Pp 386Example: to set partition 1 to a 387.Bx Free 388partition, starting at sector 1 389for 2503871 sectors (note: these numbers will be rounded upwards and 390downwards to correspond to head and cylinder boundaries): 391.Pp 392.nf 393 p 1 165 1 2503871 394.fi 395.It Xo 396.Ic a 397.No 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.Pp 406.nf 407 a 1 408.fi 409 410.El 411.Pp 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.Bx Free . 433The 434.Xr disklabel 8 435command must be used for this. 436