fdisk.8 revision 26421
1.Dd October 4, 1996
2.Dt FDISK 8
3.\".Os BSD 4
4.Sh NAME
5.Nm fdisk
6.Nd DOS partition maintenance program
7.Sh SYNOPSIS
8.Nm
9.Op Fl i
10.Op Fl u
11.Op Fl a
12.Op Fl 1234
13.Op Ar disk
14.Bl -tag -width time
15.Nm fdisk
16.Op Fl f Ar configfile
17.Op Fl i
18.Op Fl v
19.Op Fl t
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 boot code,
25a partition table,
26and a magic number.
27BIOS partitions can be used to break the disk up into several pieces.
28The BIOS brings in sector 0
29(does it really use the code?)
30and verifies the magic number.
31It then searches the 4 BIOS partitions described by sector 0
32to determine which of them is
33.Em active.
34This boot then brings in the secondary boot block from the
35.Em active
36partition and runs it.
37Under DOS,
38you could have one or more partitions with one
39.Em active.
40The DOS
41.Nm
42program can be used to divide space on the disk into partitions and set one
43.Em active.
44.Sh DESCRIPTION
45.Pp
46The FreeBSD program
47.Nm
48serves a similar purpose to the DOS program.  The first form is used to
49display partition information or to interactively edit the partition
50table.  The second is used to write a partition table using a
51.Ar configfile
52and is designed to be used by other scripts/programs.
53.Pp
54Options are:
55.It Fl u
56Is used for updating (editing) sector 0 of the disk.  Ignored if
57.Fl f
58is given.
59.It Fl i
60Initializes sector 0 of the disk.  This implies
61.Fl u ,
62unless
63.Fl f
64is given.
65.It Fl a
66Change the active partition only.  Ignored if
67.Fl f
68is given.
69.It Fl 1234
70Operate on a single fdisk entry only.  Ignored if
71.Fl f
72is given.
73.It Fl f Ar configfile
74Set partition values using the file
75.Ar configfile .
76The
77.Ar configfile
78always modifies existing partitions, unless
79.Fl i
80is also given, in which case all existing partitions are deleted (marked
81as "unused") before the
82.Ar configfile
83is read.  The
84.Ar configfile
85can be "-", in which case
86.Ar stdin
87is read.  See
88.Em CONFIGURATION FILE ,
89below, for file syntax.
90.Pp
91.Em WARNING:
92when
93.Fl f
94is used, you are not asked if you really want to write the partition
95table (as you are in the interactive mode).  Use with caution!
96.It Fl t
97Test mode; do not write partition values.  Generally used with the
98.Fl f
99option to see what would be written to the partition table.  Implies
100.Fl v .
101.It Fl v
102Be verbose.  When
103.Fl f
104is used,
105.Nm
106prints out the partition table that is written to the disk.
107.El
108.Pp
109The final disk name can be provided as a
110.Sq bare
111disk name only, e.g.
112.Ql sd0 ,
113or as a fully qualified device node under
114.Pa /dev .
115If omitted, the disks
116.Ql wd0 ,
117.Ql sd0 ,
118and
119.Ql od0
120are being searched in that order, until one is
121being found responding.
122.Pp
123When called with no arguments, it prints the sector 0 partition table.
124An example follows:
125
126.Bd -literal
127	******* Working on device /dev/rwd0 *******
128	parameters extracted from in-core disklabel are:
129	cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
130
131	parameters to be used for BIOS calculations are:
132	cylinders=769 heads=15 sectors/track=33 (495 blks/cyl)
133		
134	Warning: BIOS sector numbering starts with sector 1
135	Information from DOS bootblock is:
136	The data for partition 1 is:
137	sysid 165,(FreeBSD/NetBSD/386BSD)
138    	    start 495, size 380160 (185 Meg), flag 0
139		beg: cyl 1/ sector 1/ head 0;
140		end: cyl 768/ sector 33/ head 14
141	The data for partition 2 is:
142	sysid 164,(unknown)
143    	    start 378180, size 2475 (1 Meg), flag 0
144		beg: cyl 764/ sector 1/ head 0;
145		end: cyl 768/ sector 33/ head 14
146	The data for partition 3 is:
147	<UNUSED>
148	The data for partition 4 is:
149	sysid 99,(ISC UNIX, other System V/386, GNU HURD or Mach)
150    	    start 380656, size 224234 (109 Meg), flag 80
151		beg: cyl 769/ sector 2/ head 0;
152		end: cyl 197/ sector 33/ head 14
153.Ed
154.Pp
155The disk is divided into three partitions that happen to fill the disk.
156The second partition overlaps the end of the first.
157(Used for debugging purposes)
158.Bl -tag -width "cyl, sector and head"
159.It Em "sysid"
160is used to label the partition.  FreeBSD reserves the
161magic number 165 decimal (A5 in hex).
162.It Em "start and size"
163fields provide the start address
164and size of a partition in sectors.
165.It Em "flag 80"
166specifies that this is the active partition.
167.It Em "cyl, sector and head"
168fields are used to specify the beginning address
169and end address for the partition.
170.It Em "Note:"
171these numbers are calculated using BIOS's understanding of the disk geometry
172and saved in the bootblock.
173.El
174.Pp
175The flags
176.Fl i
177or
178.Fl u
179are used to indicate that the partition data is to be updated, unless the
180.Fl f
181option is used.  If the
182.Fl f
183option is not used, the
184.Nm
185program will enter a conversational mode.
186This mode is designed not to change any data unless you explicitly tell it to.
187.Nm
188selects defaults for its questions to guarantee the above behavior.
189.Pp
190It displays each partition
191and ask if you want to edit it.
192If you say yes,
193it will step through each field showing the old value
194and asking for a new one.
195When you are done with a partition,
196.Nm
197will display it and ask if it is correct.
198.Nm
199will then proceed to the next entry.
200.Pp
201Getting the
202.Em cyl, sector,
203and
204.Em head
205fields correct is tricky.
206So by default,
207they will be calculated for you;
208you can specify them if you choose.
209.Pp
210After all the partitions are processed,
211you are given the option to change the
212.Em active
213partition.
214Finally,
215when the all the data for the first sector has been accumulated,
216you are asked if you really want to rewrite sector 0.
217Only if you answer yes,
218will the data be written to disk.
219.Pp
220The difference between the
221.Fl u
222flag and
223.Fl i
224flag is that
225the
226.Fl u
227flag just edits the fields as they appear on the disk.
228While the
229.Fl i
230flag is used to "initialize" sector 0;
231it will setup the last BIOS partition to use the whole disk for FreeBSD;
232and make it active.
233.Sh NOTES
234.Pp
235The automatic calculation of starting cylinder etc. uses
236a set of figures that represent what the BIOS thinks is the
237geometry of the drive.
238These figures are by default taken from the incore disklabel,
239but the program initially gives you an opportunity to change them.
240This allows the user to create a bootblock that can work with drives
241that use geometry translation under the BIOS.
242.Pp
243If you hand craft your disk layout,
244please make sure that the FreeBSD partition starts on a cylinder boundary.
245A number of decisions made later may assume this.
246(This might not be necessary later.)
247.Pp
248Editing an existing partition will most likely cause you to
249lose all the data in that partition.
250.Pp
251You should run this program interactively once or twice to see how it
252works.  This is completely safe as long as you answer the last question
253in the negative.  There are subtleties that the program detects that are
254not fully explained in this manual page.
255.Sh CONFIGURATION FILE
256.Pp
257When the
258.Fl f
259option is given, a disk's partition table can be written using values
260from a
261.Ar configfile .
262The syntax of this file is very simple.  Each line is either a comment or
263a specification, and whitespace (except for newlines) are ignored:
264.Bl -tag -width Ds
265.It Xo
266.Ic #
267.No Ar comment ...
268.Xc
269Lines beginning with a "#" are comments and are ignored.
270.It Xo
271.Ic g
272.No Ar spec1
273.No Ar spec2
274.No Ar spec3
275.Xc
276Set the BIOS geometry used in partition calculations.  There must be
277three values specfied, with a letter preceding each number:
278.Bl -tag -width Ds
279.Sm off
280.It Cm c No Ar num
281.Sm on
282Set the number of cylinders to
283.Ar num .
284.Sm off
285.It Cm h No Ar num
286.Sm on
287Set the number of heads to
288.Ar num .
289.Sm off
290.It Cm s No Ar num
291.Sm on
292Set the number of sectors/track to
293.Ar num .
294.El
295.Pp
296These specs can occur in any order, as the leading letter determines
297which value is which; however, all three must be specified.
298.Pp
299This line must occur before any lines that specify partition
300information.
301.Pp
302It is an error if the following is not true:
303.Pp
304.nf
305        1 <= number of cylinders
306        1 <= number of heads <= 256
307        1 <= number of sectors/track < 64
308.fi
309.Pp
310The number of cylinders should be less than or equal to 1024, but this
311is not enforced, although a warning will be output.  Note that bootable
312FreeBSD partitions (the "/" filesystem) must lie completely within the
313first 1024 cylinders; if this is not true, booting may fail.
314Non-bootable partitions do not have this restriction.
315.Pp
316Example (all of these are equivalent), for a disk with 1019 cylinders,
31739 heads, and 63 sectors:
318.Pp
319.nf
320        g       c1019   h39     s63
321        g       h39     c1019   s63
322        g       s63     h39     c1019
323.fi
324.It Xo
325.Ic p
326.No Ar partition
327.No Ar type
328.No Ar start
329.No Ar length
330.Xc
331Set the partition given by
332.Ar partition
333(1-4) to type
334.Ar type ,
335starting at sector
336.Ar start
337for
338.Ar length
339sectors.
340.Pp
341Only those partitions explicitly mentioned by these lines are modified;
342any partition not referenced by a "p" line will not be modified.
343However, if an invalid partition table is present, or the
344.Fl i
345option is specified, all existing partition entries will be cleared
346(marked as unused), and these "p" lines will have to be used to
347explicitly set partition information.  If multiple partitions need to be
348set, multiple "p" lines must be specified; one for each partition.
349.Pp
350These partition lines must occur after any geometry specification lines,
351if one is present.
352.Pp
353The
354.Ar type
355is 165 for FreeBSD partitions.  Specifying a partition type of zero is
356the same as clearing the partition and marking it as unused; however,
357dummy values (such as "0") must still be specified for
358.Ar start
359and
360.Ar length .
361.Pp
362Note: the start offset will be rounded upwards to a head boundary if
363necessary, and the end offset will be rounded downwards to a cylinder
364boundary if necessary.
365.Pp
366Example: to clear partition 4 and mark it as unused:
367.Pp
368.nf
369        p       4       0       0       0
370.fi
371.Pp
372Example: to set partition 1 to a FreeBSD partition, starting at sector 1
373for 2503871 sectors (note: these numbers will be rounded upwards and
374downwards to correspond to head and cylinder boundaries):
375.Pp
376.nf
377        p       1       165     1       2503871
378.fi
379.It Xo
380.Ic a
381.No Ar partition
382.Xc
383Make
384.Ar partition
385the active partition.  Can occur anywhere in the config file, but only
386one must be present.
387.Pp
388Example: to make partition 1 the active partition:
389.Pp
390.nf
391        a       1
392.fi
393
394.El
395.Pp
396.Sh SEE ALSO
397.Xr disklabel 8
398.Sh BUGS
399The entire program should be made more user-friendly.
400.Pp
401Throughout this man page, the term
402.Sq partition
403is used where it should actually be
404.Sq slice ,
405in order to conform with the terms used elsewhere.
406.Pp
407You cannot use this command to completely dedicate a disk to FreeBSD.  The
408.Xr disklabel 8
409command must be used for this.
410