summaryrefslogtreecommitdiff
path: root/sbin/fdisk/fdisk.8
blob: a4d5db6127e4001a5f76f7a612fb4910d68c06cb (plain)
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
.\"	$OpenBSD: fdisk.8,v 1.65 2008/02/18 21:33:05 sobrado Exp $
.\"
.\" Copyright (c) 1997 Tobias Weingartner
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: February 18 2008 $
.Dt FDISK 8
.Os
.Sh NAME
.Nm fdisk
.Nd MBR partition maintenance program
.Sh SYNOPSIS
.Nm fdisk
.Op Fl eiuy
.Oo
.Fl c Ar cylinders
.Fl h Ar heads
.Fl s Ar sectors
.Oc
.Op Fl f Ar mbrfile
.Ar device
.Sh DESCRIPTION
On the i386 and other architectures, sector 0 of a bootable hard disk
must contain MBR bootcode, the MBR partition table containing 4 slots,
and a specific magic number (0xAA55).
The 4 slots in the MBR partition table allow a disk drive to be
sub-divided up into chunks known as MBR partitions.
.Pp
On the i386, the BIOS loads sector 0 of the boot disk into memory,
verifies the magic number, and begins executing the MBR bootcode
at the first byte.
The MBR bootcode then searches the MBR partition table for an
.Dq active
MBR partition (indicated by a
.Ql \&*
in the first column), and if one
is found, the boot block from that MBR partition is loaded and executed in
place of the original (MBR) boot block.
.Pp
Some other architectures (like the zaurus), consider sector 0 of the disk
to contain the MBR partition table, but do not use the MBR bootcode at all.
.Pp
Upon first access to a disk, the partition information is retrieved,
typically in
.Xr disklabel 5
format.
The location of the disklabel can vary from architecture to architecture,
but if one is not found the existence of an MBR partition table will create
a spoofed prototypical disklabel which can be viewed using
.Xr disklabel 8 .
This spoofing mechanism is useful for permitting partition access for
devices which would not normally have a
.Xr disklabel 5
sector.
.Pp
The options are as follows:
.Bl -tag -width Ds
.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 interactive edit of
.Nm
to modify an MBR partition table.
The editor permits configuration of the MBR partition, as well as
extended MBR partitions.
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 i
Requests that the MBR partition data be re-initialized.
In this mode,
.Nm
will completely overwrite the primary MBR bootcode and MBR partition table
using 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 spanning from cylinder 0, head 1, sector 1, and extending
to the end of the disk.
This mode is designed to initialize the MBR the very first time.
.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 y
Avoid asking yes/no questions when not desirable.
.El
.Sh TYPICAL LAYOUT
When called with no special flags,
.Nm
prints the MBR partition table of the specified device:
.Bd -literal -offset 1n
# fdisk wd0
Disk: wd0       geometry: 5168/240/63 [78140160 Sectors]
Offset: 0       Signature: 0xAA55
          Starting      Ending        LBA Info:
 #: id    C   H  S -    C   H  S [       start:      size   ]
-------------------------------------------------------------------------
 0: 04    0   1  1 -  170   0 63 [          63:     2570462 ] DOS FAT-16
 1: 00    0   0  0 -    0   0  0 [           0:           0 ] unused
 2: 00    0   0  0 -    0   0  0 [           0:           0 ] unused
*3: A6  170   1  1 - 5167 239 63 [     2570463:    75569697 ] OpenBSD
.Ed
.Pp
This 78140160 sector (38154MB) disk drive is divided into two MBR
partitions that span the whole disk.
The first MBR partition is a 1225MB FAT-16 DOS partition
(in this case containing a Phoenix BIOS Laptop Suspend-to-Disk file),
the second is a 36GB
.Ox
MBR partition using the remainder of the disk.
The fields of the output are thus:
.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 is
.Dq 1 based ,
but the start field is
.Dq 0 based .
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
The
.Ox
MBR partition shown above is subdivided further using the
functionality provided by
.Xr disklabel 8 ,
which provides
.Ox
partitions.
.Bd -literal -offset 1n
# Inside MBR partition 3: type A6 start 2570463 size 75569697
# /dev/rwd0c:
type: ESDI
disk: ESDI/IDE disk
label: HITACHI_DK13FA-4
flags:
bytes/sector: 512
sectors/track: 63
tracks/cylinder: 16
sectors/cylinder: 1008
cylinders: 16383
total sectors: 78140160
rpm: 3600
interleave: 1
trackskew: 0
cylinderskew: 0
headswitch: 0           # microseconds
track-to-track seek: 0  # microseconds
drivedata: 0

16 partitions:
#           size     offset  fstype [fsize bsize  cpg]
  a:     1740753    2570463  4.2BSD   2048 16384  328 # Cyl  2550*-  4276
  b:      819504    4311216    swap                   # Cyl  4277 -  5089
  c:    78140160          0  unused      0     0      # Cyl     0 - 77519
  d:     2097648    5130720  4.2BSD   2048 16384  328 # Cyl  5090 -  7170
  e:      614880    7228368  4.2BSD   2048 16384  328 # Cyl  7171 -  7780
  g:     2097648    7843248  4.2BSD   2048 16384  328 # Cyl  7781 -  9861
  h:      921312    9940896  4.2BSD   2048 16384  328 # Cyl  9862 - 10775
  i:     2570462         63   MSDOS                   # Cyl     0*-  2549
  j:     3355632   10862208  4.2BSD   2048 16384  328 # Cyl 10776 - 14104
  k:     2097648   14217840  4.2BSD   2048 16384  328 # Cyl 14105 - 16185
  l:     2097648   16315488  4.2BSD   2048 16384  328 # Cyl 16186 - 18266
  m:    59727024   18413136  4.2BSD   2048 16384  328 # Cyl 18267 - 77519
.Ed
.Pp
These
.Ox
partitions are then mounted as follows using
.Pa /etc/fstab :
.Bd -literal -offset indent
/dev/wd0a / ffs rw,softdep 1 1
/dev/wd0m /home ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0d /tmp ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0g /usr ffs rw,softdep,nodev 1 2
/dev/wd0h /usr/X11R6 ffs rw,softdep,nodev 1 2
/dev/wd0j /usr/local ffs rw,softdep,nodev 1 2
/dev/wd0k /usr/obj ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0l /usr/src ffs rw,softdep,nodev,nosuid 1 2
/dev/wd0e /var 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 fdisk:*0>
.Pp
.Sq *
means that the in-memory copy of the boot block has been modified, but
not yet written to disk.
.Pp
0 is the disk offset of the currently selected boot block being edited.
This number could be something other than zero when extended MBR partitions
are being edited (using the
.Em select
subcommand).
.Pp
The list of commands and their explanations are given below.
.Bl -tag -width Ds
.It help
Display a list of commands that
.Nm
understands in the interactive edit mode.
.It manual
Display this manual page.
.It reinit
Initialize the currently selected, in-memory copy of the
boot block.
.It 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.
.It edit Ar #
Edit a given table entry in the memory copy of
the current boot block.
Sizes may be adjusted using either in BIOS geometry mode or
sector offsets and sizes.
.It flag Ar #
Make the given MBR partition table entry bootable.
Only one entry can be marked bootable.
.\" 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 an optional value is given, the MBR partition is marked with the given
.\" value, and other MBR partitions are not touched.
.It update
Update the machine MBR bootcode and 0xAA55 signature in the memory copy
of the currently selected boot block.
Note that this option will overwrite an NT disk
signature, if present.
.It select Ar #
Select and load into memory the boot block pointed
to by the extended MBR partition table entry in the current boot block.
.It setpid Ar #
Change the MBR partition
identifier of the given MBR partition table entry.
This command is particularly useful for reassigning
an existing MBR partition to
.Ox .
.It swap Ar # Ar #
Swap two MBR entries.
.It print Op unit
Print the currently selected in-memory copy of the boot
block and its MBR table to the terminal.
If
.Ar unit
is specified as
.Sq b ,
.Sq k ,
.Sq m ,
or
.Sq g ,
the MBR is printed in units of bytes, kilobytes, megabytes, or gigabytes.
Otherwise the number of sectors is printed.
.It write
Write the in-memory copy of the boot block to disk.
.It exit
Exit the current level of
.Nm fdisk ,
either returning to the
previously selected in-memory copy of a boot block, or exiting the
program if there is none.
.It quit
Exit the current level of
.Nm fdisk ,
either returning to the
previously selected in-memory copy of a boot block, or exiting the
program if there is none.
Unlike
.Em exit
it does write the modified block out.
.It 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_armish 8 ,
.Xr boot_i386 8 ,
.Xr boot_landisk 8 ,
.Xr boot_macppc 8 ,
.Xr boot_zaurus 8 ,
.Xr disklabel 8
.Sh CAVEATS
Hand crafted disk layouts are highly error prone.
MBR partitions should start on a cylinder boundary
(head 0, sector 1),
except when starting on track 0,
(these should begin at head 1, sector 1).
MBR partitions should also end at cylinder boundaries.