summaryrefslogtreecommitdiff
path: root/sbin/fdisk/fdisk.8
blob: 9506d4ec63a7fbe41f28acee5ed7ffdb1e9ba1c9 (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
.\"	$OpenBSD: fdisk.8,v 1.20 1998/12/15 01:20:30 aaron 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.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"    This product includes software developed by Tobias Weingartner.
.\" 4. The name of the author may not be used to endorse or promote products
.\"    derived from this software without specific prior written permission.
.\"
.\" 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 April 4, 1993
.Dt FDISK 8
.Os OpenBSD
.Sh NAME
.Nm fdisk
.Nd DOS partition maintenance program
.Sh SYNOPSIS
.Nm fdisk
.Op Fl ie
.Op Fl f Ar mbrname
.Op Fl c Ar cyls
.Op Fl h Ar heads
.Op Fl s Ar sects
.Ar device
.Sh DESCRIPTION
In order for the BIOS to boot the kernel, certain conventions must be
adhered to.  Sector 0 of a bootable hard disk must contain boot code,
an MBR partition table, and a magic number.  These MBR partitions (also
known as BIOS partitions) can be used to break the disk up into several
pieces.  The BIOS loads sector 0 of the boot disk into memory, verifies
the magic number, and begins executing the code at the first byte.
The normal DOS MBR boot code searches the MBR partition table for an
.Dq active
partition (indicated by a
.Dq \&*
in the first column), and if one
is found, the boot block from that partition is loaded and executed in
place of the original (MBR) boot block.
.Pp
The following options are available:
.Bl -tag -width "-f mbrname"
.It Fl i
Initialize the MBR sector.
.It Fl e
Edit existing MBR sectors.
.It Fl f Ar mbrname
Specifies an alternate MBR template file.
.It Fl c,h,s
Specifies an alternate BIOS geometry for
.Nm
to use.
.El
.Pp
The DOS
.Nm
program can be used to divide space on the disk into partitions and set
one active.
This 
.Nm
program serves a similar purpose to the DOS program.
When called with no special flags, it prints the MBR partition
table of the specified device, ie.
.Bd -literal
    # fdisk fd0
    Disk: fd0       geometry: 80/2/18 [2880 sectors]
    Offset: 0       Signatures: 0xAA55,0x0
             Starting        Ending
     #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
    ----------------------------------------------------------------------
    *0: A6    0   0   1 -   79   1  18 [         0 -       2880] OpenBSD
     1: 00    0   0   0 -    0   0   0 [         0 -          0] unused
     2: A7    0   0   2 -   79   1  18 [         1 -       2879] NEXTSTEP
     3: 00    0   0   0 -    0   0   0 [         0 -          0] unused
.Ed
.Pp
The geometry displayed is the BIOS geometry unless another geometry
has been selected using the
.Fl c ,
.Fl h ,
and
.Fl s
options. 
.Pp
This disk is divided into two partitions that happen to fill the disk.
The first partition overlaps the third partition.  (Used for debugging
purposes.)
.Bl -tag -width "start/size"
.It Em "#"
Number of partition table entry.  A
.Dq \&*
denotes the bootable partition.
.It Em "id"
System identifier.
.oS
reserves the
magic number 166 decimal (A6 in hex).
If no 166 partition is found, it will use an older FreeBSD partition
(with a magic number of 165 or A5 in hex).
.It Em "cyl/hd/sec"
These fields provide the starting and ending address of the partition
in BIOS geometry
.It Em "start/size"
These fields provide the starting sector and size in sectors of the
partition in linear block addresses.
.El
.Pp
.Em NOTE :
The sectors field is
.Dq 1 based ,
and 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.
.Pp
The
.Fl i
flag is used to indicate that the partition data is to be initialized.
In this mode,
.Nm
will completely overwrite the primary MBR, and start with a fresh one using
a default template, or one given by the
.Fl f
flag.  It will set up partition number 3 to be an
.oS
partition, that will start at cylinder 0, head 1, sector 1, and extend
to the end of the disk.
This mode is designed to initialize an MBR the very first time,
or when it has been corrupted beyond repair.  It is almost equivalent
to the DOS command
.Dq FDISK /MBR .
.Pp
The flag
.Fl e
is used to modify a partition table using a interactive edit mode of the
.Nm
program.  This mode is designed to allow you to change any partition on the
drive you choose, including extended partitions.  It is a very powerfull mode,
but is safe as long as you do not execute the
.Em write
command, or answer in the negative (the default) when
.Nm
asks you about writing out changes.
.Sh COMMAND MODE
When you first enter this mode, you are presented with a prompt, that looks
like so:
.Em "fdisk: 0>" .
This prompt has two important pieces of information for you.  It will tell
you if the in-memory copy of the boot block has been modified or not.  If it
has been modified, the prompt will change to look like:
.Em "fdisk:*0>" .
The second piece of information pertains to the number given in the prompt.
This number specifies the disk offset of the currently selected boot block
you are editing.  This number could be something different that zero when
you are editing extended partitions.  The list of commands and their
explanations are given below.
.Bl -tag -width "update"
.It Em help
Display a list of commands that
.Nm
understands in the interactive edit mode.
.It Em reinit
Initialize the currently selected, in-memory copy of the
boot block.
.It Em disk
Display the current drive geometry that
.Nm
has
probed.  You are given a chance to edit it if you wish.
.It Em edit
Edit a given table entry in the memory copy of
the current boot block.  You may edit either in BIOS geometry mode,
or in sector offsets and sizes.
.It Em flag
Make the given partition table entry bootable.  Only one
entry can be marked bootable. If you wish to boot from an extended
partition, you will need to mark the partition table entry for the
extended partition as bootable.
.It Em update
Update the machine code in the memory copy of the
currently selected boot block.
.It Em select
Select and load into memory the boot block pointed
to by the extended partition table entry in the current boot block.
.It Em print
Print the currently selected in-memory copy of the boot
block and its MBR table to the terminal.
.It Em write
Write the in-memory copy of the boot block to disk.  You will
be asked to confirm this operation.
.It Em 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 Em 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 Em abort
Quit program without saving current changes.
.El
.Pp
.Sh NOTES
The automatic calculation of starting cylinder etc. uses
a set of figures that represent what the BIOS thinks is the
geometry of the drive.
These figures are by default taken from the in-core disklabel, or
values that
.Em /boot
has passed to the kernel, but
.Nm
gives you an opportunity to change them if there is a need to.
This allows the user to create a bootblock that can work with drives
that use geometry translation under a potentially different BIOS.
.Pp
If you hand craft your disk layout,
please make sure that the
.oS
partition starts on a cylinder boundary.
(This restriction may be changed in the future.)
.Pp
Editing an existing partition is risky, and may cause you to
lose all the data in that partition.
.Pp
You should run this program interactively once or twice to see how it works.
This is completely safe as long as you answer the
.Dq write
questions in the
negative.
.Sh FILES
.Bl -tag -width /usr/mdec/mbr -compact
.It Pa /usr/mdec/mbr
default MBR template
.El
.Sh SEE ALSO
.Xr boot_i386 8 ,
.Xr disklabel 8
.Sh BUGS
There are subtleties that the program detects that are not explained in
this manual page.  Also, chances are that some of the subtleties it should
detect are being steamrolled.  Caveat Emperor.