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