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