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