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