Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sbin / i386 / fdisk / fdisk.8
1 .\" $FreeBSD: src/sbin/i386/fdisk/fdisk.8,v 1.17.2.11 2002/04/25 16:25:12 trhodes Exp $
2 .\" $DragonFly: src/sbin/i386/fdisk/fdisk.8,v 1.2 2003/06/17 04:27:33 dillon Exp $
3 .\"
4 .Dd October 4, 1996
5 .Dt FDISK 8
6 .Os
7 .Sh NAME
8 .Nm fdisk
9 .Nd PC slice table maintenance program
10 .Sh SYNOPSIS
11 .Nm
12 .Op Fl BIaistu
13 .Op Fl b Ar bootcode
14 .Op Fl 1234
15 .Op Ar disk
16 .Bl -tag -width time
17 .Nm
18 .Fl f Ar configfile
19 .Op Fl itv
20 .Op Ar disk
21 .Sh PROLOGUE
22 In order for the BIOS to boot the kernel,
23 certain conventions must be adhered to.
24 Sector 0 of the disk must contain boot code,
25 a slice table,
26 and a magic number.
27 BIOS slices can be used to break the disk up into several pieces.
28 The BIOS brings in sector 0 and verifies the magic number.  The sector
29 0 boot code then searches the slice table to determine which
30 slice is marked
31 .Em active .
32 This boot code then brings in the bootstrap from the
33 .Em active
34 slice and, if marked bootable, runs it.
35 Under DOS,
36 you can have one or more slices with one
37 .Em active .
38 The DOS
39 .Nm
40 program can be used to divide space on the disk into slices and set one
41 .Em active .
42 .Sh DESCRIPTION
43 The
44 .Fx
45 program,
46 .Nm ,
47 serves a similar purpose to the DOS program.  The first form is used to
48 display slice information or to interactively edit the slice
49 table.  The second is used to write a slice table using a
50 .Ar configfile
51 and is designed to be used by other scripts/programs.
52 .Pp
53 Options are:
54 .It Fl a
55 Change the active slice only.  Ignored if
56 .Fl f
57 is given.
58 .It Fl b Ar bootcode
59 Get the boot code from the file
60 .Ar bootcode .
61 Default is
62 .Pa /boot/mbr .
63 .It Fl B
64 Reinitialize the boot code contained in sector 0 of the disk.  Ignored
65 if
66 .Fl f
67 is given.
68 .It Fl f Ar configfile
69 Set slice values using the file
70 .Ar configfile .
71 The
72 .Ar configfile
73 always modifies existing slices, unless
74 .Fl i
75 is also given, in which case all existing slices are deleted (marked
76 as "unused") before the
77 .Ar configfile
78 is read.  The
79 .Ar configfile
80 can be "-", in which case
81 .Ar stdin
82 is read.  See
83 .Sx CONFIGURATION FILE ,
84 below, for file syntax.
85 .Pp
86 .Em WARNING :
87 when
88 .Fl f
89 is used, you are not asked if you really want to write the slices
90 table (as you are in the interactive mode).  Use with caution!
91 .It Fl i
92 Initialize sector 0 of the disk.  This implies
93 .Fl u ,
94 unless
95 .Fl f
96 is given.
97 .It Fl I
98 Initialize the contents of sector 0
99 for one
100 .Fx
101 slice covering the entire disk.
102 .It Fl s
103 Print summary information and exit.
104 .It Fl t
105 Test mode; do not write slice values.  Generally used with the
106 .Fl f
107 option to see what would be written to the slice table.  Implies
108 .Fl v .
109 .It Fl u
110 Is used for updating (editing) sector 0 of the disk.  Ignored if
111 .Fl f
112 is given.
113 .It Fl v
114 Be verbose.  When
115 .Fl f
116 is used,
117 .Nm
118 prints out the slice table that is written to the disk.
119 .It Fl 1234
120 Operate on a single fdisk entry only.  Ignored if
121 .Fl f
122 is given.
123 .El
124 .Pp
125 The final disk name can be provided as a
126 .Sq bare
127 disk name only, e.g.\&
128 .Ql da0 ,
129 or as a fully qualified device node under
130 .Pa /dev .
131 If omitted, the disks
132 .Ql ad0
133 and
134 .Ql da0
135 are searched in that order, until one is found to respond.
136 .Pp
137 When called without options,
138 .Nm
139 prints the sector 0 slice table.
140 An example follows:
141 .Bd -literal
142         ******* Working on device /dev/ad0 *******
143         parameters extracted from in-core disklabel are:
144         cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
145
146         parameters to be used for BIOS calculations are:
147         cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
148
149         Warning: BIOS sector numbering starts with sector 1
150         Information from DOS bootblock is:
151         The data for partition 1 is:
152         sysid 165,(FreeBSD/NetBSD/386BSD)
153             start 495, size 380160 (185 Meg), flag 0
154                 beg: cyl 1/ sector 1/ head 0;
155                 end: cyl 768/ sector 33/ head 14
156         The data for partition 2 is:
157         sysid 164,(unknown)
158             start 378180, size 2475 (1 Meg), flag 0
159                 beg: cyl 764/ sector 1/ head 0;
160                 end: cyl 768/ sector 33/ head 14
161         The data for partition 3 is:
162         <UNUSED>
163         The data for partition 4 is:
164         sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach)
165             start 380656, size 224234 (109 Meg), flag 80
166                 beg: cyl 769/ sector 2/ head 0;
167                 end: cyl 197/ sector 33/ head 14
168 .Ed
169 .Pp
170 The disk is divided into three slices that happen to fill the disk.
171 The second slice overlaps the end of the first.
172 (Used for debugging purposes.)
173 .Bl -tag -width "cyl, sector and head"
174 .It Em "sysid"
175 is used to label the slice.
176 .Fx
177 reserves the
178 magic number 165 decimal (A5 in hex).
179 .It Em start No and Em size
180 fields provide the start address
181 and size of a slice in sectors.
182 .It Em "flag 80"
183 specifies that this is the active slice.
184 .It Em cyl , sector No and Em head
185 fields are used to specify the beginning and end addresses of the slice.
186 .It Em Note :
187 these numbers are calculated using BIOS's understanding of the disk geometry
188 and saved in the bootblock.
189 .El
190 .Pp
191 The
192 .Fl i
193 and
194 .Fl u
195 flags are used to indicate that the slice data is to be updated.
196 Unless the
197 .Fl f
198 option is also given,
199 .Nm
200 will enter a conversational mode.
201 In this mode, no changes will be written to disk unless you explicitly tell
202 .Nm
203 to.
204 .Pp
205 .Nm Fdisk
206 will display each slice and ask whether you want to edit it.
207 If you say yes,
208 .Nm
209 will step through each field, show you the old value,
210 and ask you for a new one.
211 When you are done with the slice,
212 .Nm
213 will display it and ask you whether it is correct.
214 .Nm Fdisk
215 will then proceed to the next entry.
216 .Pp
217 Getting the
218 .Em cyl , sector ,
219 and
220 .Em head
221 fields correct is tricky, so by default,
222 they will be calculated for you;
223 you can specify them if you choose to though.
224 .Pp
225 After all the slices are processed,
226 you are given the option to change the
227 .Em active
228 slice.
229 Finally, when all the new data for sector 0 has been accumulated,
230 you are asked to confirm whether you really want to rewrite it.
231 .Pp
232 The difference between the
233 .Fl u
234 and
235 .Fl i
236 flags is that
237 the
238 .Fl u
239 flag just edits (updates) the fields as they appear on the disk,
240 while the
241 .Fl i
242 flag is used to "initialize" sector 0;
243 it will set up the last BIOS slice to use the whole disk for
244 .Fx
245 and make it active.
246 .Sh NOTES
247 The automatic calculation of starting cylinder etc. uses
248 a set of figures that represent what the BIOS thinks the
249 geometry of the drive is.
250 These figures are taken from the in-core disklabel by default,
251 but
252 .Nm
253 initially gives you an opportunity to change them.
254 This allows you to create a bootblock that can work with drives
255 that use geometry translation under the BIOS.
256 .Pp
257 If you hand craft your disk layout,
258 please make sure that the
259 .Fx
260 slice starts on a cylinder boundary.
261 A number of decisions made later may assume this.
262 (This might not be necessary later.)
263 .Pp
264 Editing an existing slice will most likely result in the loss of
265 all data in that slice.
266 .Pp
267 You should run
268 .Nm
269 interactively once or twice to see how it works.
270 This is completely safe as long as you answer the last question
271 in the negative.  There are subtleties that
272 .Nm
273 detects that are not fully explained in this manual page.
274 .Sh CONFIGURATION FILE
275 When the
276 .Fl f
277 option is given, a disk's slice table can be written using values
278 from a
279 .Ar configfile .
280 The syntax of this file is very simple;
281 each line is either a comment or a specification, as follows:
282 .Bl -tag -width Ds
283 .It Xo
284 .Ic #
285 .Ar comment ...
286 .Xc
287 Lines beginning with a "#" are comments and are ignored.
288 .It Xo
289 .Ic g
290 .Ar spec1
291 .Ar spec2
292 .Ar spec3
293 .Xc
294 Set the BIOS geometry used in slice calculations.  There must be
295 three values specified, with a letter preceding each number:
296 .Bl -tag -width Ds
297 .Sm off
298 .It Cm c Ar num
299 .Sm on
300 Set the number of cylinders to
301 .Ar num .
302 .Sm off
303 .It Cm h Ar num
304 .Sm on
305 Set the number of heads to
306 .Ar num .
307 .Sm off
308 .It Cm s Ar num
309 .Sm on
310 Set the number of sectors/track to
311 .Ar num .
312 .El
313 .Pp
314 These specs can occur in any order, as the leading letter determines
315 which value is which; however, all three must be specified.
316 .Pp
317 This line must occur before any lines that specify slice
318 information.
319 .Pp
320 It is an error if the following is not true:
321 .Bd -literal -offset indent
322 1 <= number of cylinders
323 1 <= number of heads <= 256
324 1 <= number of sectors/track < 64
325 .Ed
326 .Pp
327 The number of cylinders should be less than or equal to 1024, but this
328 is not enforced, although a warning will be printed.  Note that bootable
329 .Fx
330 slices (the "/" filesystem) must lie completely within the
331 first 1024 cylinders; if this is not true, booting may fail.
332 Non-bootable slices do not have this restriction.
333 .Pp
334 Example (all of these are equivalent), for a disk with 1019 cylinders,
335 39 heads, and 63 sectors:
336 .Bd -literal -offset indent
337 g       c1019   h39     s63
338 g       h39     c1019   s63
339 g       s63     h39     c1019
340 .Ed
341 .It Xo
342 .Ic p
343 .Ar slice
344 .Ar type
345 .Ar start
346 .Ar length
347 .Xc
348 Set the slice given by
349 .Ar slice
350 (1-4) to type
351 .Ar type ,
352 starting at sector
353 .Ar start
354 for
355 .Ar length
356 sectors.
357 .Pp
358 Only those slices explicitly mentioned by these lines are modified;
359 any slice not referenced by a "p" line will not be modified.
360 However, if an invalid slice table is present, or the
361 .Fl i
362 option is specified, all existing slice entries will be cleared
363 (marked as unused), and these "p" lines will have to be used to
364 explicitly set slice information.  If multiple slices need to be
365 set, multiple "p" lines must be specified; one for each slice.
366 .Pp
367 These slice lines must occur after any geometry specification lines,
368 if one is present.
369 .Pp
370 The
371 .Ar type
372 is 165 for
373 .Fx
374 slices.  Specifying a slice type of zero is
375 the same as clearing the slice and marking it as unused; however,
376 dummy values (such as "0") must still be specified for
377 .Ar start
378 and
379 .Ar length .
380 .Pp
381 Note: the start offset will be rounded upwards to a head boundary if
382 necessary, and the end offset will be rounded downwards to a cylinder
383 boundary if necessary.
384 .Pp
385 Example: to clear slice 4 and mark it as unused:
386 .Bd -literal -offset indent
387 p       4       0       0       0
388 .Ed
389 .Pp
390 Example: to set slice 1 to a
391 .Fx
392 slice, starting at sector 1
393 for 2503871 sectors (note: these numbers will be rounded upwards and
394 downwards to correspond to head and cylinder boundaries):
395 .Pp
396 .Bd -literal -offset indent
397 p       1       165     1       2503871
398 .Ed
399 .Pp
400 .It Xo
401 .Ic a
402 .Ar slice
403 .Xc
404 Make
405 .Ar slice
406 the active slice.  Can occur anywhere in the config file, but only
407 one must be present.
408 .Pp
409 Example: to make slice 1 the active slice:
410 .Bd -literal -offset indent
411 a       1
412 .Ed
413 .El
414 .Sh FILES
415 .Bl -tag -width /boot/mbr -compact
416 .It Pa /boot/mbr
417 The default boot code
418 .El
419 .Sh SEE ALSO
420 .Xr boot0cfg 8 ,
421 .Xr disklabel 8 ,
422 .Xr newfs 8
423 .Sh BUGS
424 The default boot code will not necessarily handle all slice types
425 correctly, in particular those introduced since MS-DOS 6.x.
426 .Pp
427 The entire program should be made more user-friendly.
428 .Pp
429 Most users new to
430 .Fx
431 do not understand the difference between
432 .Ar slice
433 and
434 .Ar partition
435 causing difficulty to adjust.
436 .Pp
437 You cannot use this command to completely dedicate a disk to
438 .Fx .
439 The
440 .Xr disklabel 8
441 command must be used for this.