1.\" $NetBSD: fdisk.8,v 1.40 2003/05/01 13:36:25 dsl Exp $ 2.\" 3.Dd April 30, 2003 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 afiuvBS 12.Bk -words 13.Op Fl 0 | 1 | 2 | 3 14.Ek 15.Bk -words 16.Op Fl E Ar number 17.Ek 18.Bk -words 19.Op Fl b Ar cylinders/heads/sectors 20.Ek 21.Bk -words 22.Op Fl s Ar id/start/size Ns Bq Ar /bootmenu 23.Ek 24.Bk -words 25.Op Fl c Ar bootcode 26.Ek 27.Bk -words 28.Op Fl r|w Ar file 29.Ek 30.Bk -words 31.Op Ar device 32.Ek 33.Nm 34.Fl l 35.Sh DESCRIPTION 36The 37.Nm 38program is used to divide space on a disk into partitions and set 39one active. 40There can be at most 4 partitions defined in sector 0, 41one of which can be an extended 42partition which can be split into any number of sub-partitions. 43.Pp 44.Nx 45does not use the partitioning done by 46.Nm , 47instead it uses a 48.Nx 49disklabel saved in sector 1 of the 50.Nx 51partition. 52.Pp 53The standard mbr boot code will only boot the 'active' partition. 54However 55.Nx 56contains two alternate boot programs which allow the user to 57interactively select which of the partitions to boot. 58The 'mbr_ext' code will boot 59.Nx 60from an extended partition but will not work on old systems that do not 61support LBA reads. 62.Pp 63At the start the 64.Nm 65program will determine whether the disk sector 0 is valid as a boot sector. 66(This is determined by checking the magic number.) 67If not, 68.Nm 69will initialise the boot code as well as the partition table. 70During this, all four partitions will be marked empty. 71.Pp 72The flags 73.Fl a , 74.Fl i 75or 76.Fl u 77are used to indicate that the partition data is to be updated. 78The 79.Nm 80program will enter an interactive conversational mode. 81This mode is designed not to change any data unless you explicitly tell it to; 82.Nm 83selects defaults for its questions to guarantee that behaviour. 84.Pp 85.Nm 86will calculate the correct 87.Em cylinder , 88.Em head , 89and 90.Em sector 91values for any partition you edit. 92If you specify 93.Fl v 94you will be asked whether you want to specify them yourself. 95.Pp 96Finally, when all the data for the first sector has been accumulated, 97.Nm 98will ask if you really want to write the new partition table. 99Only if you reply affirmatively to this question will 100.Nm 101write anything to the disk. 102.Pp 103Available options: 104.Pp 105.Bl -tag -width Ds 106.It Fl 0 107Update partition slot 0. 108.It Fl 1 109Update partition slot 1. 110.It Fl 2 111Update partition slot 2. 112.It Fl 3 113Update partition slot 3. 114.It Fl a 115Change the active partition. 116In interactive mode this question will be asked after the partitions 117have been processed. 118.It Fl b Ar cylinders/heads/sectors 119Specify the BIOS parameters for 120.Ar cylinders , 121.Ar heads , 122and 123.Ar sectors . 124It is used only in conjunction with the 125.Fl u 126flag. 127.It Fl B 128On an i386 or amd64 system, interactively update the boot selector settings. 129(The boot selector permits the user to interactively select the boot 130partition, and thus which operating system is run, at system boot time. 131See 132.Xr mbr 8 133for more information.) 134.It Fl c Ar bootcode 135Specify the filename that 136.Nm 137should read the bootcode from. 138If the name of a directory is specified, then 139.Nm 140will look for files with the default names in that directory. 141The default is to read from 142.Pa /usr/mdec/mbr , 143.Pa /usr/mdec/mbr_bootsel 144or 145.Pa /usr/mdec/mbr_ext 146depending on whether 147.Ar bootmenu 148was specified for any partitions 149on an i386 machine, and leave the bootcode empty for other 150machines. 151.It Fl E Ar number 152Update extended partition 153.Ar number . 154If the specified extended partition doesn't exist an additional extended 155partition will be created. 156.It Fl f 157Run 158.Nm 159in a non-interactive mode. 160In this mode, you can only change the disk parameters by using the 161.Fl b 162flag. 163This is provided only so scripts or other programs may use 164.Nm 165as part of an automatic installation process. 166Using the 167.Fl f 168flag with 169.Fl u 170makes it impossible to specify the starting and ending 171.Ar cylinder , 172.Ar head , 173and 174.Ar sector 175fields. 176They will be automatically computed using the BIOS geometry. 177.br 178If 179.Fl u 180and 181Fl s 182are specified then the details of the specified partition will be changed. 183Any other partitions which overlap the requested part of the disk will be 184silently deleted. 185.It Fl i 186Explicitly request initialisation of the master boot code 187(similar to what 188.Nm fdisk /mbr 189does under 190.Tn MSDOS ) , 191even if the magic number in the first sector is ok. 192The partition table is left alone by this (but see above). 193.It Fl l 194Lists known 195.Em sysid 196values and exit. 197.It Fl r Ar file 198Read the boot record from file 199.Ar file 200instead of the specified disk. 201The geometry information used is still that of the disk volume. 202Any changes are written back to the file. 203.It Fl s Ar id/start/size Ns Bq Ar /bootmenu 204Specify the partition 205.Ar id , 206.Ar start , 207.Ar size , 208and optionally 209.Ar bootmenu . 210This flag requires the use of a partition selection flag 211.Po 212.Fl 0 , 213.Fl 1 , 214.Fl 2 , 215.Fl 3 , 216or 217.Fl E Ar number 218.Pc 219.It Fl S 220When used with no other flags print a series of 221.Pa /bin/sh 222commands for setting variables to the partition information. 223This could be used by installation scripts. 224.It Fl u 225Display the partitions and interactively ask which one you want to edit. 226.Nm 227will step through each field showing the old value and asking for a new one. 228The 229.Em start 230and 231.Em size 232can be specified in blocks (nn), cylinders (nnc) or megabytes (nnm), values 233in megabytes will be rounded to the nearest cylinder boundary. 234The 235.Em size 236may be specified as 237.Em $ 238in which case the partition will extend to the end of the available free space. 239.br 240.Nm 241will not allow you to create partitions which overlap. 242.Pp 243If 244.Em bootmenu 245is specified for any partition 246.Nm 247will determine whether the installed boot code supports the bootselect code, 248if it doesn't you will be asked whether you want to install the required 249boot code. 250.It Fl v 251Be more verbose, specifying 252.Fl v 253more than once may increase the amount of output. 254.br 255Specifying 256.Fl v 257with 258.Fl u 259allows the user to explicitly specify some values for with the default 260ies usually correct. 261.It Fl w Ar file 262Write the modified partition table to file 263.Ar file 264instead of the disk. 265.El 266.Pp 267When called with no arguments, it prints the partition table. 268An example follows: 269.Bd -literal 270 Disk: /dev/rwd0d 271 NetBSD disklabel disk geometry: 272 cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder) 273 total sectors: 40032696 274 275 BIOS disk geometry: 276 cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder) 277 total sectors: 40032696 278 279 Partition table: 280 0: NetBSD (sysid 169) 281 bootmenu: net 1.5. 282 start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active 283 1: Primary DOS with 32 bit FAT (sysid 11) 284 bootmenu: win98 285 start 63, size 4208967 (2055 MB, Cyls 0-262) 286 2: NetBSD (sysid 169) 287 bootmenu: current 288 start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40) 289 3: Ext. partition - LBA (sysid 15) 290 start 12498570, size 20016990 (9774 MB, Cyls 778-2024) 291 Extended partition table: 292 E0: NetBSD (sysid 169) 293 bootmenu: test 294 start 12498633, size 12305727 (6009 MB, Cyls 778-1544) 295 E1: Primary DOS with 32 bit FAT (sysid 11) 296 start 24804423, size 4096512 (2000 MB, Cyls 1544-1799) 297 E2: Primary DOS with 32 bit FAT (sysid 11) 298 start 28900998, size 3614562 (1765 MB, Cyls 1799-2024) 299 Bootselector enabled, infinite timeout. 300.Ed 301.Pp 302This example disk is divided into four partitions the last of which is 303an extended partition. 304The sub-partitions of the extended partition are also shown. 305In this case there is no free space in either the disk or in the extended 306partition. 307.Pp 308The various fields in each partition entry are: 309.br 310.in +4 311.Em ptn_number : id_name 312(sysid 313.Em id_number ) 314.br 315.in +4 316bootmenu: 317.Em bootmenu 318.br 319start 320.Em start , 321size 322.Em size ( MB 323MB, Cyls 324.Em first Ns No - Ns Em next ) 325.Op , Active 326.in -4 327.in -4 328.Bl -tag -width "bootmenu" 329.It Em ptn_number 330is the number of the partition. 331.It Em id_name 332is the name of the filesystem type or operating system that uses this partition. 333.It Em id_number 334is the number that identifies the partition type. 335169 decimal is used for 336.Nx 337partitions, 33815 decimal to create an extended partition 339and 0 to mark a partition as unused. 340Use 341.Nm 342.Fl l 343to list the known partition types. 344.It Em bootmenu 345is the menu prompt output by the interactive boot code for this partition. 346This line is omitted if the prompt is not defined. 347.It Xo 348.Em start , 349.Em size 350.Xc 351are the start address and size of the partition in sectors. 352.It Em MB 353is the size of the partition in megabytes. 354.It Xo 355.Em first , 356.Em next 357.Xc 358are the bounds of this partition displayed as cylinder/head/sector. 359If the partition starts (or ends) on a cylinder boundary the head and 360sector values are omitted. 361If 362.Fl v 363is not specified the start of extended partitions and the first partition 364on the disk are rounded down to include the mandatory red tape in the 365preceeding track. 366.It Active 367is output if this is the active partition. 368.El 369.Pp 370If the 371.Fl v 372flag is given two additional lines are output for each partition: 373.in +4 374beg: cylinder 375.Em cylinder , 376head 377.Em head , 378sector 379.Em sector 380.br 381end: cylinder 382.Em cylinder , 383head 384.Em head , 385sector 386.Em sector 387.in -4 388.Bl -tag -width "bootmenu" 389.It Xo 390.Em "cylinder" , 391.Em "head" , 392.Em "sector" 393.Xc 394are the beginning or ending address of a partition. 395.br 396.Em "Note:" 397these numbers are read from the bootblock, so are the values calculated 398by a previous run of 399.Nm . 400.El 401.Sh NOTES 402Traditionally the partition boundaries should be on cylinder boundaries 403using the BIOS geometry, all of the first track should be reserved 404for use by the BIOS. 405Although the BIOS geometry is typically different from the geometry 406reported by the drive, neither will match the actual physical geometry 407for modern disks (the actual geometry will vary across the disk). 408Keeping the partition boundaries on cylinder boundaries makes partitioning 409a driver easier as only relatively small numbers need be entered. 410.Pp 411The automatic calculation of the starting cylinder and 412other parameters uses 413a set of figures that represent what the BIOS thinks is the 414geometry of the drive. 415The default values should be correct for the system on which 416.Nm 417is run, however if you move the disk to a different system the 418BIOS of that system might use a different geometry translation. 419.Pp 420If you run the equivalent of 421.Nm 422on a different operating system then the 423.Ar bootmenu 424strings associated with extended partitions may be lost. 425.Pp 426Editing an existing partition is risky, and may cause you to 427lose all the data in that partition. 428.Pp 429You should run this program interactively once or twice to see how it works. 430This is completely safe as long as you answer the last question in the negative. 431You can also specify 432.Fl w Ar file 433to write the output to a file and later specify 434.Fl r Ar file 435to read back the updated information. 436This can be done without having write access to the disk volume. 437.Sh FILES 438.Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact 439.It Pa /usr/mdec/mbr 440Default location of i386 bootcode 441.It Pa /usr/mdec/mbr_bootsel 442Default location of i386 bootselect code 443.It Pa /usr/mdec/mbr_ext 444Default location of i386 bootselect for extended partitions 445.El 446.Sh SEE ALSO 447.Xr disklabel 8 , 448.Xr mbr 8 , 449.Xr mbrlabel 8 450.Sh BUGS 451The word 'partition' is used to mean both an mbr partition and a 452.Nx 453partition, sometimes in the same sentence. 454.Pp 455There are subtleties that the program detects that are not explained in 456this manual page. 457