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