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