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