xref: /freebsd/sbin/fdisk/fdisk.8 (revision f0a75d274af375d15b97b830966b99a02b7db911)
1.\" $FreeBSD$
2.\"
3.Dd December 12, 2006
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 BIaistu
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 s
113Print summary information and exit.
114.It Fl t
115Test mode; do not write slice values.
116Generally used with the
117.Fl f
118option to see what would be written to the slice table.
119Implies
120.Fl v .
121.It Fl u
122Update (edit) the disk's sector 0 slice table.
123Ignored if
124.Fl f
125is given.
126.It Fl v
127Be verbose.
128When
129.Fl f
130is used,
131.Nm
132prints out the slice table that is written to the disk.
133.It Fl 1234
134Operate on a single slice table entry only.
135Ignored if
136.Fl f
137is given.
138.El
139.Pp
140The final disk name can be provided as a
141.Dq bare
142disk name only, e.g.\&
143.Pa da0 ,
144or as a full pathname.
145If omitted,
146.Nm
147tries to figure out the default disk device name from the
148mounted root device.
149.Pp
150When called with no arguments, it prints the sector 0 slice table.
151An example follows:
152.Bd -literal
153	******* Working on device /dev/ad0 *******
154	parameters extracted from in-core disklabel are:
155	cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
156
157	parameters to be used for BIOS calculations are:
158	cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
159
160	Warning: BIOS sector numbering starts with sector 1
161	Information from DOS bootblock is:
162	The data for partition 1 is:
163	sysid 165,(FreeBSD/NetBSD/386BSD)
164    	    start 495, size 380160 (185 Meg), flag 0
165		beg: cyl 1/ sector 1/ head 0;
166		end: cyl 768/ sector 33/ head 14
167	The data for partition 2 is:
168	sysid 164,(unknown)
169    	    start 378180, size 2475 (1 Meg), flag 0
170		beg: cyl 764/ sector 1/ head 0;
171		end: cyl 768/ sector 33/ head 14
172	The data for partition 3 is:
173	<UNUSED>
174	The data for partition 4 is:
175	sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach)
176    	    start 380656, size 224234 (109 Meg), flag 80
177		beg: cyl 769/ sector 2/ head 0;
178		end: cyl 197/ sector 33/ head 14
179.Ed
180.Pp
181The disk is divided into three slices that happen to fill the disk.
182The second slice overlaps the end of the first.
183(Used for debugging purposes.)
184.Bl -tag -width ".Em cyl , sector No and Em head"
185.It Em sysid
186is used to label the slice.
187.Fx
188reserves the
189magic number 165 decimal (A5 in hex).
190.It Xo
191.Em start
192and
193.Em size
194.Xc
195fields provide the start address
196and size of a slice in sectors.
197.It Em "flag 80"
198specifies that this is the active slice.
199.It Xo
200.Em cyl , sector
201and
202.Em head
203.Xc
204fields are used to specify the beginning and end addresses of the slice.
205.El
206.Pp
207.Em Note :
208these numbers are calculated using BIOS's understanding of the disk geometry
209and saved in the bootblock.
210.Pp
211The
212.Fl i
213and
214.Fl u
215flags are used to indicate that the slice data is to be updated.
216Unless the
217.Fl f
218option is also given,
219.Nm
220will enter a conversational mode.
221In this mode, no changes will be written to disk unless you explicitly tell
222.Nm
223to.
224.Pp
225The
226.Nm
227utility will display each slice and ask whether you want to edit it.
228If you say yes,
229.Nm
230will step through each field, show you the old value,
231and ask you for a new one.
232When you are done with the slice,
233.Nm
234will display it and ask you whether it is correct.
235It will then proceed to the next entry.
236.Pp
237Getting the
238.Em cyl , sector ,
239and
240.Em head
241fields correct is tricky, so by default,
242they will be calculated for you;
243you can specify them if you choose to though.
244.Pp
245After all the slices are processed,
246you are given the option to change the
247.Dq active
248slice.
249Finally, when all the new data for sector 0 has been accumulated,
250you are asked to confirm whether you really want to rewrite it.
251.Pp
252The difference between the
253.Fl u
254and
255.Fl i
256flags is that
257the
258.Fl u
259flag edits (updates) the existing slice parameters
260while the
261.Fl i
262flag is used to
263.Dq initialize
264them (old values will be ignored);
265if you edit the first slice,
266.Fl i
267will also set it up to use the whole disk for
268.Fx
269and make it active.
270.Sh NOTES
271The automatic calculation of starting cylinder etc.\& uses
272a set of figures that represent what the BIOS thinks the
273geometry of the drive is.
274These figures are taken from the in-core disklabel by default,
275but
276.Nm
277initially gives you an opportunity to change them.
278This allows you to create a bootblock that can work with drives
279that use geometry translation under the BIOS.
280.Pp
281If you hand craft your disk layout,
282please make sure that the
283.Fx
284slice starts on a cylinder boundary.
285.Pp
286Editing an existing slice will most likely result in the loss of
287all data in that slice.
288.Pp
289You should run
290.Nm
291interactively once or twice to see how it works.
292This is completely safe as long as you answer the last question
293in the negative.
294There are subtleties that
295.Nm
296detects that are not fully explained in this manual page.
297.Sh CONFIGURATION FILE
298When the
299.Fl f
300option is given, a disk's slice table can be written using values
301from a
302.Ar configfile .
303The syntax of this file is very simple;
304each line is either a comment or a specification, as follows:
305.Bl -tag -width indent
306.It Ic # Ar comment ...
307Lines beginning with a
308.Ic #
309are comments and are ignored.
310.It Ic g Ar spec1 spec2 spec3
311Set the BIOS geometry used in slice calculations.
312There must be
313three values specified, with a letter preceding each number:
314.Bl -tag -width indent
315.It Cm c Ns Ar num
316Set the number of cylinders to
317.Ar num .
318.It Cm h Ns Ar num
319Set the number of heads to
320.Ar num .
321.It Cm s Ns Ar num
322Set the number of sectors/track to
323.Ar num .
324.El
325.Pp
326These specs can occur in any order, as the leading letter determines
327which value is which; however, all three must be specified.
328.Pp
329This line must occur before any lines that specify slice
330information.
331.Pp
332It is an error if the following is not true:
333.Bd -literal -offset indent
3341 <= number of cylinders
3351 <= number of heads <= 256
3361 <= number of sectors/track < 64
337.Ed
338.Pp
339The number of cylinders should be less than or equal to 1024, but this
340is not enforced, although a warning will be printed.
341Note that bootable
342.Fx
343slices (the
344.Dq Pa /
345file system) must lie completely within the
346first 1024 cylinders; if this is not true, booting may fail.
347Non-bootable slices do not have this restriction.
348.Pp
349Example (all of these are equivalent), for a disk with 1019 cylinders,
35039 heads, and 63 sectors:
351.Bd -literal -offset indent
352g       c1019   h39     s63
353g       h39     c1019   s63
354g       s63     h39     c1019
355.Ed
356.It Ic p Ar slice type start length
357Set the slice given by
358.Ar slice
359(1-4) to type
360.Ar type ,
361starting at sector
362.Ar start
363for
364.Ar length
365sectors.
366.Pp
367Only those slices explicitly mentioned by these lines are modified;
368any slice not referenced by a
369.Ic p
370line will not be modified.
371However, if an invalid slice table is present, or the
372.Fl i
373option is specified, all existing slice entries will be cleared
374(marked as unused), and these
375.Ic p
376lines will have to be used to
377explicitly set slice information.
378If multiple slices need to be
379set, multiple
380.Ic p
381lines must be specified; one for each slice.
382.Pp
383These slice lines must occur after any geometry specification lines,
384if one is present.
385.Pp
386The
387.Ar type
388is 165 for
389.Fx
390slices.
391Specifying a slice type of zero is
392the same as clearing the slice and marking it as unused; however,
393dummy values (such as
394.Dq 0 )
395must still be specified for
396.Ar start
397and
398.Ar length .
399.Pp
400Note: the start offset will be rounded upwards to a head boundary if
401necessary, and the end offset will be rounded downwards to a cylinder
402boundary if necessary.
403.Pp
404Example: to clear slice 4 and mark it as unused:
405.Pp
406.Dl "p       4       0       0       0"
407.Pp
408Example: to set slice 1 to a
409.Fx
410slice, starting at sector 1
411for 2503871 sectors (note: these numbers will be rounded upwards and
412downwards to correspond to head and cylinder boundaries):
413.Pp
414.Dl "p       1       165     1       2503871"
415.It Ic a Ar slice
416Make
417.Ar slice
418the active slice.
419Can occur anywhere in the config file, but only
420one must be present.
421.Pp
422Example: to make slice 1 the active slice:
423.Pp
424.Dl "a       1"
425.El
426.Sh FILES
427.Bl -tag -width ".Pa /boot/mbr" -compact
428.It Pa /boot/mbr
429The default boot code.
430.El
431.Sh SEE ALSO
432.Xr boot0cfg 8 ,
433.Xr bsdlabel 8 ,
434.Xr newfs 8
435.Sh BUGS
436The default boot code will not necessarily handle all slice types
437correctly, in particular those introduced since
438.Tn MS-DOS
4396.x.
440.Pp
441The entire utility should be made more user-friendly.
442.Pp
443Most users new to
444.Fx
445do not understand the difference between
446.Dq slice
447and
448.Dq partition ,
449causing difficulty to adjust.
450.Pp
451You cannot use this command to completely dedicate a disk to
452.Fx .
453The
454.Xr bsdlabel 8
455command must be used for this.
456