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