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