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