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