xref: /openbsd-src/sbin/fdisk/fdisk.8 (revision 411db55cb24f3e2cf7c244d91d7912fb4f529ede)
1*411db55cSjmc.\"	$OpenBSD: fdisk.8,v 1.120 2024/09/29 18:00:38 jmc Exp $
210a68084Skrw.\"
3a1705421Sweingart.\"
4a1705421Sweingart.\" Copyright (c) 1997 Tobias Weingartner
5a1705421Sweingart.\"
610a68084Skrw.\" Permission to use, copy, modify, and distribute this software for any
710a68084Skrw.\" purpose with or without fee is hereby granted, provided that the above
810a68084Skrw.\" copyright notice and this permission notice appear in all copies.
9a1705421Sweingart.\"
1010a68084Skrw.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1110a68084Skrw.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1210a68084Skrw.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1310a68084Skrw.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1410a68084Skrw.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1510a68084Skrw.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1610a68084Skrw.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17df930be7Sderaadt.\"
18*411db55cSjmc.Dd $Mdocdate: September 29 2024 $
19df930be7Sderaadt.Dt FDISK 8
20fc8533a3Saaron.Os
21df930be7Sderaadt.Sh NAME
22df930be7Sderaadt.Nm fdisk
23158420d4Skrw.Nd partition table maintenance program
24df930be7Sderaadt.Sh SYNOPSIS
257349792aSaaron.Nm fdisk
26f43a9f23Skrw.Op Fl evy
27f43a9f23Skrw.Op Fl A  | g | i | u
284d22bfe1Sderaadt.Op Fl b Ar blocks Ns Op @ Ns Ar offset Ns Op : Ns Ar type
2995e8765cSkrw.Op Fl l Ar blocks | Fl c Ar cylinders Fl h Ar heads Fl s Ar sectors
307f367d37Skrw.Op Fl f Ar file
314b849b11Sderaadt.Ar disk
32a1705421Sweingart.Sh DESCRIPTION
3389a8290dSderaadt.Nm fdisk
347f367d37Skrwcreates and edits MBR and GPT partition tables.
357f367d37SkrwThese tables are used by the boot process of some
367f367d37Skrwplatforms to find the
37f941d2b2Sjmc.Ox
387f367d37Skrwkernel and, when present, are used by the kernel to find the
3989a8290dSderaadt.Xr disklabel 5 .
4089a8290dSderaadt.Pp
417f367d37SkrwCaution is advised when editing these tables since some platforms
427f367d37Skrwrely on specific configurations created at install time.
435b628108Sderaadt.Pp
444282d8e3SrayThe options are as follows:
454282d8e3Sray.Bl -tag -width Ds
4695e8765cSkrw.It Fl A
477f367d37SkrwModifies the GPT partition table entries on
487f367d37Skrw.Ar disk
497f367d37Skrwto put all available space not taken by
5095e8765cSkrw.Fl b
517f367d37Skrwinto a single
527f367d37Skrw.Ox
5395e8765cSkrwpartition.
54ae4d93deSkrwThe available space is maximized by deleting all existing partition
55ae4d93deSkrwentries except for partition types APFS ISC, APFS, APFS Recovery, BIOS Boot,
56ae4d93deSkrwHiFive FSBL, HiFive BBL and partitions with the
57ae4d93deSkrw.Sq Required
58ae4d93deSkrwGPT attribute set.
5965deb39bSkrw.Pp
607f367d37SkrwIf
617f367d37SkrwAPFS ISC, APFS, or APFS Recovery
627f367d37Skrwpartitions are detected then existing
637f367d37SkrwEFI system
647f367d37Skrwpartitions are also preserved.
657f367d37SkrwIf the preserved EFI system partition has fewer blocks
667f367d37Skrwthan the number requested with
6741ce3b17Snaddy.Fl b ,
687f367d37Skrwthe modified GPT is discarded.
694d22bfe1Sderaadt.It Fl b Ar blocks Ns Op @ Ns Ar offset Ns Op : Ns Ar type
707f367d37SkrwCreates a partition table entry of the specified number of blocks, offset
71353d3493Skrwand type.
72353d3493Skrw.Ar offset
73353d3493Skrwdefaults to the first available block, and
74353d3493Skrw.Ar type
75353d3493Skrwdefaults to
76353d3493Skrw.Sq EF .
77353d3493Skrw.Pp
787f367d37Skrw.Fl b
797f367d37Skrwis only available in combination with
80f43a9f23Skrw.Fl A ,
81f43a9f23Skrw.Fl g ,
8295e8765cSkrwor
83f43a9f23Skrw.Fl i .
847f367d37Skrw.Pp
85f43a9f23SkrwIf
86f43a9f23Skrw.Fl A
87f43a9f23Skrwor
88f43a9f23Skrw.Fl g
89f43a9f23Skrwis specified, only the
90bf95c6fdSkrw.Ar blocks
91353d3493Skrwvalue is used.
9264c9f6d5Sjmc.It Xo
9364c9f6d5Sjmc.Fl c Ar cylinders
9464c9f6d5Sjmc.Fl h Ar heads
954282d8e3Sray.Fl s Ar sectors
964282d8e3Sray.Xc
977f367d37SkrwSpecifies a geometry for
984282d8e3Sray.Nm
994282d8e3Srayto use.
1007f367d37SkrwBy default the disk size and geometry are obtained
1017f367d37Skrwfrom the default
1027f367d37Skrw.Xr disklabel 5
1037f367d37Skrwconstructed by the kernel for
1047f367d37Skrw.Ar disk .
105eb99c4cdSjmcSee
1067f367d37Skrw.Xr disklabel 5
1077f367d37Skrwand
1087f367d37Skrw.Xr disklabel 8 .
1097f367d37Skrw.It Fl e
1107f367d37SkrwInvokes the interactive partition table editor.
1117f367d37SkrwSee
1127f367d37Skrw.Sx COMMAND MODE
1137f367d37Skrwbelow.
1147f367d37Skrw.It Fl f Ar file
1157f367d37SkrwSpecifies a file containing the bootcode for an MBR.
1164282d8e3SrayThe default file is
1174282d8e3Sray.Pa /usr/mdec/mbr .
1181f546e5fSjsing.It Fl g
1197f367d37SkrwWrites a default GPT, including a protective MBR, to
120f43a9f23Skrw.Ar disk .
1217f367d37SkrwThe GPT has a single
1221f546e5fSjsing.Ox
1237f367d37Skrwpartition containing all available space not taken by
124f43a9f23Skrw.Fl b .
1254282d8e3Sray.It Fl i
1267f367d37SkrwWrites a default MBR to
127f43a9f23Skrw.Ar disk .
1287f367d37SkrwThe MBR has a single
1294282d8e3Sray.Ox
1307f367d37Skrwpartition containing all the available space not taken by
131f43a9f23Skrw.Fl b .
1327f367d37SkrwThe bootcode is initialized as described in
1337f367d37Skrw.Fl u .
1347f367d37Skrw.It Fl l Ar count
135f43a9f23SkrwTreat
136f43a9f23Skrw.Ar disk
1377f367d37Skrwas though it has a size of
1387f367d37Skrw.Ar count
1397f367d37Skrwblocks.
1404282d8e3Sray.It Fl u
1417f367d37SkrwUpdates the MBR bootcode.
1427f367d37SkrwIf a bootcode file is present (see
1437f367d37Skrw.Fl f )
1447f367d37Skrwthe MBR, except for the partition entries, is replaced by
1457f367d37Skrwthe first block of the file.
1467f367d37SkrwIf no bootcode file is present, zeros are used.
1477f367d37Skrw.Pp
148a15ff946SkrwNot available when editing a GPT.
149fbf68f68Skrw.It Fl v
1507f367d37SkrwPrints detailed information about the MBR, the Primary GPT and the
1517f367d37SkrwSecondary GPT.
1524282d8e3Sray.It Fl y
1537f367d37SkrwNew or modified partition table is written to disk without
1547f367d37Skrwasking for confirmation.
1554b849b11Sderaadt.It Ar disk
1567f367d37Skrw.Nm
1577f367d37Skrwcreates or modifies the partition table of
1587f367d37Skrw.Ar disk .
1594b849b11Sderaadt.Ar disk
1607f367d37Skrwcan be a full pathname,
1617f367d37Skrwe.g.
1627f367d37Skrw.Pa /dev/rsd0c ,
1637f367d37Skrwa raw partition name, e.g.
1647f367d37Skrw.Pa sd0c ,
1657f367d37Skrwor just the disk name, e.g.
1667f367d37Skrw.Pa sd0 .
1674282d8e3Sray.El
16801040c1bSderaadt.Sh TYPICAL LAYOUT
169*411db55cSjmcWhen called without options,
17001040c1bSderaadt.Nm
1717f367d37Skrwprints the partition table of
172f43a9f23Skrw.Ar disk .
173158420d4Skrw.Pp
174f43a9f23SkrwIf
175f43a9f23Skrw.Ar disk
1767f367d37Skrwhas a GPT a terse version of its contents is printed:
1777f367d37Skrw.Bd -literal -offset 1n
1787f367d37Skrw# fdisk sd0
1797f367d37SkrwDisk: sd0       Usable LBA: 64 to 500118128 [500118192 Sectors]
1807f367d37Skrw   #: type                                 [       start:         size ]
1817f367d37Skrw------------------------------------------------------------------------
1827f367d37Skrw   1: EFI Sys                              [          64:          960 ]
1837f367d37Skrw   3: OpenBSD                              [        1024:    500117105 ]
1847f367d37Skrw.Ed
1857f367d37Skrw.Pp
1867f367d37SkrwWhen
1877f367d37Skrw.Ar disk
1887f367d37Skrwdoes not have a GPT, the first block of
1897f367d37Skrw.Ar disk
1907f367d37Skrwis printed as an MBR:
191c9943843Sjmc.Bd -literal -offset 1n
19222d3f465Skrw# fdisk sd0
19322d3f465SkrwDisk: sd0      geometry: 121601/255/63 [1953525168 Sectors]
19401040c1bSderaadtOffset: 0      Signature: 0xAA55
19501040c1bSderaadt           Starting       Ending      LBA Info:
19601040c1bSderaadt #: id     C  H  S -      C   H  S [     start:       size ]
19722d3f465Skrw------------------------------------------------------------------------
1989179f1f6Ssobrado 0: 0B     0  1  1 -  26108   0 63 [        63:  419425020 ] FAT32
19901040c1bSderaadt 1: 00     0  0  0 -      0   0  0 [         0:          0 ] unused
20001040c1bSderaadt 2: 00     0  0  0 -      0   0  0 [         0:          0 ] unused
20122d3f465Skrw*3: A6 26108  1  1 - 121600 254 63 [ 419425083: 1534094982 ] OpenBSD
20201040c1bSderaadt.Ed
20301040c1bSderaadt.Pp
2047f367d37Skrw.Em NOTE :
2057f367d37SkrwPartition entry #3 of this MBR is flagged as bootable.
20601040c1bSderaadt.Pp
20701040c1bSderaadt.Em NOTE :
2087f367d37SkrwThe
2097f367d37Skrw.Em S
2107f367d37Skrwfield in the C/H/S values is
21101040c1bSderaadt.Dq 1 based ,
21237a24919Sjmcbut the LBA "start" field is
21301040c1bSderaadt.Dq 0 based .
21437a24919Sjmc.Pp
2157f367d37SkrwThe
2167f367d37Skrw.Fl v
2177f367d37Skrwoption causes more information to be printed:
218158420d4Skrw.Bd -literal -offset 1n
2197f367d37Skrw# fdisk -v sd0
2207f367d37SkrwPrimary GPT:
2217f367d37SkrwDisk: sd0       Usable LBA: 64 to 500118128 [500118192 Sectors]
2227f367d37SkrwGUID: f0418899-4976-4604-a783-3ebe135a8f12
22377db81deSkrw   #: type                                 [       start:         size ]
2247f367d37Skrw      guid                                 name
22577db81deSkrw------------------------------------------------------------------------
22677db81deSkrw   1: EFI Sys                              [          64:          960 ]
2277f367d37Skrw      d0834013-dab8-44df-a5e4-123148f17e03 EFI System Area
2287f367d37Skrw   3: OpenBSD                              [        1024:    500117105 ]
2297f367d37Skrw      cd356d77-8369-44b4-996e-79e8b9a47bfe OpenBSD Area
23001040c1bSderaadt
2317f367d37SkrwSecondary GPT:
2327f367d37SkrwDisk: sd0       Usable LBA: 64 to 500118128 [500118192 Sectors]
2337f367d37SkrwGUID: f0418899-4976-4604-a783-3ebe135a8f12
2347f367d37Skrw   #: type                                 [       start:         size ]
2357f367d37Skrw      guid                                 name
2367f367d37Skrw------------------------------------------------------------------------
2377f367d37Skrw   1: EFI Sys                              [          64:          960 ]
2387f367d37Skrw      d0834013-dab8-44df-a5e4-123148f17e03 EFI System Area
2397f367d37Skrw   3: OpenBSD                              [        1024:    500117105 ]
2407f367d37Skrw      cd356d77-8369-44b4-996e-79e8b9a47bfe OpenBSD Area
2417f367d37Skrw
2427f367d37SkrwMBR:
2437f367d37SkrwDisk: sd0       geometry: 31130/255/63 [500118192 Sectors]
2447f367d37SkrwOffset: 0       Signature: 0xAA55
2457f367d37Skrw            Starting         Ending         LBA Info:
2467f367d37Skrw #: id      C   H   S -      C   H   S [       start:        size ]
2477f367d37Skrw-------------------------------------------------------------------------------
2487f367d37Skrw 0: EE      0   0   2 -  31130 233  63 [           1:   500118191 ] EFI GPT
2497f367d37Skrw 1: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
2507f367d37Skrw 2: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
2517f367d37Skrw 3: 00      0   0   0 -      0   0   0 [           0:           0 ] unused
25201040c1bSderaadt.Ed
25301040c1bSderaadt.Sh COMMAND MODE
2547f367d37SkrwWhen
255a1705421Sweingart.Nm
256*411db55cSjmcenters interactive command mode,
2577f367d37Skrwit copies the partition table from
2587f367d37Skrw.Ar disk
2597f367d37Skrwinto memory and performs all edits on
2607f367d37Skrwthat copy.
2617f367d37SkrwThe partition table on
2627f367d37Skrw.Ar disk
2637f367d37Skrwis modified only by
2647f367d37Skrw.Em write
2657f367d37Skrwor
2667f367d37Skrw.Em quit
2677f367d37Skrwcommands.
2687f367d37Skrw.Pp
26901040c1bSderaadtThe prompt contains information about the state of the edit
27001040c1bSderaadtprocess.
27101040c1bSderaadt.Pp
272cbfc0aa2Skrw.Dl Ar disk Ns *:1>
273c9943843Sjmc.Pp
274cbfc0aa2SkrwWhere
275cbfc0aa2Skrw.Ar disk
276cbfc0aa2Skrwis the name of the disk being edited,
277c9943843Sjmc.Sq *
2787f367d37Skrwmeans that the partition table has been modified, but
279cbfc0aa2Skrwnot yet written to disk and
2807f367d37Skrw1 is the edit level when operating on the MBR or GPT.
2817f367d37SkrwThis number is 2 when editing an extended partition in the MBR,
2827f367d37Skrw3 when editing an extended partition within the edit level 2
2837f367d37Skrwextended partition, and so on.
28401040c1bSderaadt.Pp
2857f367d37SkrwThe list of commands and their functions is
2867f367d37Skrwgiven below.
2877f367d37SkrwCommands may be abbreviated.
2887f367d37SkrwThe first command matching the abbreviation is selected.
28901040c1bSderaadt.Bl -tag -width Ds
29067bd9dbbSjmc.It Cm ?\&
29167bd9dbbSjmcA synonym for
29267bd9dbbSjmc.Cm help .
29367bd9dbbSjmc.It Cm help
2947f367d37SkrwDisplays a short summary of available commands.
29567bd9dbbSjmc.It Cm manual
2967f367d37SkrwDisplays this manual page.
297158420d4Skrw.It Cm reinit Op Cm gpt | Cm mbr
2987f367d37SkrwInitializes the partition table.
299c94b0391Skrw.Pp
3007f367d37SkrwBy default an MBR partition table is initialized.
301158420d4SkrwIf
302158420d4Skrw.Cm gpt
3037f367d37Skrwis specified a GPT partition table is initialized, including the
3047f367d37Skrwprotective MBR.
305fa72fed3Skrw.It Cm setpid Ar #
306fa72fed3SkrwSets the identifier of the partition table entry.
30767bd9dbbSjmc.It Cm edit Ar #
3087f367d37SkrwEdit an entry in the partition table.
3097f367d37SkrwThe offset and size of the entry may be specified in CHS mode (MBR only),
3107f367d37Skrwby using sector offsets and sizes, or by using
3117f367d37Skrwthe units
31267bd9dbbSjmc.Sq b ,
31367bd9dbbSjmc.Sq k ,
31467bd9dbbSjmc.Sq m ,
31559f8c167Snaddy.Sq g ,
31667bd9dbbSjmcor
31759f8c167Snaddy.Sq t
3187f367d37Skrwto indicate bytes, kilobytes, megabytes, gigabytes, or terabytes.
31967bd9dbbSjmcThe special size value
32067bd9dbbSjmc.Sq *
3217f367d37Skrwcauses the partition to be sized to use the remainder of the disk.
3223902c032Sjmc.It Cm flag Ar # Op Ar value
32385135147SkrwSet the partition's flag (MBR) or attribute (GPT) value.
32485135147Skrw.Ar value
32585135147Skrwcan be a positive integer or a hex string.
32685135147SkrwAn MBR partition will accept values from 0 to 0xff.
32785135147SkrwA GPT partition will accept values from 0 to 0xfffffffffffffff.
3287f367d37SkrwIf
3293902c032Sjmc.Ar value
330*411db55cSjmcis not provided, the partition's bootable flag is set
33185135147Skrwand all other partitions have their bootable flags reset.
33285135147SkrwMBR partitions with the bootable flag set are printed with a
3337f367d37Skrw.Sq *
3347f367d37Skrwprefix.
33585135147SkrwGPT partitions with the bootable flag set display 'bootable' in
33685135147Skrwtheir attributes list.
33767bd9dbbSjmc.It Cm update
3387f367d37SkrwUpdates the MBR bootcode.
3397f367d37SkrwIf a bootcode file is present (see
3407f367d37Skrw.Fl f )
3417f367d37Skrwthe MBR, except for the partition entries, is replaced by
3427f367d37Skrwthe first block of the file.
3437f367d37SkrwIf no bootcode file is present, zeros are used.
3447f367d37Skrw.Pp
345158420d4SkrwNot available when editing a GPT.
34667bd9dbbSjmc.It Cm select Ar #
3477f367d37SkrwSelects an extended partition entry, increasing the edit level by 1.
3487f367d37Skrw.Pp
349158420d4SkrwNot available when editing a GPT.
35067bd9dbbSjmc.It Cm swap Ar # Ar #
3517f367d37SkrwSwaps two partition entries.
35267bd9dbbSjmc.It Cm print Op Ar unit
3537f367d37SkrwPrints the partition table.
3547f367d37SkrwIf
355e238ed06Sray.Ar unit
3567f367d37Skrwis
357e238ed06Sray.Sq b ,
358e238ed06Sray.Sq k ,
359e238ed06Sray.Sq m ,
36059f8c167Snaddy.Sq g ,
361e238ed06Srayor
36259f8c167Snaddy.Sq t
3637f367d37Skrwpartition sizes are shown in bytes,
3647f367d37Skrwkilobytes, megabytes, gigabytes, or terabytes.
3657f367d37SkrwIf
3667f367d37Skrw.Ar unit
3677f367d37Skrwis not provided, sizes are shown in sectors.
36867bd9dbbSjmc.It Cm write
3697f367d37SkrwWrites the partition table to disk.
37067bd9dbbSjmc.It Cm exit
37106b3f8b3SkrwDiscards outstanding changes and exits the current edit level.
37206b3f8b3SkrwIf the edit level is 1,
37306b3f8b3Skrw.Nm
37406b3f8b3Skrwterminates.
37506b3f8b3Skrw.It Cm quit
3767f367d37SkrwWrites outstanding changes to disk and exits the current edit
3777f367d37Skrwlevel.
3787f367d37SkrwIf the edit level is 1,
3797f367d37Skrw.Nm
3807f367d37Skrwterminates.
38167bd9dbbSjmc.It Cm abort
38206b3f8b3SkrwDiscards outstanding changes and terminates
38306b3f8b3Skrw.Nm .
384a1705421Sweingart.El
385acb5e83fSderaadt.Sh FILES
3865eaf1a72Saaron.Bl -tag -width /usr/mdec/mbr -compact
3875eaf1a72Saaron.It Pa /usr/mdec/mbr
3887f367d37Skrwdefault MBR bootcode
3895eaf1a72Saaron.El
390df930be7Sderaadt.Sh SEE ALSO
3917f367d37Skrw.Xr disklabel 5 ,
3927f367d37Skrw.Xr boot 8 ,
39301040c1bSderaadt.Xr boot_amd64 8 ,
3947acc01d2Saaron.Xr boot_i386 8 ,
39501040c1bSderaadt.Xr boot_macppc 8 ,
3967acc01d2Saaron.Xr disklabel 8
397