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