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