1.\" $OpenBSD: fdisk.8,v 1.95 2019/04/29 18:54:12 krw Exp $ 2.\" 3.\" 4.\" Copyright (c) 1997 Tobias Weingartner 5.\" 6.\" Permission to use, copy, modify, and distribute this software for any 7.\" purpose with or without fee is hereby granted, provided that the above 8.\" copyright notice and this permission notice appear in all copies. 9.\" 10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17.\" 18.Dd $Mdocdate: April 29 2019 $ 19.Dt FDISK 8 20.Os 21.Sh NAME 22.Nm fdisk 23.Nd partition table maintenance program 24.Sh SYNOPSIS 25.Nm fdisk 26.Op Fl egvy 27.Op Fl i | u 28.Op Fl b Ar blocks 29.Oo 30.Fl c Ar cylinders 31.Fl h Ar heads 32.Fl s Ar sectors 33.Oc 34.Op Fl f Ar mbrfile 35.Op Fl l Ar blocks 36.Ar disk 37.Sh DESCRIPTION 38.Nm fdisk 39makes changes to the MBR and GPT tables found on some disks. 40On such disks sector 0 contains a 4-entry MBR partition table 41that divides the space. 42The GPT partition table, when present, starts at sector 1. 43.Pp 44Each entry has a type. 45A type of 46.Ar 0xA6 47indicates an 48.Ox 49MBR partition, which starts with its own 5016-entry partition table known as a 51.Xr disklabel 5 . 52This can be edited using 53.Xr disklabel 8 . 54.Pp 55Caution is advised when editing these tables, since some platforms 56use tricks to boot and may rely on specific configurations created 57at install time. 58.Pp 59The options are as follows: 60.Bl -tag -width Ds 61.It Fl b Ar blocks 62A special boot partition of the specified size will be written to disk 63on architectures that need one. 64Only valid with 65.Fl i . 66.It Xo 67.Fl c Ar cylinders 68.Fl h Ar heads 69.Fl s Ar sectors 70.Xc 71Specifies an alternate BIOS geometry for 72.Nm 73to use. 74By default, an automatic calculation of disk size will be built 75using heuristics. 76These figures are taken from the in-core disklabel 77(see 78.Xr disklabel 8 ) , 79or values that 80.Em /boot 81has passed to the kernel. 82.Pp 83Only one of 84.Fl chs 85or 86.Fl l 87can be specified. 88.It Fl e 89Use the 90.Nm 91interactive editor to modify the partition table. 92See 93.Sx COMMAND MODE , 94below, for more information. 95.It Fl f Ar mbrfile 96Specifies an alternate MBR template file. 97The default file is 98.Pa /usr/mdec/mbr . 99.It Fl g 100A protective MBR and a default GPT will be written to disk. 101The default GPT will have a single 102.Ox 103partition containing all available space not allocated by a 104.Fl b 105specification. 106Only valid with 107.Fl i . 108.It Fl i 109Requests that the partition table data be re-initialized. 110In this mode, 111.Nm 112will completely overwrite the primary MBR bootcode and MBR partition table. 113.Pp 114If 115.Fl g 116is not specified then the MBR will be overwritten by 117the default MBR template 118.Pa /usr/mdec/mbr 119(or the one optionally specified by the 120.Fl f 121flag). 122In the default template, MBR partition number 3 will be configured as an 123.Ox 124MBR partition containing all available space not allocated by a 125.Fl b 126specification. 127.Pp 128Only one of 129.Fl i 130or 131.Fl u 132can be specified. 133.It Fl l Ar blocks 134Specify the number of blocks in the disk, and force the MBR to be in LBA 135mode only. 136.Pp 137Only one of 138.Fl chs 139or 140.Fl l 141can be specified. 142.It Fl u 143Update MBR bootcode, preserving existing MBR partition table. 144The MBR bootcode extends from offset 0x000 to the start of the MBR partition 145table at offset 0x1BE. 146It is similar to the 147.Fl i 148flag, except the existing MBR partition table is preserved. 149This is useful for writing new MBR bootcode onto an existing drive, and is 150equivalent to the DOS command 151.Dq FDISK /MBR . 152Note that this option will overwrite the NT disk signature, if present. 153.Pp 154Only one of 155.Fl i 156or 157.Fl u 158can be specified. 159.It Fl v 160Print the contents of the MBR, the Primary GPT and the Secondary GPT. 161Also print more detailed GPT header and partition entry information. 162Cannot be used with 163.Fl i , 164.Fl u , 165or 166.Fl e . 167.It Fl y 168Avoid asking yes/no questions when not desirable. 169.It Ar disk 170Specify the 171.Ar disk 172to operate on. 173It can be specified either by its full pathname or an abbreviated disk form. 174In its abbreviated form, the path to the device and the 175.Sq r 176denoting 177.Qq raw device 178are omitted and the partition letter is optional. 179For example, the first IDE disk can be specified as either 180.Pa /dev/rwd0c , 181.Pa wd0c , 182or 183.Pa wd0 . 184.El 185.Sh TYPICAL LAYOUT 186When called with no special flags, 187.Nm 188prints the partition table of the specified disk. 189.Pp 190If the disk does not contain a valid GPT the contents 191of the MBR are displayed. 192For example: 193.Bd -literal -offset 1n 194# fdisk sd0 195Disk: sd0 geometry: 121601/255/63 [1953525168 Sectors] 196Offset: 0 Signature: 0xAA55 197 Starting Ending LBA Info: 198 #: id C H S - C H S [ start: size ] 199------------------------------------------------------------------------ 200 0: 0B 0 1 1 - 26108 0 63 [ 63: 419425020 ] FAT32 201 1: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 202 2: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 203*3: A6 26108 1 1 - 121600 254 63 [ 419425083: 1534094982 ] OpenBSD 204.Ed 205.Pp 206This 1953525168 sector (931GB) disk drive is divided into two MBR 207partitions that span the whole disk. 208The first MBR partition is a 200GB FAT32 partition; 209the second is a 731GB 210.Ox 211MBR partition using the remainder of the disk. 212The fields of the output are: 213.Bl -tag -width "start/size" 214.It Em "#" 215Number identifying each MBR partition table entry. 216There are a total of four slots. 217.Sq * 218denotes the MBR partition which is declared bootable. 219.It Em "id" 220MBR partition type identifier. 221.Ox 222reserves the 223magic number hexadecimal A6 (166 decimal). 224.It Em "C/H/S" 225These fields provide the starting and ending address of the MBR partition 226in BIOS geometry. 227.It Em "start/size" 228These fields provide the starting sector and size in sectors of the 229MBR partition in linear block addresses. 230.El 231.Pp 232.Em NOTE : 233The BIOS geometry sectors field (C/H/S) is 234.Dq 1 based , 235but the LBA "start" field is 236.Dq 0 based . 237.Pp 238The CHS values will need to be in the BIOS's geometry 239for the system to be able to boot and use the drive correctly. 240These values must be kept correctly synchronized or a variety of 241problems develop which are very difficult to diagnose. 242.Pp 243If the disk contains a protective MBR and a valid GPT, the contents of the GPT 244are displayed. 245For example: 246.Bd -literal -offset 1n 247Disk: sd2 Usable LBA: 64 to 7765952 [7766016 Sectors] 248 #: type [ start: size ] 249------------------------------------------------------------------------ 250 1: EFI Sys [ 64: 960 ] 251 3: OpenBSD [ 1024: 7764929 ] 252.Ed 253.Pp 254This 7766016 sector disk drive is divided into two 255partitions that span the whole disk. 256The first partition is a 960 sector EFI Sys partition; 257the second is a 7764929 sector 258.Ox 259partition using the remainder of the disk. 260The fields of the output are: 261.Bl -tag -width "type" 262.It Em "#" 263Number identifying each partition table entry. 264.It Em "type" 265The partition type identifier. 266If the type is recognized the name of the type is displayed. 267Otherwise the type GUID is displayed. 268.It Em "start" 269The sector the partition starts on. 270.It Em "size" 271The number of sectors in the partition. 272.El 273.Pp 274If the 275.Fl v 276option is specified, the disk GUID and each partition's GUID and name are 277also displayed. 278.Pp 279In either the MBR or GPT case the 280.Ox 281partition shown above is subdivided further using the 282functionality provided by 283.Xr disklabel 8 , 284which provides 285.Ox 286partitions. 287.Bd -literal -offset 1n 288# /dev/rsd0c: 289type: SCSI 290disk: SCSI disk 291label: WDC WD10EADS-65L 292duid: 085ef8d68623f5b3 293flags: 294bytes/sector: 512 295sectors/track: 63 296tracks/cylinder: 255 297sectors/cylinder: 16065 298cylinders: 121601 299total sectors: 1953525168 300boundstart: 419425083 301boundend: 1953520065 302drivedata: 0 303 30416 partitions: 305# size offset fstype [fsize bsize cpg] 306 a: 2097125 419425083 4.2BSD 2048 16384 1 307 b: 4715520 421522208 swap 308 c: 1953525168 0 unused 309 d: 8388608 426237728 4.2BSD 2048 16384 1 310 e: 16771072 434626336 4.2BSD 2048 16384 1 311 f: 4194304 451397408 4.2BSD 2048 16384 1 312 g: 2097152 455591712 4.2BSD 2048 16384 1 313 h: 20971520 457688864 4.2BSD 2048 16384 1 314 i: 419425020 63 MSDOS 315 j: 4194304 478660384 4.2BSD 2048 16384 1 316 k: 4194304 482854688 4.2BSD 2048 16384 1 317 l: 629145536 487049024 4.2BSD 4096 32768 1 318.Ed 319.Pp 320These 321.Ox 322partitions are then mounted as follows using 323.Pa /etc/fstab : 324.Bd -literal -offset indent 325/dev/sd0a / ffs rw,softdep 1 1 326/dev/sd0d /tmp ffs rw,softdep,nodev,nosuid 1 2 327/dev/sd0e /var ffs rw,softdep,nodev,nosuid 1 2 328/dev/sd0f /usr ffs rw,softdep,nodev 1 2 329/dev/sd0g /usr/X11R6 ffs rw,softdep,nodev 1 2 330/dev/sd0h /usr/local ffs rw,softdep,nodev 1 2 331/dev/sd0i /mnt/example msdos rw,nodev,nosuid 1 2 332/dev/sd0j /usr/src ffs rw,softdep,nodev,nosuid 1 2 333/dev/sd0k /usr/obj ffs rw,softdep,nodev,nosuid 1 2 334/dev/sd0l /home ffs rw,softdep,nodev,nosuid 1 2 335.Ed 336.Sh COMMAND MODE 337The 338.Fl e 339flag causes 340.Nm 341to enter an interactive command mode. 342The prompt contains information about the state of the edit 343process. 344.Pp 345.Dl Ar disk Ns *:1> 346.Pp 347Where 348.Ar disk 349is the name of the disk being edited, 350.Sq * 351means that the in-memory copy of the partition table has been modified, but 352not yet written to disk and 3531 is the number of the boot block being edited. 354This number will be 2 when editing an extended MBR partition, 3553 when editing an extended MBR partition within an extended MBR partition, 356and so on. 357.Pp 358The list of commands and their explanations are given below. 359Commands may be abbreviated provided enough characters are given to ensure 360unambiguity. 361.Bl -tag -width Ds 362.It Cm ?\& 363A synonym for 364.Cm help . 365.It Cm help 366Display a list of commands that 367.Nm 368understands in the interactive edit mode. 369.It Cm manual 370Display this manual page. 371.It Cm reinit Op Cm gpt | Cm mbr 372Initialize the currently selected, in-memory copy of the 373boot block. 374If 375.Cm gpt 376is specified a protective MBR and a GPT are initialized. 377If 378.Cm mbr 379is specified only an MBR is initialized. 380If neither 381.Cm mbr 382nor 383.Cm gpt 384are specified then a protective MBR and a GPT are initialized if a protective 385MBR already exists. 386Otherwise only an MBR is initialized. 387.It Cm disk 388Display the current drive geometry that 389.Nm 390probed using kernel provided information and various heuristics. 391The disk geometry may be changed at this point. 392Not available when editing a GPT. 393.It Cm edit Ar # 394Edit a given table entry in the memory copy of 395the current boot block. 396Sizes may be adjusted in BIOS geometry mode (MBR only) or using 397sector offsets and sizes. 398A unit 399.Sq b , 400.Sq k , 401.Sq m , 402or 403.Sq g 404may be appended to indicate bytes, kilobytes, megabytes, or gigabytes. 405The special size value 406.Sq * 407will cause the partition to be sized to use the remainder of the disk. 408.It Cm flag Ar # Op Ar value 409Make the given MBR partition table entry bootable 410and mark all others as not bootable 411(only one entry can be marked bootable). 412The bootable partition is denoted with 413.Sq * . 414.\" If you wish to boot from an extended 415.\" MBR partition, you will need to mark the MBR partition table entry for the 416.\" extended MBR partition as bootable. 417If a 418.Ar value 419of 0 is given, 420the MBR partition is marked as not bootable, 421but no other MBR partitions are touched. 422.It Cm update 423Update the machine MBR bootcode and 0xAA55 signature in the memory copy 424of the currently selected MBR. 425Note that this option will overwrite an NT disk 426signature, if present. 427Not available when editing a GPT. 428.It Cm select Ar # 429Select and load into memory the MBR pointed 430to by the extended MBR partition table entry in the current boot block. 431Not available when editing a GPT. 432.It Cm setpid Ar # 433Change the partition 434identifier of the given partition table entry. 435This command is particularly useful for reassigning 436an existing partition to 437.Ox . 438.It Cm swap Ar # Ar # 439Swap two partition entries. 440.It Cm print Op Ar unit 441Print the currently selected in-memory copy of the 442partition table to the terminal. 443A 444.Ar unit 445.Sq b , 446.Sq k , 447.Sq m , 448or 449.Sq g 450may be appended to indicate bytes, kilobytes, megabytes, or gigabytes. 451Otherwise the number of sectors is printed. 452.It Cm write 453Write the in-memory copy of the partition table to disk. 454.It Cm exit 455Exit the current level of 456.Nm fdisk , 457either returning to the 458previously selected in-memory copy of a MBR, or exiting the 459program if there is none. 460.It Cm quit 461Exit the current level of 462.Nm fdisk , 463either returning to the 464previously selected in-memory copy of a MBR, or exiting the 465program if there is none. 466Unlike 467.Em exit 468it does write the modified block out. 469.It Cm abort 470Quit program without saving current changes. 471.El 472.Sh FILES 473.Bl -tag -width /usr/mdec/mbr -compact 474.It Pa /usr/mdec/mbr 475default MBR template 476.El 477.Sh SEE ALSO 478.Xr fstab 5 , 479.Xr boot_amd64 8 , 480.Xr boot_i386 8 , 481.Xr boot_macppc 8 , 482.Xr disklabel 8 483.Sh CAVEATS 484Hand crafted disk layouts are highly error prone. 485It is common practice, 486though by no means required, 487that MBR partitions start on a cylinder boundary 488(generally head 0, sector 1, but head 1, sector 1 for track 0), 489and that MBR partitions also end at cylinder boundaries. 490