xref: /openbsd/sbin/fdisk/fdisk.8 (revision 74ae6390)
1.\"	$OpenBSD: fdisk.8,v 1.93 2016/09/03 14:25:05 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 3 2016 $
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 ] Win95 FAT-32
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 FAT-32 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 fdisk:*1>
346.Pp
347.Sq *
348means that the in-memory copy of the partition table has been modified, but
349not yet written to disk.
350.Pp
3511 is the disk offset of the currently selected boot block being edited.
352This number will be 2 when editing an extended MBR partition,
3533 when editing an extended MBR partition within an extended MBR partition,
354and so on.
355.Pp
356The list of commands and their explanations are given below.
357Commands may be abbreviated provided enough characters are given to ensure
358unambiguity.
359.Bl -tag -width Ds
360.It Cm ?\&
361A synonym for
362.Cm help .
363.It Cm help
364Display a list of commands that
365.Nm
366understands in the interactive edit mode.
367.It Cm manual
368Display this manual page.
369.It Cm reinit Op Cm gpt | Cm mbr
370Initialize the currently selected, in-memory copy of the
371boot block.
372If
373.Cm gpt
374is specified a protective MBR and a GPT are initialized.
375If
376.Cm mbr
377is specified only an MBR is initialized.
378If neither
379.Cm mbr
380nor
381.Cm gpt
382are specified then a protective MBR and a GPT are initialized if a protective
383MBR already exists.
384Otherwise only an MBR is initialized.
385.It Cm disk
386Display the current drive geometry that
387.Nm
388probed using kernel provided information and various heuristics.
389The disk geometry may be changed at this point.
390Not available when editing a GPT.
391.It Cm edit Ar #
392Edit a given table entry in the memory copy of
393the current boot block.
394Sizes may be adjusted in BIOS geometry mode (MBR only) or using
395sector offsets and sizes.
396A unit
397.Sq b ,
398.Sq k ,
399.Sq m ,
400or
401.Sq g
402may be appended to indicate bytes, kilobytes, megabytes, or gigabytes.
403The special size value
404.Sq *
405will cause the partition to be sized to use the remainder of the disk.
406.It Cm flag Ar # Op Ar value
407Make the given MBR partition table entry bootable
408and mark all others as not bootable
409(only one entry can be marked bootable).
410The bootable partition is denoted with
411.Sq * .
412.\" If you wish to boot from an extended
413.\" MBR partition, you will need to mark the MBR partition table entry for the
414.\" extended MBR partition as bootable.
415If a
416.Ar value
417of 0 is given,
418the MBR partition is marked as not bootable,
419but no other MBR partitions are touched.
420.It Cm update
421Update the machine MBR bootcode and 0xAA55 signature in the memory copy
422of the currently selected MBR.
423Note that this option will overwrite an NT disk
424signature, if present.
425Not available when editing a GPT.
426.It Cm select Ar #
427Select and load into memory the MBR pointed
428to by the extended MBR partition table entry in the current boot block.
429Not available when editing a GPT.
430.It Cm setpid Ar #
431Change the partition
432identifier of the given partition table entry.
433This command is particularly useful for reassigning
434an existing partition to
435.Ox .
436.It Cm swap Ar # Ar #
437Swap two partition entries.
438.It Cm print Op Ar unit
439Print the currently selected in-memory copy of the
440partition table to the terminal.
441A
442.Ar unit
443.Sq b ,
444.Sq k ,
445.Sq m ,
446or
447.Sq g
448may be appended to indicate bytes, kilobytes, megabytes, or gigabytes.
449Otherwise the number of sectors is printed.
450.It Cm write
451Write the in-memory copy of the partition table to disk.
452.It Cm exit
453Exit the current level of
454.Nm fdisk ,
455either returning to the
456previously selected in-memory copy of a MBR, or exiting the
457program if there is none.
458.It Cm quit
459Exit the current level of
460.Nm fdisk ,
461either returning to the
462previously selected in-memory copy of a MBR, or exiting the
463program if there is none.
464Unlike
465.Em exit
466it does write the modified block out.
467.It Cm abort
468Quit program without saving current changes.
469.El
470.Sh FILES
471.Bl -tag -width /usr/mdec/mbr -compact
472.It Pa /usr/mdec/mbr
473default MBR template
474.El
475.Sh SEE ALSO
476.Xr fstab 5 ,
477.Xr boot_amd64 8 ,
478.Xr boot_i386 8 ,
479.Xr boot_macppc 8 ,
480.Xr disklabel 8
481.Sh CAVEATS
482Hand crafted disk layouts are highly error prone.
483It is common practice,
484though by no means required,
485that MBR partitions start on a cylinder boundary
486(generally head 0, sector 1, but head 1, sector 1 for track 0),
487and that MBR partitions also end at cylinder boundaries.
488