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