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