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