OpenBSD manual page server

Manual Page Search Parameters

FDISK(8) System Manager's Manual FDISK(8)

fdiskpartition table maintenance program

fdisk [-evy] [-A | -g | -i | -u] [-b blocks[@offset[:type]]] [-l blocks | -c cylinders -h heads -s sectors] [-f file] disk

fdisk creates and edits MBR and GPT partition tables. These tables are used by the boot process of some platforms to find the OpenBSD kernel and, when present, are used by the kernel to find the disklabel(5).

Caution is advised when editing these tables since some platforms rely on specific configurations created at install time.

The options are as follows:

Modifies the GPT partition table entries on disk to put all available space not taken by -b into a single OpenBSD partition. The available space is first maximized by deleting all existing partition entries except those for APFS ISC, APFS, APFS Recovery, BIOS Boot, HiFive FSBL and HiFive BBL partitions.

If APFS ISC, APFS, or APFS Recovery partitions are detected then existing EFI system partitions are also preserved. If the preserved EFI system partition has fewer blocks than the number requested with -b, the modified GPT is discarded.

blocks[@offset[:type]]
Creates a partition table entry of the specified number of blocks, offset and type. offset defaults to the first available block, and type defaults to ‘EF’.

-b is only available in combination with -A, -g, or -i.

If -A or -g is specified, only the blocks value is used.

cylinders -h heads -s sectors
Specifies a geometry for fdisk to use. By default the disk size and geometry are obtained from the default disklabel(5) constructed by the kernel for disk. See disklabel(5) and disklabel(8).
Invokes the interactive partition table editor. See COMMAND MODE below.
file
Specifies a file containing the bootcode for an MBR. The default file is /usr/mdec/mbr.
Writes a default GPT, including a protective MBR, to disk. The GPT has a single OpenBSD partition containing all available space not taken by -b.
Writes a default MBR to disk. The MBR has a single OpenBSD partition containing all the available space not taken by -b. The bootcode is initialized as described in -u.
count
Treat disk as though it has a size of count blocks.
Updates the MBR bootcode. If a bootcode file is present (see -f) the MBR, except for the partition entries, is replaced by the first block of the file. If no bootcode file is present, zeros are used.

Not available when editing a GPT.

Prints detailed information about the MBR, the Primary GPT and the Secondary GPT.
New or modified partition table is written to disk without asking for confirmation.
disk
fdisk creates or modifies the partition table of disk. disk can be a full pathname, e.g. /dev/rsd0c, a raw partition name, e.g. sd0c, or just the disk name, e.g. sd0.

When called without options fdisk prints the partition table of disk.

If disk has a GPT a terse version of its contents is printed:

# fdisk sd0
Disk: sd0       Usable LBA: 64 to 500118128 [500118192 Sectors]
   #: type                                 [       start:         size ]
------------------------------------------------------------------------
   1: EFI Sys                              [          64:          960 ]
   3: OpenBSD                              [        1024:    500117105 ]

When disk does not have a GPT, the first block of disk is printed as an MBR:

# fdisk sd0
Disk: sd0      geometry: 121601/255/63 [1953525168 Sectors]
Offset: 0      Signature: 0xAA55
           Starting       Ending      LBA Info:
 #: id     C  H  S -      C   H  S [     start:       size ]
------------------------------------------------------------------------
 0: 0B     0  1  1 -  26108   0 63 [        63:  419425020 ] FAT32
 1: 00     0  0  0 -      0   0  0 [         0:          0 ] unused
 2: 00     0  0  0 -      0   0  0 [         0:          0 ] unused
*3: A6 26108  1  1 - 121600 254 63 [ 419425083: 1534094982 ] OpenBSD

NOTE: Partition entry #3 of this MBR is flagged as bootable.

NOTE: The field in the C/H/S values is “1 based”, but the LBA "start" field is “0 based”.

The -v option causes more information to be printed:

# fdisk -v sd0
Primary GPT:
Disk: sd0       Usable LBA: 64 to 500118128 [500118192 Sectors]
GUID: f0418899-4976-4604-a783-3ebe135a8f12
   #: type                                 [       start:         size ]
      guid                                 name
------------------------------------------------------------------------
   1: EFI Sys                              [          64:          960 ]
      d0834013-dab8-44df-a5e4-123148f17e03 EFI System Area
   3: OpenBSD                              [        1024:    500117105 ]
      cd356d77-8369-44b4-996e-79e8b9a47bfe OpenBSD Area

Secondary GPT:
Disk: sd0       Usable LBA: 64 to 500118128 [500118192 Sectors]
GUID: f0418899-4976-4604-a783-3ebe135a8f12
   #: type                                 [       start:         size ]
      guid                                 name
------------------------------------------------------------------------
   1: EFI Sys                              [          64:          960 ]
      d0834013-dab8-44df-a5e4-123148f17e03 EFI System Area
   3: OpenBSD                              [        1024:    500117105 ]
      cd356d77-8369-44b4-996e-79e8b9a47bfe OpenBSD Area

MBR:
Disk: sd0       geometry: 31130/255/63 [500118192 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
 0: EE      0   0   2 -  31130 233  63 [           1:   500118191 ] EFI GPT
 1: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
 3: 00      0   0   0 -      0   0   0 [           0:           0 ] unused

When fdisk enters interactive command mode it copies the partition table from disk into memory and performs all edits on that copy. The partition table on disk is modified only by write or quit commands.

The prompt contains information about the state of the edit process.

disk*:1>

Where disk is the name of the disk being edited, ‘*’ means that the partition table has been modified, but not yet written to disk and 1 is the edit level when operating on the MBR or GPT. This number is 2 when editing an extended partition in the MBR, 3 when editing an extended partition within the edit level 2 extended partition, and so on.

The list of commands and their functions is given below. Commands may be abbreviated. The first command matching the abbreviation is selected.

A synonym for help.
Displays a short summary of available commands.
Displays this manual page.
[gpt | mbr]
Initializes the partition table.

By default an MBR partition table is initialized. If gpt is specified a GPT partition table is initialized, including the protective MBR.

#
Sets the identifier of the partition table entry.
#
Edit an entry in the partition table. The offset and size of the entry may be specified in CHS mode (MBR only), by using sector offsets and sizes, or by using the units ‘b’, ‘k’, ‘m’, ‘g’, or ‘t’ to indicate bytes, kilobytes, megabytes, gigabytes, or terabytes. The special size value ‘*’ causes the partition to be sized to use the remainder of the disk.
# [value]
Sets the partition entry's flag value. If value is not provided the partition entry is flagged as being bootable and all other partition entries are flagged as not bootable. Partition entries flagged as bootable are printed with a ‘*’ prefix.

If value is provided the partition entry's flag value is set to value and no other partition entry is modified. A value of 0 is used to clear the bootable flag.

Updates the MBR bootcode. If a bootcode file is present (see -f) the MBR, except for the partition entries, is replaced by the first block of the file. If no bootcode file is present, zeros are used.

Not available when editing a GPT.

#
Selects an extended partition entry, increasing the edit level by 1.

Not available when editing a GPT.

# #
Swaps two partition entries.
[unit]
Prints the partition table. If unit is ‘b’, ‘k’, ‘m’, ‘g’, or ‘t’ partition sizes are shown in bytes, kilobytes, megabytes, gigabytes, or terabytes. If unit is not provided, sizes are shown in sectors.
Writes the partition table to disk.
Discards outstanding changes and exits the current edit level. If the edit level is 1, fdisk terminates.
Writes outstanding changes to disk and exits the current edit level. If the edit level is 1, fdisk terminates.
Discards outstanding changes and terminates fdisk.

/usr/mdec/mbr
default MBR bootcode

disklabel(5), boot(8), boot_amd64(8), boot_i386(8), boot_macppc(8), disklabel(8)

July 18, 2022 OpenBSD-7.2