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