xref: /openbsd/sbin/fdisk/fdisk.8 (revision 8932bfb7)
1.\"	$OpenBSD: fdisk.8,v 1.74 2010/12/03 08:14:56 jmc Exp $
2.\"
3.\" Copyright (c) 1997 Tobias Weingartner
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.Dd $Mdocdate: December 3 2010 $
27.Dt FDISK 8
28.Os
29.Sh NAME
30.Nm fdisk
31.Nd MBR partition maintenance program
32.Sh SYNOPSIS
33.Nm fdisk
34.Op Fl eiuy
35.Oo
36.Fl c Ar cylinders
37.Fl h Ar heads
38.Fl s Ar sectors
39.Oc
40.Op Fl f Ar mbrfile
41.Ar disk
42.Sh DESCRIPTION
43On the i386 and other architectures, sector 0 of a bootable hard disk
44must contain MBR bootcode, the MBR partition table containing 4 slots,
45and a specific magic number (0xAA55).
46The 4 slots in the MBR partition table allow a disk drive to be
47divided into chunks known as MBR partitions.
48.Pp
49On the i386, the BIOS loads sector 0 of the boot disk into memory,
50verifies the magic number, and begins executing the MBR bootcode
51at the first byte.
52The MBR bootcode then searches the MBR partition table for an
53.Dq active
54MBR partition (indicated by a
55.Ql \&*
56in the first column), and if one
57is found, the boot block from that MBR partition is loaded and executed in
58place of the original (MBR) boot block.
59.Pp
60Some other architectures (like the zaurus), consider sector 0 of the disk
61to contain the MBR partition table, but do not use the MBR bootcode at all.
62.Pp
63Upon first access to a disk, the partition information is retrieved,
64typically in
65.Xr disklabel 5
66format.
67The location of the disklabel can vary from architecture to architecture,
68but if one is not found the existence of an MBR partition table will create
69a spoofed prototypical disklabel which can be viewed using
70.Xr disklabel 8 .
71This spoofing mechanism is useful for permitting partition access for
72devices which would not normally have a
73.Xr disklabel 5
74sector.
75.Pp
76The options are as follows:
77.Bl -tag -width Ds
78.It Xo
79.Fl c Ar cylinders
80.Fl h Ar heads
81.Fl s Ar sectors
82.Xc
83Specifies an alternate BIOS geometry for
84.Nm
85to use.
86By default, an automatic calculation of disk size will be built
87using heuristics.
88These figures are taken from the in-core disklabel
89(see
90.Xr disklabel 8 ) ,
91or values that
92.Em /boot
93has passed to the kernel.
94.It Fl e
95Use the
96.Nm
97interactive editor to modify an MBR partition table.
98The editor permits configuration of the MBR partition, as well as
99extended MBR partitions.
100See
101.Sx COMMAND MODE ,
102below, for more information.
103.It Fl f Ar mbrfile
104Specifies an alternate MBR template file.
105The default file is
106.Pa /usr/mdec/mbr .
107.It Fl i
108Requests that the MBR partition data be re-initialized.
109In this mode,
110.Nm
111will completely overwrite the primary MBR bootcode and MBR partition table
112using the default MBR template
113.Pa /usr/mdec/mbr
114(or the one optionally specified by the
115.Fl f
116flag).
117In the default template, MBR partition number 3 will be configured as an
118.Ox
119MBR partition spanning the entire disk, except for a zone left at the start
120for booting.
121This mode is designed to initialize the MBR the very first time.
122.It Fl u
123Update MBR bootcode, preserving existing MBR partition table.
124The MBR bootcode extends from offset 0x000 to the start of the MBR partition table
125at offset 0x1BE.
126It is similar to the
127.Fl i
128flag, except the existing MBR partition table is preserved.
129This is useful for writing new MBR bootcode onto an existing drive, and is
130equivalent to the DOS command
131.Dq FDISK /MBR .
132Note that this option will overwrite the NT disk signature, if present.
133.It Fl y
134Avoid asking yes/no questions when not desirable.
135.It Ar disk
136Specify the
137.Ar disk
138to operate on.
139It can be specified either by its full pathname or an abbreviated disk form.
140In its abbreviated form, the path to the device, the
141.Sq r
142denoting
143.Qq raw device ,
144and the partition letter, can all be omitted.
145For example, the first IDE disk can be specified as either
146.Pa /dev/rwd0c ,
147.Pa /dev/wd0c ,
148or
149.Ar wd0 .
150.El
151.Sh TYPICAL LAYOUT
152When called with no special flags,
153.Nm
154prints the MBR partition table of the specified disk:
155.Bd -literal -offset 1n
156# fdisk sd0
157Disk: sd0       geometry: 121601/255/63 [1953525168 Sectors]
158Offset: 0       Signature: 0xAA55
159          Starting     Ending    LBA Info:
160 #: id     C H S -      C   H  S [     start:       size ]
161------------------------------------------------------------------------
162 0: 0B     0 1 1 -  26108   0 63 [        63:  419425020 ] Win95 FAT-32
163 1: 00     0 0 0 -      0   0  0 [         0:          0 ] unused
164 2: 00     0 0 0 -      0   0  0 [         0:          0 ] unused
165*3: A6 26108 1 1 - 121600 254 63 [ 419425083: 1534094982 ] OpenBSD
166.Ed
167.Pp
168This 1953525168 sector (931GB) disk drive is divided into two MBR
169partitions that span the whole disk.
170The first MBR partition is a 200GB FAT-32 partition,
171the second is a 731GB
172.Ox
173MBR partition using the remainder of the disk.
174The fields of the output are:
175.Bl -tag -width "start/size"
176.It Em "#"
177Number identifying each MBR partition table entry.
178There are a total of four slots.
179.Sq *
180denotes the MBR partition which is declared bootable.
181.It Em "id"
182MBR partition type identifier.
183.Ox
184reserves the
185magic number hexadecimal A6 (166 decimal).
186.It Em "C/H/S"
187These fields provide the starting and ending address of the MBR partition
188in BIOS geometry.
189.It Em "start/size"
190These fields provide the starting sector and size in sectors of the
191MBR partition in linear block addresses.
192.El
193.Pp
194.Em NOTE :
195The BIOS geometry sectors field (C/H/S) is
196.Dq 1 based ,
197but the LBA "start" field is
198.Dq 0 based .
199.Pp
200The CHS values will need to be in the BIOS's geometry
201for the system to be able to boot and use the drive correctly.
202These values must be kept correctly synchronized or a variety of
203problems develop which are very difficult to diagnose.
204.Pp
205The
206.Ox
207MBR partition shown above is subdivided further using the
208functionality provided by
209.Xr disklabel 8 ,
210which provides
211.Ox
212partitions.
213.Bd -literal -offset 1n
214# /dev/rsd0c:
215type: SCSI
216disk: SCSI disk
217label: WDC WD10EADS-65L
218duid: 085ef8d68623f5b3
219flags:
220bytes/sector: 512
221sectors/track: 63
222tracks/cylinder: 255
223sectors/cylinder: 16065
224cylinders: 121601
225total sectors: 1953525168
226boundstart: 419425083
227boundend: 1953520065
228drivedata: 0
229
23016 partitions:
231#                size           offset  fstype [fsize bsize  cpg]
232  a:          2097125        419425083  4.2BSD   2048 16384    1
233  b:          4715520        421522208    swap
234  c:       1953525168                0  unused
235  d:          8388608        426237728  4.2BSD   2048 16384    1
236  e:         16771072        434626336  4.2BSD   2048 16384    1
237  f:          4194304        451397408  4.2BSD   2048 16384    1
238  g:          2097152        455591712  4.2BSD   2048 16384    1
239  h:         20971520        457688864  4.2BSD   2048 16384    1
240  i:        419425020               63   MSDOS
241  j:          4194304        478660384  4.2BSD   2048 16384    1
242  k:          4194304        482854688  4.2BSD   2048 16384    1
243  l:        629145536        487049024  4.2BSD   4096 32768    1
244.Ed
245.Pp
246These
247.Ox
248partitions are then mounted as follows using
249.Pa /etc/fstab :
250.Bd -literal -offset indent
251/dev/sd0a / ffs rw,softdep 1 1
252/dev/sd0d /tmp ffs rw,softdep,nodev,nosuid 1 2
253/dev/sd0e /var ffs rw,softdep,nodev,nosuid 1 2
254/dev/sd0f /usr ffs rw,softdep,nodev 1 2
255/dev/sd0g /usr/X11R6 ffs rw,softdep,nodev 1 2
256/dev/sd0h /usr/local ffs rw,softdep,nodev 1 2
257/dev/sd0i /mnt/example msdos rw,nodev,nosuid 1 2
258/dev/sd0j /usr/src ffs rw,softdep,nodev,nosuid 1 2
259/dev/sd0k /usr/obj ffs rw,softdep,nodev,nosuid 1 2
260/dev/sd0l /home ffs rw,softdep,nodev,nosuid 1 2
261.Ed
262.Sh COMMAND MODE
263The
264.Fl e
265flag causes
266.Nm
267to enter an interactive command mode.
268The prompt contains information about the state of the edit
269process.
270.Pp
271.Dl fdisk:*1\*(Gt
272.Pp
273.Sq *
274means that the in-memory copy of the boot block has been modified, but
275not yet written to disk.
276.Pp
2771 is the disk offset of the currently selected boot block being edited.
278This number will be 2 when editing an extended MBR partition,
2793 when editing an extended MBR partition within an extended MBR partition,
280and so on.
281.Pp
282The list of commands and their explanations are given below.
283Commands may be abbreviated provided enough characters are given to ensure
284unambiguity.
285.Bl -tag -width Ds
286.It Cm ?\&
287A synonym for
288.Cm help .
289.It Cm help
290Display a list of commands that
291.Nm
292understands in the interactive edit mode.
293.It Cm manual
294Display this manual page.
295.It Cm reinit
296Initialize the currently selected, in-memory copy of the
297boot block.
298.It Cm disk
299Display the current drive geometry that
300.Nm
301probed using kernel provided information and various heuristics.
302The disk geometry may be changed at this point.
303.It Cm edit Ar #
304Edit a given table entry in the memory copy of
305the current boot block.
306Sizes may be adjusted in BIOS geometry mode or using sector offsets and sizes.
307A unit
308.Sq b ,
309.Sq k ,
310.Sq m ,
311or
312.Sq g
313may be appended to indicate bytes, kilobytes, megabytes, or gigabytes.
314The special size value
315.Sq *
316will cause the partition to be sized to use the remainder of the disk.
317.It Cm flag Ar # Op Ar value
318Make the given MBR partition table entry bootable
319and mark all others as not bootable
320(only one entry can be marked bootable).
321.\" If you wish to boot from an extended
322.\" MBR partition, you will need to mark the MBR partition table entry for the
323.\" extended MBR partition as bootable.
324If a
325.Ar value
326of 0 is given,
327the MBR partition is marked as not bootable,
328but no other MBR partitions are touched.
329.It Cm update
330Update the machine MBR bootcode and 0xAA55 signature in the memory copy
331of the currently selected boot block.
332Note that this option will overwrite an NT disk
333signature, if present.
334.It Cm select Ar #
335Select and load into memory the boot block pointed
336to by the extended MBR partition table entry in the current boot block.
337.It Cm setpid Ar #
338Change the MBR partition
339identifier of the given MBR partition table entry.
340This command is particularly useful for reassigning
341an existing MBR partition to
342.Ox .
343.It Cm swap Ar # Ar #
344Swap two MBR entries.
345.It Cm print Op Ar unit
346Print the currently selected in-memory copy of the boot
347block and its MBR table to the terminal.
348A
349.Ar unit
350.Sq b ,
351.Sq k ,
352.Sq m ,
353or
354.Sq g
355may be appended to indicate bytes, kilobytes, megabytes, or gigabytes.
356Otherwise the number of sectors is printed.
357.It Cm write
358Write the in-memory copy of the boot block to disk.
359.It Cm exit
360Exit the current level of
361.Nm fdisk ,
362either returning to the
363previously selected in-memory copy of a boot block, or exiting the
364program if there is none.
365.It Cm quit
366Exit the current level of
367.Nm fdisk ,
368either returning to the
369previously selected in-memory copy of a boot block, or exiting the
370program if there is none.
371Unlike
372.Em exit
373it does write the modified block out.
374.It Cm abort
375Quit program without saving current changes.
376.El
377.Sh FILES
378.Bl -tag -width /usr/mdec/mbr -compact
379.It Pa /usr/mdec/mbr
380default MBR template
381.El
382.Sh SEE ALSO
383.Xr fstab 5 ,
384.Xr boot_amd64 8 ,
385.Xr boot_armish 8 ,
386.Xr boot_i386 8 ,
387.Xr boot_landisk 8 ,
388.Xr boot_macppc 8 ,
389.Xr boot_zaurus 8 ,
390.Xr disklabel 8
391.Sh CAVEATS
392Hand crafted disk layouts are highly error prone.
393It is common practice,
394though by no means required,
395that MBR partitions start on a cylinder boundary
396(generally head 0, sector 1, but head 1, sector 1 for track 0),
397and that MBR partitions also end at cylinder boundaries.
398