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