xref: /netbsd-src/sbin/fdisk/fdisk.8 (revision 11a6dbe72840351315e0652b2fc6663628c84cad)
1.\"	$NetBSD: fdisk.8,v 1.59 2008/01/20 15:04:09 dsl Exp $
2.\"
3.Dd January 20, 2008
4.Dt FDISK 8
5.Os
6.Sh NAME
7.Nm fdisk
8.Nd MS-DOS partition maintenance program
9.Sh SYNOPSIS
10.Nm
11.Op Fl afiuvBFS
12.Bk -words
13.Op Fl 0 | 1 | 2 | 3
14.Ek
15.Bk -words
16.Op Fl t Ar disktab
17.Ek
18.Bk -words
19.Op Fl T Ar disktype
20.Ek
21.Bk -words
22.Op Fl E Ar number
23.Ek
24.Bk -words
25.Op Fl b Ar cylinders/heads/sectors
26.Ek
27.Bk -words
28.Op Fl s Ar id/start/size Ns Bq Ar /bootmenu
29.Ek
30.Bk -words
31.Op Fl c Ar bootcode
32.Ek
33.Bk -words
34.Op Fl r|w Ar file
35.Ek
36.Bk -words
37.Op Ar device
38.Ek
39.Nm
40.Fl l
41.Sh DESCRIPTION
42The
43.Nm
44program is used to display or update the
45.Em "master boot record"
46or
47.Em MBR
48in the first sector (sector 0)
49of a disk that uses the MBR style of partitioning.
50The following
51.Nx
52ports use this style of disk partitioning:
53amd64, arc, bebox, cobalt, hpcarm, hpcmips, hpcsh, i386, macppc,
54mvmeppc, netwinder, ofppc, playstation2, and prep.
55.Pp
56The MBR contains bootable code, a partition table,
57an indication of which partition is
58.Sq active ,
59and (optionally, depending on the boot code) a menu
60for selecting a partition to be booted.
61There can be at most 4 partitions defined in sector 0,
62one of which can be an extended
63partition which can be split into any number of sub-partitions.
64.Pp
65The boot code in the MBR is usually invoked by the BIOS or firmware,
66and the MBR passes control to the next stage boot code
67stored in the first sector of the partition to be booted
68(the
69.Em "partition boot record"
70or
71.Em PBR ) .
72.Pp
73After booting,
74.Nx
75does not use the partitioning done by
76.Nm ,
77instead it uses a
78.Nx
79disklabel saved in sector 1 of the
80.Nx
81partition.
82See
83.Xr mbrlabel 8
84for a way of using information from the MBR
85to construct a
86.Nx
87disklabel.
88.Pp
89The standard MBR boot code will only boot the
90.Sq active
91partition.
92However
93.Nx
94contains additional boot programs which allow the user to
95interactively select which of the partitions to boot.
96The
97.Sq mbr_ext
98code will also boot
99.Nx
100from an extended partition but will not work on old systems that do not
101support LBA reads, the
102.Sq mbr_com0
103and
104.Sq mbr_com0_9600
105will read and write from a serial port.
106At the start the
107.Nm
108program will determine whether the disk sector 0 is valid as a boot sector.
109(This is determined by checking the magic number.)
110If not,
111.Nm
112will initialise the boot code as well as the partition table.
113During this, all four partitions will be marked empty.
114.Pp
115The flags
116.Fl a ,
117.Fl i
118or
119.Fl u
120are used to indicate that the partition data is to be updated.
121The
122.Nm
123program will enter an interactive conversational mode.
124This mode is designed not to change any data unless you explicitly tell it to;
125.Nm
126selects defaults for its questions to guarantee that behaviour.
127.Pp
128.Nm
129will calculate the correct
130.Em cylinder ,
131.Em head ,
132and
133.Em sector
134values for any partition you edit.
135If you specify
136.Fl v
137you will be asked whether you want to specify them yourself.
138.Pp
139Finally, when all the data for the first sector has been accumulated,
140.Nm
141will ask if you really want to write the new partition table.
142Only if you reply affirmatively to this question will
143.Nm
144write anything to the disk.
145.Pp
146Available options:
147.Pp
148.Bl -tag -width Ds
149.It Fl 0
150Update partition slot 0.
151.It Fl 1
152Update partition slot 1.
153.It Fl 2
154Update partition slot 2.
155.It Fl 3
156Update partition slot 3.
157.It Fl a
158Change the active partition.
159In interactive mode this question will be asked after the partitions
160have been processed.
161.It Fl b Ar cylinders/heads/sectors
162Specify the BIOS parameters for
163.Ar cylinders ,
164.Ar heads ,
165and
166.Ar sectors .
167It is used only in conjunction with the
168.Fl u
169flag.
170.It Fl B
171On an i386 or amd64 system, interactively update the boot selector settings.
172(The boot selector permits the user to interactively select the boot
173partition, and thus which operating system is run, at system boot time.
174See
175.Xr mbr 8
176for more information.)
177.It Fl c Ar bootcode
178Specify the filename that
179.Nm
180should read the bootcode from.
181If the name of a directory is specified, then
182.Nm
183will look for files with the default names in that directory.
184The default is to read from
185.Pa /usr/mdec/mbr ,
186.Pa /usr/mdec/mbr_bootsel
187or
188.Pa /usr/mdec/mbr_ext
189depending on whether
190.Ar bootmenu
191was specified for any partitions
192on an i386 machine, and leave the bootcode empty for other
193machines.
194.It Fl E Ar number
195Update extended partition
196.Ar number .
197If the specified extended partition doesn't exist an additional extended
198partition will be created.
199.It Fl f
200Run
201.Nm
202in a non-interactive mode.
203In this mode, you can only change the disk parameters by using the
204.Fl b
205flag.
206This is provided only so scripts or other programs may use
207.Nm
208as part of an automatic installation process.
209.Pp
210Using the
211.Fl f
212flag with
213.Fl u
214makes it impossible to specify the starting and ending
215.Ar cylinder ,
216.Ar head ,
217and
218.Ar sector
219fields.
220They will be automatically computed using the BIOS geometry.
221.Pp
222If
223.Fl u
224and
225.Fl s
226are specified then the details of the specified partition will be changed.
227Any other partitions which overlap the requested part of the disk will be
228silently deleted.
229.It Fl F
230Indicate that
231.Ar device
232is a regular file.
233Unless the geometry of
234.Ar device
235is told to
236.Nm
237by
238.Fl T Ar disktype ,
239.Nm
240will count the 512-byte sectors in
241.Ar device
242and produce a fake geometry.
243.It Fl i
244Explicitly request initialisation of the master boot code
245(similar to what
246.Ic fdisk /mbr
247does under
248.Tn MS-DOS ) ,
249even if the magic number in the first sector is ok.
250The partition table is left alone by this (but see above).
251.It Fl l
252Lists known
253.Em sysid
254values and exit.
255.It Fl r Ar file
256Read the boot record from file
257.Ar file
258instead of the specified disk.
259The geometry information used is still that of the disk volume.
260Any changes are written back to the file.
261.It Fl s Ar id/start/size Ns Bq Ar /bootmenu
262Specify the partition
263.Ar id ,
264.Ar start ,
265.Ar size ,
266and optionally
267.Ar bootmenu .
268This flag requires the use of a partition selection flag
269.Po
270.Fl 0 ,
271.Fl 1 ,
272.Fl 2 ,
273.Fl 3 ,
274or
275.Fl E Ar number
276.Pc
277.It Fl S
278When used with no other flags print a series of
279.Pa /bin/sh
280commands for setting variables to the partition information.
281This could be used by installation scripts.
282.It Fl t Ar disktab
283Read
284.Ar disktype
285from the named
286.Xr disktab 5
287file instead of from
288.Pa /etc/disktab .
289.It Fl T Ar disktype
290Use the disklabel
291.Ar disktype
292instead of the disklabel on
293.Ar device .
294.It Fl u
295Display the partitions and interactively ask which one you want to edit.
296.Nm
297will step through each field showing the old value and asking for a new one.
298The
299.Em start
300and
301.Em size
302can be specified in blocks (nn), cylinders (nnc), megabytes (nnm),
303or gigabytes (nng), values in megabytes and gigabytes
304will be rounded to the nearest cylinder boundary.
305The
306.Em size
307may be specified as
308.Em $
309in which case the partition will extend to the end of the available free space.
310.Pp
311.Nm
312will not allow you to create partitions which overlap.
313.Pp
314If
315.Em bootmenu
316is specified for any partition
317.Nm
318will determine whether the installed boot code supports the bootselect code,
319if it doesn't you will be asked whether you want to install the required
320boot code.
321To remove a
322.Em bootmenu
323label, simply press
324.Aq space
325followed by
326.Aq return .
327.It Fl v
328Be more verbose, specifying
329.Fl v
330more than once may increase the amount of output.
331.Pp
332Using
333.Fl v
334with
335.Fl u
336allows the user to change more parameters than normally permitted.
337.It Fl w Ar file
338Write the modified partition table to file
339.Ar file
340instead of the disk.
341.El
342.Pp
343When called with no arguments, it prints the partition table.
344An example follows:
345.Bd -literal
346    Disk: /dev/rwd0d
347    NetBSD disklabel disk geometry:
348    cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
349    total sectors: 40032696
350
351    BIOS disk geometry:
352    cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
353    total sectors: 40032696
354
355    Partition table:
356    0: NetBSD (sysid 169)
357	bootmenu: net 1.5.
358	start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active
359    1: Primary DOS with 32 bit FAT (sysid 11)
360	bootmenu: win98
361	start 63, size 4208967 (2055 MB, Cyls 0-262)
362    2: NetBSD (sysid 169)
363	bootmenu: current
364	start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40)
365    3: Ext. partition - LBA (sysid 15)
366	start 12498570, size 20016990 (9774 MB, Cyls 778-2024)
367    Extended partition table:
368    E0: NetBSD (sysid 169)
369	bootmenu: test
370	start 12498633, size 12305727 (6009 MB, Cyls 778-1544)
371    E1: Primary DOS with 32 bit FAT (sysid 11)
372	start 24804423, size 4096512 (2000 MB, Cyls 1544-1799)
373    E2: Primary DOS with 32 bit FAT (sysid 11)
374	start 28900998, size 3614562 (1765 MB, Cyls 1799-2024)
375    Bootselector enabled, infinite timeout.
376    First active partition: 0
377.Ed
378.Pp
379This example disk is divided into four partitions the last of which is
380an extended partition.
381The sub-partitions of the extended partition are also shown.
382In this case there is no free space in either the disk or in the extended
383partition.
384.Pp
385The various fields in each partition entry are:
386.br
387.in +4
388.Em ptn_number : id_name
389(sysid
390.Em id_number )
391.br
392.in +4
393bootmenu:
394.Em bootmenu
395.br
396start
397.Em start ,
398size
399.Em size ( MB
400MB, Cyls
401.Em first Ns No - Ns Em next )
402.Op , Active
403.in -4
404.in -4
405.Bl -tag -width "bootmenu"
406.It Em ptn_number
407is the number of the partition.
408.It Em id_name
409is the name of the filesystem type or operating system that uses this partition.
410.It Em id_number
411is the number that identifies the partition type.
412169 decimal is used for
413.Nx
414partitions,
41515 decimal to create an extended partition
416and 0 to mark a partition as unused.
417Use
418.Nm
419.Fl l
420to list the known partition types.
421.It Em bootmenu
422is the menu prompt output by the interactive boot code for this partition.
423This line is omitted if the prompt is not defined.
424.It Xo
425.Em start ,
426.Em size
427.Xc
428are the start address and size of the partition in sectors.
429.It Em MB
430is the size of the partition in megabytes.
431.It Xo
432.Em first ,
433.Em next
434.Xc
435are the bounds of this partition displayed as cylinder/head/sector.
436If the partition starts (or ends) on a cylinder boundary the head and
437sector values are omitted.
438If
439.Fl v
440is not specified the start of extended partitions and the first partition
441on the disk are rounded down to include the mandatory red tape in the
442preceding track.
443.It Active
444is output if this is the active partition.
445.El
446.Pp
447If the
448.Fl v
449flag is specified, the beginning and end of each partition are also
450displayed as follows:
451.in +4
452beg: cylinder
453.Em cylinder ,
454head
455.Em head ,
456sector
457.Em sector
458.br
459end: cylinder
460.Em cylinder ,
461head
462.Em head ,
463sector
464.Em sector
465.in -4
466.Bl -tag -width "bootmenu"
467.It Xo
468.Em "cylinder" ,
469.Em "head" ,
470.Em "sector"
471.Xc
472are the beginning or ending address of a partition.
473.Pp
474.Em "Note:"
475these numbers are read from the bootblock, so are the values calculated
476by a previous run of
477.Nm .
478.El
479.Pp
480.Nm
481attempts to check whether each partition is bootable,
482by checking the magic number and some other characteristics
483of the first sector of each partition (the PBR).
484If the partition does not apear to be bootable,
485.Nm
486will print a line containing
487.Dq "PBR is not bootable"
488followed by an error message.
489If the partition is bootable, and if the
490.Fl v
491flag is specified,
492.Nm
493will print
494.Dq "PBR appears to be bootable" .
495If the
496.Fl v
497flag is specified more than once,
498.Nm
499will print the heading
500.Dq "Information from PBR:"
501followed by one or more lines of information gleaned from the PBR;
502this additional information may be incorrect or misleading,
503because different operating systems use different PBR formats.
504Note that, even if no errors are reported, an attempt to boot
505from the partition might fail.
506.Nx
507partitions may be made bootable using
508.Xr installboot 8 .
509.Sh NOTES
510This program is only available (and useful) on systems with PC-platform-style
511MBR partitioning.
512.Pp
513Traditionally the partition boundaries should be on cylinder boundaries
514using the BIOS geometry, with the exception of the first partition,
515which traditionally begins in the second track of the first cylinder
516(cylinder 0, head 1, sector 1).
517Although the BIOS geometry is typically different from the geometry
518reported by the drive, neither will match the actual physical geometry
519for modern disks (the actual geometry will vary across the disk).
520Keeping the partition boundaries on cylinder boundaries makes partitioning
521a driver easier as only relatively small numbers need be entered.
522.Pp
523The automatic calculation of the starting cylinder and
524other parameters uses
525a set of figures that represent what the BIOS thinks is the
526geometry of the drive.
527The default values should be correct for the system on which
528.Nm
529is run, however if you move the disk to a different system the
530BIOS of that system might use a different geometry translation.
531.Pp
532If you run the equivalent of
533.Nm
534on a different operating system then the
535.Ar bootmenu
536strings associated with extended partitions may be lost.
537.Pp
538Editing an existing partition is risky, and may cause you to
539lose all the data in that partition.
540.Pp
541You should run this program interactively once or twice to see how it works.
542This is completely safe as long as you answer the last question in the negative.
543You can also specify
544.Fl w Ar file
545to write the output to a file and later specify
546.Fl r Ar file
547to read back the updated information.
548This can be done without having write access to the disk volume.
549.Sh FILES
550.Bl -tag -width /usr/mdec/mbrxxxxxxxx -compact
551.It Pa /usr/mdec/mbr
552Default location of i386 bootcode
553.It Pa /usr/mdec/mbr_bootsel
554Default location of i386 bootselect code
555.It Pa /usr/mdec/mbr_ext
556Default location of i386 bootselect for extended partitions
557.El
558.Sh SEE ALSO
559.Xr disktab 5 ,
560.Xr boot 8 ,
561.Xr disklabel 8 ,
562.Xr installboot 8 ,
563.Xr mbr 8 ,
564.Xr mbrlabel 8
565.Sh BUGS
566The word
567.Sq partition
568is used to mean both an MBR partition and a
569.Nx
570partition, sometimes in the same sentence.
571.Pp
572There are subtleties that the program detects that are not explained in
573this manual page.
574