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