1.\" $OpenBSD: fdisk.8,v 1.120 2024/09/29 18:00:38 jmc 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: September 29 2024 $ 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 evy 27.Op Fl A | g | i | u 28.Op Fl b Ar blocks Ns Op @ Ns Ar offset Ns Op : Ns Ar type 29.Op Fl l Ar blocks | Fl c Ar cylinders Fl h Ar heads Fl s Ar sectors 30.Op Fl f Ar file 31.Ar disk 32.Sh DESCRIPTION 33.Nm fdisk 34creates and edits MBR and GPT partition tables. 35These tables are used by the boot process of some 36platforms to find the 37.Ox 38kernel and, when present, are used by the kernel to find the 39.Xr disklabel 5 . 40.Pp 41Caution is advised when editing these tables since some platforms 42rely on specific configurations created at install time. 43.Pp 44The options are as follows: 45.Bl -tag -width Ds 46.It Fl A 47Modifies the GPT partition table entries on 48.Ar disk 49to put all available space not taken by 50.Fl b 51into a single 52.Ox 53partition. 54The available space is maximized by deleting all existing partition 55entries except for partition types APFS ISC, APFS, APFS Recovery, BIOS Boot, 56HiFive FSBL, HiFive BBL and partitions with the 57.Sq Required 58GPT attribute set. 59.Pp 60If 61APFS ISC, APFS, or APFS Recovery 62partitions are detected then existing 63EFI system 64partitions are also preserved. 65If the preserved EFI system partition has fewer blocks 66than the number requested with 67.Fl b , 68the modified GPT is discarded. 69.It Fl b Ar blocks Ns Op @ Ns Ar offset Ns Op : Ns Ar type 70Creates a partition table entry of the specified number of blocks, offset 71and type. 72.Ar offset 73defaults to the first available block, and 74.Ar type 75defaults to 76.Sq EF . 77.Pp 78.Fl b 79is only available in combination with 80.Fl A , 81.Fl g , 82or 83.Fl i . 84.Pp 85If 86.Fl A 87or 88.Fl g 89is specified, only the 90.Ar blocks 91value is used. 92.It Xo 93.Fl c Ar cylinders 94.Fl h Ar heads 95.Fl s Ar sectors 96.Xc 97Specifies a geometry for 98.Nm 99to use. 100By default the disk size and geometry are obtained 101from the default 102.Xr disklabel 5 103constructed by the kernel for 104.Ar disk . 105See 106.Xr disklabel 5 107and 108.Xr disklabel 8 . 109.It Fl e 110Invokes the interactive partition table editor. 111See 112.Sx COMMAND MODE 113below. 114.It Fl f Ar file 115Specifies a file containing the bootcode for an MBR. 116The default file is 117.Pa /usr/mdec/mbr . 118.It Fl g 119Writes a default GPT, including a protective MBR, to 120.Ar disk . 121The GPT has a single 122.Ox 123partition containing all available space not taken by 124.Fl b . 125.It Fl i 126Writes a default MBR to 127.Ar disk . 128The MBR has a single 129.Ox 130partition containing all the available space not taken by 131.Fl b . 132The bootcode is initialized as described in 133.Fl u . 134.It Fl l Ar count 135Treat 136.Ar disk 137as though it has a size of 138.Ar count 139blocks. 140.It Fl u 141Updates the MBR bootcode. 142If a bootcode file is present (see 143.Fl f ) 144the MBR, except for the partition entries, is replaced by 145the first block of the file. 146If no bootcode file is present, zeros are used. 147.Pp 148Not available when editing a GPT. 149.It Fl v 150Prints detailed information about the MBR, the Primary GPT and the 151Secondary GPT. 152.It Fl y 153New or modified partition table is written to disk without 154asking for confirmation. 155.It Ar disk 156.Nm 157creates or modifies the partition table of 158.Ar disk . 159.Ar disk 160can be a full pathname, 161e.g. 162.Pa /dev/rsd0c , 163a raw partition name, e.g. 164.Pa sd0c , 165or just the disk name, e.g. 166.Pa sd0 . 167.El 168.Sh TYPICAL LAYOUT 169When called without options, 170.Nm 171prints the partition table of 172.Ar disk . 173.Pp 174If 175.Ar disk 176has a GPT a terse version of its contents is printed: 177.Bd -literal -offset 1n 178# fdisk sd0 179Disk: sd0 Usable LBA: 64 to 500118128 [500118192 Sectors] 180 #: type [ start: size ] 181------------------------------------------------------------------------ 182 1: EFI Sys [ 64: 960 ] 183 3: OpenBSD [ 1024: 500117105 ] 184.Ed 185.Pp 186When 187.Ar disk 188does not have a GPT, the first block of 189.Ar disk 190is printed as an MBR: 191.Bd -literal -offset 1n 192# fdisk sd0 193Disk: sd0 geometry: 121601/255/63 [1953525168 Sectors] 194Offset: 0 Signature: 0xAA55 195 Starting Ending LBA Info: 196 #: id C H S - C H S [ start: size ] 197------------------------------------------------------------------------ 198 0: 0B 0 1 1 - 26108 0 63 [ 63: 419425020 ] FAT32 199 1: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 200 2: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 201*3: A6 26108 1 1 - 121600 254 63 [ 419425083: 1534094982 ] OpenBSD 202.Ed 203.Pp 204.Em NOTE : 205Partition entry #3 of this MBR is flagged as bootable. 206.Pp 207.Em NOTE : 208The 209.Em S 210field in the C/H/S values is 211.Dq 1 based , 212but the LBA "start" field is 213.Dq 0 based . 214.Pp 215The 216.Fl v 217option causes more information to be printed: 218.Bd -literal -offset 1n 219# fdisk -v sd0 220Primary GPT: 221Disk: sd0 Usable LBA: 64 to 500118128 [500118192 Sectors] 222GUID: f0418899-4976-4604-a783-3ebe135a8f12 223 #: type [ start: size ] 224 guid name 225------------------------------------------------------------------------ 226 1: EFI Sys [ 64: 960 ] 227 d0834013-dab8-44df-a5e4-123148f17e03 EFI System Area 228 3: OpenBSD [ 1024: 500117105 ] 229 cd356d77-8369-44b4-996e-79e8b9a47bfe OpenBSD Area 230 231Secondary GPT: 232Disk: sd0 Usable LBA: 64 to 500118128 [500118192 Sectors] 233GUID: f0418899-4976-4604-a783-3ebe135a8f12 234 #: type [ start: size ] 235 guid name 236------------------------------------------------------------------------ 237 1: EFI Sys [ 64: 960 ] 238 d0834013-dab8-44df-a5e4-123148f17e03 EFI System Area 239 3: OpenBSD [ 1024: 500117105 ] 240 cd356d77-8369-44b4-996e-79e8b9a47bfe OpenBSD Area 241 242MBR: 243Disk: sd0 geometry: 31130/255/63 [500118192 Sectors] 244Offset: 0 Signature: 0xAA55 245 Starting Ending LBA Info: 246 #: id C H S - C H S [ start: size ] 247------------------------------------------------------------------------------- 248 0: EE 0 0 2 - 31130 233 63 [ 1: 500118191 ] EFI GPT 249 1: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 250 2: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 251 3: 00 0 0 0 - 0 0 0 [ 0: 0 ] unused 252.Ed 253.Sh COMMAND MODE 254When 255.Nm 256enters interactive command mode, 257it copies the partition table from 258.Ar disk 259into memory and performs all edits on 260that copy. 261The partition table on 262.Ar disk 263is modified only by 264.Em write 265or 266.Em quit 267commands. 268.Pp 269The prompt contains information about the state of the edit 270process. 271.Pp 272.Dl Ar disk Ns *:1> 273.Pp 274Where 275.Ar disk 276is the name of the disk being edited, 277.Sq * 278means that the partition table has been modified, but 279not yet written to disk and 2801 is the edit level when operating on the MBR or GPT. 281This number is 2 when editing an extended partition in the MBR, 2823 when editing an extended partition within the edit level 2 283extended partition, and so on. 284.Pp 285The list of commands and their functions is 286given below. 287Commands may be abbreviated. 288The first command matching the abbreviation is selected. 289.Bl -tag -width Ds 290.It Cm ?\& 291A synonym for 292.Cm help . 293.It Cm help 294Displays a short summary of available commands. 295.It Cm manual 296Displays this manual page. 297.It Cm reinit Op Cm gpt | Cm mbr 298Initializes the partition table. 299.Pp 300By default an MBR partition table is initialized. 301If 302.Cm gpt 303is specified a GPT partition table is initialized, including the 304protective MBR. 305.It Cm setpid Ar # 306Sets the identifier of the partition table entry. 307.It Cm edit Ar # 308Edit an entry in the partition table. 309The offset and size of the entry may be specified in CHS mode (MBR only), 310by using sector offsets and sizes, or by using 311the units 312.Sq b , 313.Sq k , 314.Sq m , 315.Sq g , 316or 317.Sq t 318to indicate bytes, kilobytes, megabytes, gigabytes, or terabytes. 319The special size value 320.Sq * 321causes the partition to be sized to use the remainder of the disk. 322.It Cm flag Ar # Op Ar value 323Set the partition's flag (MBR) or attribute (GPT) value. 324.Ar value 325can be a positive integer or a hex string. 326An MBR partition will accept values from 0 to 0xff. 327A GPT partition will accept values from 0 to 0xfffffffffffffff. 328If 329.Ar value 330is not provided, the partition's bootable flag is set 331and all other partitions have their bootable flags reset. 332MBR partitions with the bootable flag set are printed with a 333.Sq * 334prefix. 335GPT partitions with the bootable flag set display 'bootable' in 336their attributes list. 337.It Cm update 338Updates the MBR bootcode. 339If a bootcode file is present (see 340.Fl f ) 341the MBR, except for the partition entries, is replaced by 342the first block of the file. 343If no bootcode file is present, zeros are used. 344.Pp 345Not available when editing a GPT. 346.It Cm select Ar # 347Selects an extended partition entry, increasing the edit level by 1. 348.Pp 349Not available when editing a GPT. 350.It Cm swap Ar # Ar # 351Swaps two partition entries. 352.It Cm print Op Ar unit 353Prints the partition table. 354If 355.Ar unit 356is 357.Sq b , 358.Sq k , 359.Sq m , 360.Sq g , 361or 362.Sq t 363partition sizes are shown in bytes, 364kilobytes, megabytes, gigabytes, or terabytes. 365If 366.Ar unit 367is not provided, sizes are shown in sectors. 368.It Cm write 369Writes the partition table to disk. 370.It Cm exit 371Discards outstanding changes and exits the current edit level. 372If the edit level is 1, 373.Nm 374terminates. 375.It Cm quit 376Writes outstanding changes to disk and exits the current edit 377level. 378If the edit level is 1, 379.Nm 380terminates. 381.It Cm abort 382Discards outstanding changes and terminates 383.Nm . 384.El 385.Sh FILES 386.Bl -tag -width /usr/mdec/mbr -compact 387.It Pa /usr/mdec/mbr 388default MBR bootcode 389.El 390.Sh SEE ALSO 391.Xr disklabel 5 , 392.Xr boot 8 , 393.Xr boot_amd64 8 , 394.Xr boot_i386 8 , 395.Xr boot_macppc 8 , 396.Xr disklabel 8 397