1.\" $NetBSD: fdisk.8,v 1.30 2002/03/26 23:56:05 christos Exp $ 2.\" 3.Dd December 19, 2000 4.Dt FDISK 8 5.Os 6.Sh NAME 7.Nm fdisk 8.Nd DOS partition maintenance program 9.Sh SYNOPSIS 10.Nm "" 11.Op Fl aiufBS 12.Bk -words 13.Op Fl 0 | 1 | 2 | 3 14.Ek 15.Bk -words 16.Op Fl b Ar cylinders/heads/sectors 17.Ek 18.Bk -words 19.Op Fl s Ar id/start/size 20.Ek 21.Bk -words 22.Op Fl c Ar bootcode 23.Ek 24.Bk -words 25.Op Ar device 26.Ek 27.Sh DESCRIPTION 28In order for the BIOS to boot the kernel, certain conventions must be 29adhered to. 30Sector 0 of the disk must contain boot code, a partition table, and a 31magic number. 32Newer BIOS programs want the entire first track reserved. 33BIOS partitions can be used to break the disk up into several pieces. 34The BIOS brings in sector 0, verifies the magic number, and begins 35executing the code at the first byte. 36This code in turn searches the DOS partition table for an `active' 37partition. 38If one is found, the boot block from that partition is loaded and replaces 39the original boot block. 40Under DOS, you could have one or more partitions with one active. 41The DOS 42.Nm 43program can be used to divide space on the disk into partitions and set 44one active. 45.Pp 46The 47.Nx 48program 49.Nm 50serves a similar purpose to the DOS program. 51When called with no arguments, it prints the sector 0 partition table. 52An example follows: 53.Bd -literal 54 NetBSD disklabel disk geometry: 55 cylinders: 769 heads: 15 sectors/track: 33 (495 sectors/cylinder) 56 57 BIOS geometry: 58 cylinders: 769 heads: 15 sectors/track: 33 (495 sectors/cylinder) 59 60 Partition table: 61 0: sysid 169 (NetBSD) 62 start 495, size 380160 (185 MB), flag 0 63 beg: cylinder 1, head 0, sector 1 64 end: cylinder 768, head 14, sector 33 65 1: sysid 164 (reserved) 66 start 378180, size 2475 (1 MB), flag 0 67 beg: cylinder 764, head 0, sector 1 68 end: cylinder 768, head 14, sector 33 69 2: \*[Lt]UNUSED\*[Gt] 70 3: sysid 99 (GNU HURD or Mach or Sys V/386 (such as ISC UNIX)) 71 start 380656, size 224234 (109 MB), flag 80 72 beg: cylinder 769, head 0, sector 2 73 end: cylinder 197, head 14, sector 33 74.Ed 75.Pp 76This example disk is divided into three partitions that happen to fill the 77disk. 78The second partition overlaps the end of the first 79.Po 80used for debugging purposes 81.Pc . 82.Pp 83The various fields in each partition are: 84.Bl -tag -width "cylinder" 85.It Em "sysid" 86is used to label the partition. 87.Nx 88reserves the magic number 169 decimal (A9 in hex). 89The number 0 is used to mark a partition as unused. See the 90.Fl l 91flag. 92.It Xo 93.Em start , 94.Em size 95.Xc 96start address and size of a partition in sectors. 97.It Em "flag 80" 98specifies that this is the active partition. 99.It Xo 100.Em "cylinder" , 101.Em "head" , 102.Em "sector" 103.Xc 104the beginning or ending address of a partition. 105.El 106.Pp 107.Em "Note:" 108these numbers are calculated using BIOS's understanding of the disk geometry 109and saved in the bootblock. 110.Pp 111At the start the 112.Nm 113program will determine whether the disk sector 0 is valid as a boot sector. 114(This is determined by checking the magic number.) 115If not, 116.Nm 117will initialize the boot code as well as the partition table. 118During this, all four partitions will be marked empty. 119.Pp 120The flags 121.Fl a , 122.Fl i 123or 124.Fl u 125are used to indicate that the partition data is to be updated. 126The 127.Nm 128program will enter an interactive conversational mode. 129This mode is designed not to change any data unless you explicitly tell it to; 130.Nm 131selects defaults for its questions to guarantee that behavior. 132.Pp 133Getting the 134.Em cylinder , 135.Em head , 136and 137.Em sector 138fields correct is tricky. 139So by default, 140they will be calculated for you; 141you can specify them if you choose. 142.Pp 143Finally, 144when all the data for the first sector has been accumulated, 145.Nm 146will ask if you really want to rewrite sector 0. 147Only if you reply affirmatively to this question will 148.Nm 149write anything to the disk. 150.Pp 151Available options: 152.Pp 153.Bl -tag -width Ds 154.It Fl 0 155Update partition slot 0. 156.It Fl 1 157Update partition slot 1. 158.It Fl 2 159Update partition slot 2. 160.It Fl 3 161Update partition slot 3. 162.It Fl a 163Change the active partition. 164In interactive mode this question will be asked after the partitions 165have been processed. 166.It Fl b Ar cylinders/heads/sectors 167Specify the BIOS parameters for 168.Ar cylinders , 169.Ar heads 170and 171.Ar sectors . 172It is used only in conjunction with the 173.Fl u 174flag. 175.It Fl B 176Install or update the bootselect code on an i386 machine. 177.It Fl c Ar bootcode 178Specify the filename that 179.Nm 180should read the bootcode from. 181The default is to read from 182.Pa /usr/mdec/mbr 183if run on an i386 machine, and leave the bootcode empty for other 184machines. 185.It Fl f 186Run 187.Nm 188in a non-interactive mode. 189In this mode, you can only change the disk parameters by using the 190.Fl b 191flag. 192This is provided only so scripts or other programs may use 193.Nm 194as part of an automatic installation process. 195Using the 196.Fl f 197flag with 198.Fl u 199makes it impossible to specify the starting and ending 200.Ar cylinder , 201.Ar head 202and 203.Ar sector 204fields. 205They will be automatically computed using the BIOS geometry. 206.It Fl i 207Explicitly request initialization of the master boot code 208(similar to what 209.Nm fdisk /mbr 210does under 211.Tn MSDOS ) , 212even if the magic number in the first sector is ok. 213The partition table is left alone by this (but see above). 214.It Fl l 215Lists known 216.Em sysid 217values and exit. 218.It Fl s Ar id/start/size 219Specify the partition 220.Ar id , 221.Ar start 222and 223.Ar size . 224This flag requires the use of a partition selection flag 225.Po 226.Fl 0 , 227.Fl 1 , 228.Fl 2 , 229or 230.Fl 3 231.Pc 232.It Fl S 233When used with no other flags print a series of 234.Pa /bin/sh 235commands for setting variables to the partition information. 236This is used by the installation scripts. 237.It Fl u 238Display each partition in turn and interactively ask if you want to edit it. 239If you reply affirmatively, it will step through each field showing the old 240value and asking for a new one. 241When you are done with a partition, 242.Nm 243will display the information again and ask if it is correct. 244.Nm 245will then proceed to the next entry. 246.El 247.Sh NOTES 248The automatic calculation of the starting cylinder and 249other parameters 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, but 253.Nm 254gives 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 258Editing an existing partition is risky, and may cause you to 259lose all the data in that partition. 260.Pp 261You should run this program interactively once or twice to see how it works. 262This is completely safe as long as you answer the last question in the negative. 263.Sh FILES 264.Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact 265.It Pa /usr/mdec/mbr 266Default location of i386 bootcode 267.It Pa /usr/mdec/mbr_bootsel 268Default location of i386 bootselect code 269.El 270.Sh SEE ALSO 271.Xr disklabel 8 , 272.Xr mbr 8 , 273.Xr mbrlabel 8 274.Sh BUGS 275There are subtleties that the program detects that are not explained in 276this manual page. 277